plone / plone.app.event

Event content type for Plone
https://pypi.python.org/pypi/plone.app.event
Other
17 stars 37 forks source link

language independent field definitions for dexterity #170

Open agitator opened 9 years ago

agitator commented 9 years ago

could somebody look at https://github.com/plone/plone.app.event/commit/55917b979ba2e0951b5b9ce4459073606b416371

agitator commented 9 years ago

it seems that language independent fields don't support default values ...

default_start is not called and events created show the first possible date, in this case a date in feb 2004

https://github.com/plone/plone.app.event/compare/1.1.x-lang-independent-fields with https://github.com/plone/plone.app.multilingual/tree/datakurre-lif

@datakurre @jensens @thet @rnixx any ideas?

datakurre commented 9 years ago

Is the default value missing already from the add-form? Does it affect only p.a.event or all language independent fields? Please, file an issue for p.a.m. And if you have resources, a failing test would be great. It might be possible that the code, which looks lif value from existing translations fails to fallback to the default value when no translations exist yet.

agitator kirjoitti la joulukuuta 13 11:28:51 2014 GMT+0200:

it seems that language independent fields don't support default values ...

default_start is not called and events created show the first possible date, in this case a date in feb 2004

https://github.com/plone/plone.app.event/compare/1.1.x-lang-independent-fields with https://github.com/plone/plone.app.multilingual/tree/datakurre-lif

@datakurre @jensens @thet any ideas?


Reply to this email directly or view it on GitHub: https://github.com/plone/plone.app.event/issues/170#issuecomment-6687070

agitator commented 9 years ago

yes, on creation of the first object, no other langs exist. and yes the fallback to the default value doesn’t work when no other langs available. no idea how to write a test for that, sorry

datakurre commented 9 years ago

@agitator Would you have time to debug (wih pdb), why LIF-defaultvalueprovider does not fallback to the field's default value? The relevant code is

https://github.com/plone/plone.app.multilingual/blob/datakurre-lif/src/plone/app/multilingual/dx/form.py#L45

It should, unless the field is somehow initialized before that's called.

agitator commented 9 years ago
ipdb> self.field.title
u'label_event_start'
ipdb> isLanguageIndependent(self.field)
True
ipdb> self.field.default

self.field.default is None

datakurre commented 9 years ago

Does the field have defaultFactory? Maybe support for that is what is missing from p.a.m.

agitator kirjoitti su joulukuuta 14 13:22:13 2014 GMT+0200:

ipdb> self.field.title
u'label_event_start'
ipdb> isLanguageIndependent(self.field)
True
ipdb> self.field.default

self.field.default is None


Reply to this email directly or view it on GitHub: https://github.com/plone/plone.app.event/issues/170#issuecomment-6690990

agitator commented 9 years ago
ipdb> self.field.defaultFactory
ipdb> 

there, but also None

datakurre commented 9 years ago

@agitator @thet Ok, I'm sorry that I misunderstood the issue. It seems that multilingual supports the normal schema default values, but apparently it's p.a.event does something else (non standard?) that I don't understand. So, I guess, this is p.a.event issue after all.

agitator commented 9 years ago

it seems that the adapter for default_start isn't called

def default_start(data):
    return default_start_dt(data.context)
provideAdapter(ComputedWidgetAttribute(
    default_start, field=IEventBasic['start']), name='default')
datakurre commented 9 years ago

@agitator Ok, now that make sense and restores this to p.a.m issue.

p.a.m. registers its own default adapter, which overrides your adapter. p.a.m support zope.schema defaults, but not custom z3c.form defaults (because it overrides them).

Please, file an issue for p.a.m. Fix should be possible, but maybe not trivial, because it would require some ZCA-tricks for getting the adapter, which the language independent field default adapter hides.

thet commented 9 years ago

i don't have much resources to dive into this issues, but maybe this gives some hints?

in plone.app.event 1.x we set the default values like so:

from z3c.form.widget import ComputedWidgetAttribute
from zope.component import provideAdapter
def default_start(data):
    return default_start_dt(data.context)
provideAdapter(ComputedWidgetAttribute(default_start, field=IEventBasic['start']), name='default')

vs in plone.app.event 2.x (master branch):

https://github.com/plone/plone.app.event/blob/master/plone/app/event/dx/behaviors.py#L56

from zope.schema.interfaces import IContextAwareDefaultFactory
from zope.interface import provider
@provider(IContextAwareDefaultFactory)
def default_start(context):
    return default_start_dt(context)

plone.app.event 2.x doesn't have a custom behavior factory and IIRC, the IContextAwareDefaultFactory way doesn't work with behaviors with custom behavior factories.

datakurre commented 9 years ago

plone.dexterity = 2.2.4 might support zope.schema context aware default factories for behaviors with custom factories, so that could be another solution.

Johannes Raggam wrote:

i don't have much resources to dive into this issues, but maybe this gives some hints?

in plone.app.event 1.x we set the default values like so:

from z3c.form.widget import ComputedWidgetAttribute from zope.component import provideAdapter def default_start(data): return default_start_dt(data.context) provideAdapter(ComputedWidgetAttribute(default_start, field=IEventBasic['start']), name='default')

vs in plone.app.event 2.x (master branch):

https://github.com/plone/plone.app.event/blob/master/plone/app/event/dx/behaviors.py#L56

from zope.schema.interfaces import IContextAwareDefaultFactory from zope.interface import provider @provider(IContextAwareDefaultFactory) def default_start(context): return default_start_dt(context)

plone.app.event 2.x doesn't have a custom behavior factory and IIRC, the IContextAwareDefaultFactory way doesn't work with behaviors with custom behavior factories.

— Reply to this email directly or view it on GitHub https://github.com/plone/plone.app.event/issues/170#issuecomment-66974653.

agitator commented 9 years ago

context aware adapters work, but still fighting timezone problems with post_processing

datakurre commented 9 years ago

@agitator Nice to hear. @thet might be interested in discussing about post_processing; If I remember correctly, the post processing was almost done in the behavior adapter at one point, but it was later refactored into z3c.form event handler. One main issue has been that post_processing can only truly happen after all field values are known.

agitator commented 9 years ago

talked to him at the aplinecitysprint, dug further into it, seems to be connected with the special post processing of dates within plone.app.event

datakurre commented 9 years ago

@agigator

Yes, there's event handler, which is only called after successful z3c.form POST submission with the saved values. It's far from perfect solution, but the problem has been hard and we haven't figured out a better yet :(

Probably it should somehow be refactored back to behavior adapter, so that it would be z3c.form independent.

agitator wrote

talked to him at the aplinecitysprint, dug further into it, seems to be connected with the special post processing of dates within plone.app.event

— Reply to this email directly or view it on GitHub https://github.com/plone/plone.app.event/issues/170#issuecomment-71430420.