[Zope3-Users] Re: Prevent Duplicate Persistency

jürgen Kartnaller juergen at kartnaller.at
Wed Mar 15 12:14:42 EST 2006


Dax wrote:
> Thanks a lot, Mats.  This is a way to do it, but if I were to add a
> "name" schema to IMark and checkName on the actual "name", then I
> would not be able to do this for "url" as well, right?  So my question
> is how would I do this for url without having url as the name for the
> Mark object?

You should have a look at formlib/form.txt.
See section Invariants.

Jürgen
> 
> On 3/15/06, Mats Nordgren <mats at ronin-group.org> wrote:
>> 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: zope3-users-bounces at zope.org [mailto:zope3-users-bounces at zope.org] On
>> Behalf Of Dax
>> Sent: Tuesday, March 14, 2006 8:00 PM
>> To: zope3-users at 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 at zope.org
>> http://mail.zope.org/mailman/listinfo/zope3-users
>>
>>


-- 

---------------------------------------------------
Jürgen Kartnaller   mailto:juergen_at_kartnaller.at
                    http://www.kartnaller.at
                    http://www.mcb-bregenz.at
---------------------------------------------------



More information about the Zope3-users mailing list