Re: API for setting/getting values on Dexterity content
Roel Bruggink <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.devel |
|---|---|
| Message-ID | <CAO5yuCWTBMfps6mO3mcb1cqoQK=YjYWLC+O=7rPdfmaHoA1X2A@mail.gmail.com> |
I read your blog and I get your point. I just think direct attribute access for anything else than the main schema is not possible, be it just because of ambiguity. That is why I asked how `set_value` and `get_value` should behave when passed a fieldname :) Let's see if we can resolve this somehow, instead of bickering whether I've read you blog or not ;) -Roel On 22 October 2014 12:39, Andreas Jung <[email protected]> wrote: > > Perhaps you did not read my blog posts or you did not got my point. > > The developer experience with Plone and Dexerity - if done the > right way - is horrible. As developer right now I have to know > which behavior implements which field in order to set/get > a value the right way. It is horrible because as a developer > I want to write pythonic code (translates to attribute access). > This was also one of the design goals and promises of Dexterity > as far as I recall. But reality is different. Everyone one write > Pythonic code but the code is potentially broken (see my rants > about the plone.app.event implementation). > > So the idea - or better the necessity - is to give developers > a consistent way to read/set values. This means in the first place that > the whole behavior stuff should be hidden from the developer - at least > for the standard developer which average skills who is the potential > user of plone.api. As a developer (e.g. in my current role as writer > of a fat migration process) I want assign values to an object without > checking other peoples source code about where a particular attribute > is defined and check for the related interface. This complexity must be > hidden in order to writer code in more clear way, in a more reliable way > and in a more readable way. > > The implementation of set/get methods must perform some kind of > introspection on the schema and the attached behaviors in order > to retrieve the related interface for adopting the current context > object. This is of course in some way slower that direct attribute > access but it is the right way. There is certainly a performance loss > with this approach but I guess that this could be minimized with > clever caching of the schema introspection results. > > -aj > > Roel Bruggink wrote: > > Hi Andreas, > > > > I get what you say. I have a few questions on how this would work in > > practice, though. > > > > Assuming the following: > > IMySchema(): > > start > > end > > name > > animal_type default='Känguru' > > > > IMyFirstBehavior(): > > start > > end > > lives_in default='Känguru Island' > > > > IMySecondBehavior(): > > name default='Jos Henken' > > > > How should set_value('start', now()) and get_value('start') behave? > > > > Would a dict-like api be of more use, ie obj['IMyBehavior.fieldname'] = > > 'new value' ? We'll still probably have to adapt the object to that api, > > though. > > > > So in the end, direct attribute access for just the schema itself would > > work, unless the fieldname is unique between all behaviors. > > > > -Roel > > > > On 22 October 2014 10:25, Andreas Jung > > <[email protected] > > <mailto:[email protected]>> wrote: > > > > Hi there, > > > > the following suggestion is based on former blog posts of mine, e.g. > > > > > https://www.andreas-jung.com/contents/bad-dexterity-application-design > > > https://www.andreas-jung.com/contents/copying-dexterity-fields-from-one-instance-to-another-instance > > > > I clearly see a need for an API for safely setting and getting values > > for Dexerity content that takes all aspects of behaviors into > account. > > In general: direct attribute access to on Dexterity instance was a > nice > > goal but in reality it is a broken and dangerous programming pattern > in > > Plone right now - unless the direct getting/setting of values through > > direct attribute access can be fixed somehow (I think this is very > > hard). > > > > The safest way would be to provide methods like > > > > plone.api.content.set_value(obj, fieldname, value) > > value = plone.api.content.get_value(obj, fieldname) > > > > as part of plone.api or through methods of the Dexterity base > > classes Item and Container: > > > > obj.set_value(fieldname, value) > > value = obj.get_value(fieldname). > > > > The method names are dust and smoke and could be named differently. > > > > Any thoughts on the need for encapsulating the setting/getting of > value? > > Any thoughts where such an API would fit best (plone.api vs. base > > classes)? > > > > -aj > > > > > > > > > ------------------------------------------------------------------------------ > > Comprehensive Server Monitoring with Site24x7. > > Monitor 10 servers for $9/Month. > > Get alerted through email, SMS, voice calls or mobile push > > notifications. > > Take corrective actions from your mobile device. > > http://p.sf.net/sfu/Zoho > > _______________________________________________ > > Plone-developers mailing list > > Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > > <mailto:Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org> > > https://lists.sourceforge.net/lists/listinfo/plone-developers > > > > > > > > > > -- > > Roel Bruggink > > http://www.fourdigits.nl/mensen/roel-bruggink > > > > Four Digits BV > > http://www.fourdigits.nl <http://www.fourdigits.nl/> tel: +31(0)26 > 4422700 > > > > > ------------------------------------------------------------------------------ > > Comprehensive Server Monitoring with Site24x7. > > Monitor 10 servers for $9/Month. > > Get alerted through email, SMS, voice calls or mobile push notifications. > > Take corrective actions from your mobile device. > > http://p.sf.net/sfu/Zoho > > > > _______________________________________________ > > Plone-developers mailing list > > Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > > https://lists.sourceforge.net/lists/listinfo/plone-developers > > > > > ------------------------------------------------------------------------------ > Comprehensive Server Monitoring with Site24x7. > Monitor 10 servers for $9/Month. > Get alerted through email, SMS, voice calls or mobile push notifications. > Take corrective actions from your mobile device. > http://p.sf.net/sfu/Zoho > _______________________________________________ > Plone-developers mailing list > Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org > https://lists.sourceforge.net/lists/listinfo/plone-developers > -- Roel Bruggink http://www.fourdigits.nl/mensen/roel-bruggink Four Digits BV http://www.fourdigits.nl tel: +31(0)26 4422700 ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://p.sf.net/sfu/Zoho _______________________________________________ Plone-developers mailing list Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/plone-developers