Re: DateInput widget, format attr & ugettext

2009-08-12 Thread carsten

Thanks, Malcolm!

I filed the ugettext_lazy problem under #11701 and attached a patch
that fixes it by using force_unicode() on the format in DateWidget.

FWIW, users could also workaround this thing by using their forms
__init__, like so:

def __init__(self, *args, **kwargs):
super(SomeForm, self).__init__(*args, **kwargs)
self.fields['some_date'].widget.format = ugettext_lazy('%d.%m.
%Y')

Seems, the __proxy__ then already is a string/unicode when reaching
the widgets formatting method.


On Aug 7, 5:39 am, Malcolm Tredinnick 
wrote:
> On Fri, 2009-08-07 at 11:56 +1000, Malcolm Tredinnick wrote:
> > On Thu, 2009-08-06 at 08:06 -0700, cArkraus wrote:
> > > Hey all,
>
> > > I cant seem to get my (non-model-)forms datefield localized.
>
> > > Here's my first attempt:
> > > some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
> > > ('%d.%m.%Y')))
>
> > This would do the translation when the file is imported, which won't
> > reflect the user's current locale. The working rule is that you don't
> > use ugettext() outside of a view function (or something called directly
> > by a view).
>
> > > That's working fine, until the user switches his sessions language.
> > > Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
> > > the correctly localized one(ie. '%Y-%m-%d').
>
> > > Now, if I change to ugettext_lazy() like this:
>
> > > some_date = fields.DateField(widget=widgets.DateInput
> > > (format=ugettext_lazy('%d.%m.%Y')))
>
> > > I get a TemplateSyntaxError 'strftime() argument 1 must be string or
> > > read-only buffer, not __proxy__'
>
> > That's a bug in Django and Python (both sides share some blame: Python's
> > string handling is retarded in cases like this and Django doesn't work
> > around it correctly here). It's not particularly easy to work around it,
> > either.
>
> This came about ambiguously: without hunting down the offending place
> right at the moment, I'm still fairly certain it's easy to fix this in
> Django's core. I can't think of an easy way to work around it in Django
> apps, however (that might be because I'm not imaginative enough).
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateInput widget, format attr & ugettext

2009-08-06 Thread Malcolm Tredinnick

On Fri, 2009-08-07 at 11:56 +1000, Malcolm Tredinnick wrote:
> On Thu, 2009-08-06 at 08:06 -0700, cArkraus wrote:
> > Hey all,
> > 
> > I cant seem to get my (non-model-)forms datefield localized.
> > 
> > Here's my first attempt:
> > some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
> > ('%d.%m.%Y')))
> 
> This would do the translation when the file is imported, which won't
> reflect the user's current locale. The working rule is that you don't
> use ugettext() outside of a view function (or something called directly
> by a view).
> 
> > That's working fine, until the user switches his sessions language.
> > Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
> > the correctly localized one(ie. '%Y-%m-%d').
> > 
> > Now, if I change to ugettext_lazy() like this:
> > 
> > some_date = fields.DateField(widget=widgets.DateInput
> > (format=ugettext_lazy('%d.%m.%Y')))
> > 
> > I get a TemplateSyntaxError 'strftime() argument 1 must be string or
> > read-only buffer, not __proxy__'
> 
> That's a bug in Django and Python (both sides share some blame: Python's
> string handling is retarded in cases like this and Django doesn't work
> around it correctly here). It's not particularly easy to work around it,
> either.

This came about ambiguously: without hunting down the offending place
right at the moment, I'm still fairly certain it's easy to fix this in
Django's core. I can't think of an easy way to work around it in Django
apps, however (that might be because I'm not imaginative enough).

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DateInput widget, format attr & ugettext

2009-08-06 Thread Malcolm Tredinnick

On Thu, 2009-08-06 at 08:06 -0700, cArkraus wrote:
> Hey all,
> 
> I cant seem to get my (non-model-)forms datefield localized.
> 
> Here's my first attempt:
> some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
> ('%d.%m.%Y')))

This would do the translation when the file is imported, which won't
reflect the user's current locale. The working rule is that you don't
use ugettext() outside of a view function (or something called directly
by a view).

> That's working fine, until the user switches his sessions language.
> Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
> the correctly localized one(ie. '%Y-%m-%d').
> 
> Now, if I change to ugettext_lazy() like this:
> 
> some_date = fields.DateField(widget=widgets.DateInput
> (format=ugettext_lazy('%d.%m.%Y')))
> 
> I get a TemplateSyntaxError 'strftime() argument 1 must be string or
> read-only buffer, not __proxy__'

That's a bug in Django and Python (both sides share some blame: Python's
string handling is retarded in cases like this and Django doesn't work
around it correctly here). It's not particularly easy to work around it,
either.

Please open a ticket with this short example (only the ugettext_lazy()
case). Although you might also check that the i18n component in Trac
doesn't have a ticket open like this. I'm a little surprised it hasn't
been noticed before.

Regards,
Malcolm



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



DateInput widget, format attr & ugettext

2009-08-06 Thread cArkraus

Hey all,

I cant seem to get my (non-model-)forms datefield localized.

Here's my first attempt:
some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
('%d.%m.%Y')))

That's working fine, until the user switches his sessions language.
Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
the correctly localized one(ie. '%Y-%m-%d').

Now, if I change to ugettext_lazy() like this:

some_date = fields.DateField(widget=widgets.DateInput
(format=ugettext_lazy('%d.%m.%Y')))

I get a TemplateSyntaxError 'strftime() argument 1 must be string or
read-only buffer, not __proxy__'

I'm pretty stuck - it's my first i18n project. Could somebody help me
out, please?

Cheers & thx for any pointer!
Carsten

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---