[Zope3-Users] z3c.form: Data Manager - getting value via dm.query() instead of dm.get()
Roger Ineichen
dev at projekt01.ch
Thu Aug 14 08:23:47 EDT 2008
Hi Hermann
Hi Hermann
> Betreff: Re: AW: AW: AW: [Zope3-Users] z3c.form: Data Manager
> - getting value via dm.query() instead of dm.get()
[...]
> > Such a search session object could look like:
> >
> > class ISearchSession(ISession):
> > """Message filter session."""
> >
> > searchText = zope.schema.TextLine(
> > title=Search text',
> > description=u'The search text',
> > default=u'',
> > required=False)
> >
> > class SearchSessioon(Session):
> > _spd = None
> >
> > @Lazy
> > def spd(self):
> > return self.__getitem__('SEARCH_SESSION_KEY')
> >
> > @apply
> > def searchText():
> > def get(self):
> > return self.spd.get('searchText', u'')
> > def set(self, searchText):
> > self.spd['searchText'] = searchText
> > return property(get, set)
>
> Is the parent object Session/ISession the one from
> zope.session? How does it connect to the persistent Session
> object? And what is "@Lazy"?
Yes,
from zope.session.session import Session
Lazy will cache your method result and return them again
for future access.
See:
from zope.cachedescriptors.property import Lazy
> Yes, that's a possibility, but it would force me to write:
>
> - An property for every field.
> - A class for every search view.
>
> All in all that's around ~ 200 lines of code for 5 search
> forms with appr.
> 5 fields each, compared to appr. 10 lines of code in my solution.
I see
> > I allways use such a session implementation because it
> abstracts what
> > you need, uses schema fields, offers built in defaults and
> works well
> > with z3c.form.
>
> Yes, thanks for the code snippet, it's interesting and a
> clean solution.
>
> > Note; I'm still not 100% sure if the get() or query() usage in
> > applyChanges is right or wrong. I hope to find time to deep
> into that
> > in the near future.
> >
> > But I think nobody will understand the concept if we
> implement a form
> > property for use get or query in applyChanges.
>
> Yes, that may be true. Hmmm...
>
> > Hope the session concept works for you till someone
> agrees/checks the
> > get/query useage.
>
> Well, I have two more possibilities until this is sorted out entirely:
>
> 1) Monkey patch z3c.form.DictionaryField.get() and let it
> return interfaces.NOVALUE
> 2) Write an register my own data manager to overcome this.
I think a custom data manager is the way to go for you.
Probably a session property handling needs something
different then a simple dict or a context data manager.
Regards
Roger Ineichen
> Thanks again for help,
> Best Regards,
> Hermann
>
> --
> hermann at qwer.tk
> GPG key ID: 299893C7 (on keyservers)
> FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
>
>
>
More information about the Zope3-users
mailing list