#9459: forms.DateTimeField() rendered with HiddenInput looses microseconds
-------------------------------+--------------------------------------------
Reporter: guettli | Owner: nobody
Status: new | Milestone:
Component: Forms | Version: 1.0
Resolution: | Keywords:
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 1 |
-------------------------------+--------------------------------------------
Comment (by tobias):
Slightly more acceptable approach, with a couple bug fixes:
{{{
class DateTimeWithUsecsField(forms.DateTimeField):
def clean(self, value):
if value and '.' in value:
value, usecs = value.rsplit('.', 1)
usecs += '0'*(6-len(usecs)) # right pad with zeros if
necessary
try:
usecs = int(usecs)
except ValueError:
raise ValidationError('Microseconds must be an integer')
else:
usecs = 0
cleaned_value = super(DateTimeWithUsecsField, self).clean(value)
if cleaned_value:
cleaned_value = cleaned_value.replace(microsecond=usecs)
return cleaned_value
}}}
Also updated at http://www.djangosnippets.org/snippets/1342/
--
Ticket URL: <http://code.djangoproject.com/ticket/9459#comment:5>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" 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/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---