Re: API for setting/getting values on Dexterity content
Roel Bruggink <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.devel |
|---|---|
| Message-ID | <CAO5yuCWPbeeXYWPU9biMdo1j5pqzHSu386zfGwmcq6g6PNcmDA@mail.gmail.com> |
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]> 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
> 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