[Zope3-Users] datafield as objectname

Egon Frerich e.frerich at nord-com.net
Fri Mar 3 07:31:04 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello Brett,

you 'll see my code is in German but I assume that is not a problem.

> from zope.app.container.contained import NameChooser
> from zope.app.exception.interfaces import UserError
> 
> class ObjektNamenFuerRaumBestimmer(NameChooser):
> 
>     def checkName(self, name, object):
>         if name <> object.RaumName:
>             raise UserError(u'Der RaumName stimmt nicht mit dem' \
>                             'Objektnamen ueberein!')
>         return super(ObjektNamenFuerRaumBestimmer, self).checkName(name, object)
> 
>     def chooseName(self, name, object):
>         name = object.RaumName
>         try:
>             self.checkName(name, object)
>         except UserError, e:
>             if str(e) == "The given name is already being used":
>                 object.RaumName = u"KopieVon" + object.RaumName
>                 self.chooseName('', object)
>                 name = object.RaumName
>                 return name
>         return name
> 
> def aendernObjektnamen(raum, event):
>     import logging
>     if raum.__name__ != raum.RaumName:
>         alter_name = raum.__name__
>         behaelter = raum.__parent__
>         behaelter.__setitem__(raum.RaumName, raum)
>         behaelter.__delitem__(alter_name)

And these lines are in the ZCML:


>   <subscriber
>       for=".interfaces.IRaum
>            zope.app.event.interfaces.IObjectModifiedEvent"
>       handler=".behaelter.aendernObjektnamen"
>       />


>   <content class=".behaelter.RaumBehaelter">
>     <implements
>         interface="zope.app.container.interfaces.IContainerNamesContainer"
>         />


>   <adapter
>      for=".interfaces.IRaumBehaelter"
>      provides="zope.app.container.interfaces.INameChooser"
>      factory=".behaelter.ObjektNamenFuerRaumBestimmer"
>      />

Regards,
Egon



Brett Haydon schrieb am 03.03.2006 05:43:

> Hi there,
> I have a similar problem setting the contenttype to the objectname, and I
> was trying to work out the NameChooser part. Do you mind including a snippet
> of the code so I can see how you did it?
> 
> Thanks,
> 
> Brett
> 
> -----Original Message-----
> From: zope3-users-bounces at zope.org [mailto:zope3-users-bounces at zope.org] On
> Behalf Of Egon Frerich
> Sent: Wednesday, 1 March 2006 2:28 AM
> To: zope3-users at zope.org
> Subject: [Zope3-Users] datafield as objectname
> 
> Hello,
> 
> in my application one of the contenttype datafields should be the
> objectname in the container. With a subclass of NameChooser I managed to
> add content objects into the container with an objectname which is
> identical with a name in a datafield.
> 
> But how can I rename the objectname/change the datafield?
> 
> With "IContainerNamesContainer" the rename button in the containerview
> is gone.
> 
> The user would prefer to change the datafield in the edit form.  Then it
> is possible to change both names via "IObjectModifiedEvent". But the old
> objectname is in the URL for the edit form (with the message that
> changes are stored) so the user can only go back to the container view
> (and gets an error if he tries to make another change in the edit form).
> To my knowledge it is not possible to change the URL because the
> IObjectModifiedEvent has no argument with the request.
> 
> What should I do?
> 
> Egon
> 
_______________________________________________
Zope3-users mailing list
Zope3-users at zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

- --
Egon Frerich, Freudenbergstr. 16, 28213 Bremen

E-Mail: e.frerich at nord-com.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: GnuPT 2.7.2
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFECDcHuTzybIiyjvURAsN6AJ9HSOivJ9T8TSz4iAJ5TInNf3RlGACdF6h5
hyX3QAA1wN5Eb9Rndy49BZI=
=1oY0
-----END PGP SIGNATURE-----


More information about the Zope3-users mailing list