Ah. Ok. Setting format does work at construction time though.

On May 11, 2:36 pm, abecc <[EMAIL PROTECTED]> wrote:
> Hi,
>
> DateConverter doesn't set month_style at construction time.
> If you want to use a different month_style you should subclass it
> like this:
>
> class MyDateConv(DateConverter):
>       month_style = "dd/mm/yyyy"
>
> -Augusto
>
> On May 10, 12:09 pm, TiNo <[EMAIL PROTECTED]> wrote:
>
> > Almost. Yours still returns mm/dd/yyyy.
>
> > Wanna know why?
>
> > _from_python looks like this:
>
> > class DateConverter(validators.DateTimeConverter):
> > [..]
> >         def _from_python(self, value, state):
> >                 log.debug((self,value,state))
> >                 if not value:
> >                         return None
> >                 elif isinstance(value, datetime):
> >                         # Python stdlib can only handle dates with year 
> > greater than 1900
> >                         if value.year <= 1900:
> >                                 return strftime_before1900(value, 
> > self.format)
> >                         else:
> >                                 return value.strftime(self.format)
> >                 else:
> >                         return value
>
> > The value that I pass is a datetime.date object...
> > so it returns value.
>
> > so when I set default = datetime.datetime.tody() it returns the right
> > thing!
>
> > thnx folks
>
> > On May 10, 4:02 pm, remi jolin <[EMAIL PROTECTED]> wrote:
>
> > > le 10.05.2007 13:30 TiNo a écrit:> That still does return mm/dd/yyyy and 
> > > not dd/mm/yyyy as the default
> > > > value.
> > > > Besides the validator does not work for me that way...
> > > > And if I set the DateConverter(with month_style="dd/mm/yyy"), it
> > > > throws errors for the strings the datePicker gave me...
>
> > > > (side question, how do I get a date through the converter first, and
> > > > through the validator after that? Can I set two validators?)
>
> > > try with the following validator :
>
> > > class DateConverter(validators.DateTimeConverter):
> > >     def _to_python(self, value, state):
> > >         if value and isinstance(value, datetime.date):
> > >             return value
> > >         try:
> > >             tpl = time.strptime(value, self.format)
> > >         except ValueError:
> > >             raise Invalid(self.message('badFormat', state), value, state)
> > >         return datetime.date(year=tpl.tm_year, month=tpl.tm_mon, 
> > > day=tpl.tm_mday)
>
> > > and
> > > data=CalendarDatePicker(name="data",validator=DateConverter(format="%d/%m/%
> > >  Y"),
> > > default=datetime.date.today())


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to