This could be done by using the URL as the name for the Mark object.

from zope.app.container.contained import NameChooser

Class MarkNameChooser(NameChooser):
        def chooseName(self, name, object):
                name = object.url
                self.checkName(name, object)
                return name

<adapter
        for=".interfaces.IMarkContainer"
      provides="zope.app.container.interfaces.INameChooser"
      factory=".bookmarks.MarkNameChooser" />

Make sure your Mark object is configured with set_before_add

<addform
        ...
        set_before_add="url" />


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Dax
Sent: Tuesday, March 14, 2006 8:00 PM
To: zope3-users@zope.org
Subject: [Zope3-Users] Prevent Duplicate Persistency

For the following example (taken from "Zope3 In 30 Minutes"):

class IMark(Interface):
    """This is the book mark object."""

    url = TextLine(
        title=u"URL/Link",
        description=u"URL of the website",
        default=u"http://www.zope.org";,
        required=True)

    description = Text(
        title=u"Description",
        description=u"Description of the website",
        default=u"",
        required=False)

How can I prevent Mark objects from having the same url?  So if a Mark
object exists in BookMarker with Mark.url="http://www.zope.org/";, how
can I prevent another Mark object from being added when its url is
"http://www.zope.org";?

Thanks.
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to