Re: How to edit dexterity types without needing to know about their behaviors
Johannes Raggam <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.devel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, 2014-03-14 at 02:46 -0700, ajung wrote:
> ajung wrote
> >
> > johannes raggam wrote
> >>
> >> i'll fix that, probably at the wine and beer sprint. but then you'll
> >> still always get UTC datetime values instead of localized ones, if you
> >> get the start/end attributes directly from the context.
> >>
> >>> Consistency-is-king
> >>> Andreas
> >>
> >> pragmatism is okay.
> >> johannes
>
> Here are the facts why plone.app.event currently freaks me out.
>
> The source 'start' object is
> v = DateTime('2008/09/09 09:00:00 GMT+2')
> which translates to 07:00 UTC.
>
> The migration code tries to concert the DateTime instance to a Python
> datetime instance with UTC timezone and setting the 'timezone' of the event
> object to 'Etc/GMT+2' using
>
> v = v.asdatetime()
> tz = str(v.tzinfo)
> if tz.startswith('GMT'):
> tz = 'Etc/%s' % tz
> new_obj.timezone = tz
> acc = IEventAccessor(new_obj)
> v = v.replace(tzinfo=pytz.timezone('UTC'))
> setattr(acc, k, v)
first, are you sure, that you want to use Etc/GMT+2 as timezone? Etc/GMT
is not GMT, see the answer here:
http://answers.yahoo.com/question/index?qid=20090707145844AANnghH
>>> import pytz
>>> from datetime import datetime
>>> vie = pytz.timezone('Europe/Vienna')
>>> etc = pytz.timezone('Etc/GMT+2')
>>> dt = vie.localize(datetime.now())
>>> dt
datetime.datetime(2014, 3, 14, 11, 13, 11, 629280, tzinfo=<DstTzInfo
'Europe/Vienna' CET+1:00:00 STD>)
>>> dt.astimezone(etc)
datetime.datetime(2014, 3, 14, 8, 13, 11, 629280, tzinfo=<StaticTzInfo
'Etc/GMT+2'>)
then, just set the timezone on the accessor and start and end datetime
as floating datetimes. if you don't have multiple timezone in the portal
you are migrating, that shouldn't be a problem.
the behavior's setter applies a FAKEZONE, just to be able to compare the
value against something already stored on the content object without.
that way, we avoid a "TypeError: can't compare offset-naive and
offset-aware datetimes", because the widget's value is timezone naive.
as i said, i'm going to refactor this....
then, the data_postprocessing event handler (p.a.event.dx.behaviors,
line 427) takes the floating-timezone value with it's FAKEZONE, removes
it and converts that value to UTC, using the timezone attribute from the
content object.
i'm going to repeat myself, but i think that was not clear enough.
>
> After the migration the event show up in Plone with
>
> 09.09.2008 um 07:00 bis 10.09.2008 um 15:00 (Etc/GMT+2 / UTC-200)
> ^^^^^^^^^^^^^^^^^^^^
>
> Taking the debugger:
>
> >>> ev = app.restrictedTraverse('eteaching/news/tagungen/ilias_2008/')
> >>> ev.start
> datetime.datetime(2008, 9, 9, 9, 0,
> tzinfo=<plone.app.event.dx.behaviors.FakeZone object at 0xa7c1250>)
> >>> ev = app.restrictedTraverse('eteaching/news/tagungen/ilias_2008/')
> >>> ev.timezone
> 'Etc/GMT+2'
> >>> ev.start
> datetime.datetime(2008, 9, 9, 9, 0,
> tzinfo=<plone.app.event.dx.behaviors.FakeZone object at 0xa7c1250>)
> >>> ev.start.tzinfo
> <plone.app.event.dx.behaviors.FakeZone object at 0xa7c1250>
> >>> ev.start.tzinfo.tzname(ev.start)
> 'FAKEZONE'
>
> That the hell is a FAKEZONE?
>
> Obviously my code is wrong because it does not change the 'hour' from 9 to 7
> (because of the two hours offset).
>
> So I changed the code to
>
> v = v.astimezone(pytz.utc)
>
> In this case the output changed to
>
> 09.09.2008 um 05:00 ...
> ^^^^^^^^^^^^^^^^^^^^
>
> ...which is even more weird.
>
> -aj
>
>
>
>
> --
> View this message in context: http://plone.293351.n2.nabble.com/How-to-edit-dexterity-types-without-needing-to-know-about-their-behaviors-tp7570571p7570628.html
> Sent from the Core Developers mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> Plone-developers mailing list
> Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/plone-developers
--
programmatic web development
di(fh) johannes raggam / thet
python plone zope development
plone framework team member
mail: office-//[email protected]
web: http://programmatic.pro
http://bluedynamics.com
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Plone-developers mailing list
Plone-developers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/plone-developers
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iEYEABECAAYFAlMi2TUACgkQW4mNMQxDgAeTTQCg2tjc92BQhSEX/In6DWyJtfom f/MAoIB8ipWbPIs6bd70uiD2U6OI+33B =Owc5 -----END PGP SIGNATURE-----