[Zope3-Users] Re: question about request.locale and creation time

Shailesh Kumar shaileshk at gmail.com
Mon Jan 15 10:47:10 EST 2007


I tried solving this problem as follows. Don't know if its the best
solution, but works for me as my application is meant only for Intranet
environments.


   - I subclassed zope.app.container.browser.contents.Contents.
   - In the subclass I overrided _*extractContentInfo *method
   - Created a LocalTimezone class as described in Python manual by
   subclassing tzinfo
   - Converted the created and modifed datetime objects from dublin-core
   information to local time zone
   - Used this class to create the Container views

The time information looks now fine for me.

Is there any better way?

With regards,
-Shailesh


On 1/15/07, Shailesh Kumar <shaileshk at gmail.com> wrote:

> Sorry, the mail went only to Philipp by mistake.
>
> Hi Philipp,
> Thanx for the pointers. I went through the sections of your book regarding
> this. I guess I now understand my problem better. The problem is about the
> time-zone and not about formatting. The Creation and Modification time
> stamps seem to be the UTC time stamps, and I want the display to be
> according to local time zone.
>
> How can I do it?
>
> With regards,
> -Shailesh
>
>
>
> On 1/14/07, Philipp von Weitershausen <philipp at weitershausen.de > wrote:
> >
> >
> >
> > Shailesh Kumar wrote:
> > > Hi,
> > >
> > > When I look at the Creation time and Modification time in any of the
> > > container views, it shows me the UTC time.
> > >
> > > Looking at
> > > zope.app.container.browser.contents.py
> > > < http://zope.app.container.browser.contents.py>: Line 174
> > >
> > > I found that:
> > >
> > >             formatter = self.request.locale.dates.getFormatter(
> > >                 'dateTime', 'short')
> > >
> > >             created = self.safe_getattr(dc, 'created', None)
> > >             if created is not None:
> > >                 info['created'] = formatter.format(created)
> > >
> > >             modified = self.safe_getattr(dc, 'modified', None)
> > >             if modified is not None:
> > >                 info['modified'] = formatter.format(modified)
> > >
> > > is being used to compute them.
> >
> > No, the local formatter is used to *format* dates according to the
> > current locale. 8th of March this year, for example would be "3/8/2007"
> > in the U.S. English locale, but "08.03.2007" in the German locale.
> >
> > > I am puzzled, how does the browser set its locale? I guess this must
> > be
> > > a very basic question. But I am not able to figure it out.
> >
> > request.locale is set according to the most preferred language/locale
> > returned by the IUserPreferredLanguages adapter for the request. The
> > default adapter reads browser's the Accept-Language header. More
> > advanced adapters could use cookies or something else that the user can
> > influence though the website directly.
> >
> > My book talks about this in detail: http://worldcookery.com
> >
> >
> > --
> > http://worldcookery.com -- Professional Zope documentation and training
> > 2nd edition of Web Component Development with Zope 3 is now shipping!
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20070115/72049247/attachment.htm


More information about the Zope3-users mailing list