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
-~--~~~~--~~--~--~---



Re: Initial values in form fields

2008-09-03 Thread cArkraus

@Daniel: thanks a lot - that did the trick!
> I'm not sure I really understand what you want to do here
Fyi. I´m working on a travel site, where I need quite some different
travel search forms. Whereas some fields in these forms are common(eg.
number of travelers, destination,...) some fields need customization -
like default travel start date.
So my idea was to instantiate derived forms corresponding to the site
sections I would place them at; think 'SummerSearchForm' in views
related to summer tours and 'WinterSearchForm' in skiing season pages
and so forth. I can do that now - thx again! : )

@ Bruno
Thx for the comp.lang.py tip ...definitely will have a look!

On Sep 2, 10:11 pm, bruno desthuilliers
<[EMAIL PROTECTED]> wrote:
> On 2 sep, 19:10, cArkraus <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hey everyone,
>
> > am pretty new to Django and Python in general.
> > I seem not be able to let the 'initial' value of a form-field be
> > calculated by its parent form.
>
> > I'd like to do sth like this:
>
> > class AbstractForm(forms.Form):
> >     some_attr = "foo"
>
> >     def some_method(self):
> >         if self.some_attr == "foo": return "foo"
> >         return "Something else..."
>
> >     some_field = forms.CharField(initial=self.some_method())
>
> > ..but obviously I cant access 'self' when declaring some_field..
>
> Indeed. the AbstractForm class doesn't exists yet, so let's not even
> talk about an instance...
>
> > and
> > obviously I have yet to learn a lot about Python oop :)
>
> May I recommand comp.lang.py ? FWIW, how functions become methods is
> something I explained quite a few times there !-)
>
> > Fyi. I do not want to initiate form defaults like
> > f = MyForm(initial=...) in my views since I'd have to repeat that in
> > each view.
>
> > I'd rather do things like this lateron:
> > class ConcreteForm(AbstractForm):
> >     some_attr = "bar"
>
> > Somebody willing to enlighten me?
>
> Honestly, I think Daniel's solution is the way to go... At least, it's
> the simplest thing  to do, and it should JustWork(tm).
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Initial values in form fields

2008-09-02 Thread cArkraus

Hey everyone,

am pretty new to Django and Python in general.
I seem not be able to let the 'initial' value of a form-field be
calculated by its parent form.

I'd like to do sth like this:

class AbstractForm(forms.Form):
some_attr = "foo"

def some_method(self):
if self.some_attr == "foo": return "foo"
return "Something else..."

some_field = forms.CharField(initial=self.some_method())

..but obviously I cant access 'self' when declaring some_field.. and
obviously I have yet to learn a lot about Python oop :)

Fyi. I do not want to initiate form defaults like
f = MyForm(initial=...) in my views since I'd have to repeat that in
each view.

I'd rather do things like this lateron:
class ConcreteForm(AbstractForm):
some_attr = "bar"

Somebody willing to enlighten me?

Thx a lot & cheers
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---