#5794: [patch] newforms DateTimeInput breaks form_for_model rendering
------------------------------------------+---------------------------------
Reporter: MikeH <[EMAIL PROTECTED]> | Owner: nobody
Status: new | Component:
django.newforms
Version: SVN | Resolution:
Keywords: | Stage: Accepted
Has_patch: 1 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
------------------------------------------+---------------------------------
Changes (by mtredinnick):
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
Old description:
> Using revision 6593, I have the following problem when rendering forms
> for models that have DateTimeFields
>
> [EMAIL PROTECTED]:~/tthome$ ./manage.py shell
> Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>
> from tthome.events.models import Event
>
> import django.newforms as forms
>
> f = forms.form_for_model(Event)
>
> form = f()
>
> print form
>
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line
> 13, in __str__
> return self.__unicode__().encode('utf-8')
> File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
> 80, in __unicode__
> return self.as_table()
> File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
> 159, in as_table
> return
> self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
> u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
> File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
> 144, in _html_output
> output.append(normal_row % {'errors': force_unicode(bf_errors),
> 'label': force_unicode(label), 'field': unicode(bf), 'help_text':
> help_text})
> File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
> 251, in __unicode__
> return self.as_widget()
> File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
> 279, in as_widget
> return widget.render(self.html_name, data, attrs=attrs)
> File "/usr/lib/python2.5/site-packages/django/newforms/widgets.py",
> line 165, in render
> value.strftime(self.format), attrs)
> AttributeError: 'NoneType' object has no attribute 'strftime'
>
>
> The attached patch fixes this behavior, but it might not be the best
> solution...
New description:
Using revision 6593, I have the following problem when rendering forms for
models that have DateTimeFields
{{{
#!python
[EMAIL PROTECTED]:~/tthome$ ./manage.py shell
Python 2.5.1 (r251:54863, Oct 5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
from tthome.events.models import Event
import django.newforms as forms
f = forms.form_for_model(Event)
form = f()
print form
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/django/utils/encoding.py", line
13, in __str__
return self.__unicode__().encode('utf-8')
File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
80, in __unicode__
return self.as_table()
File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
159, in as_table
return
self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>',
u'<tr><td colspan="2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
144, in _html_output
output.append(normal_row % {'errors': force_unicode(bf_errors),
'label': force_unicode(label), 'field': unicode(bf), 'help_text':
help_text})
File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
251, in __unicode__
return self.as_widget()
File "/usr/lib/python2.5/site-packages/django/newforms/forms.py", line
279, in as_widget
return widget.render(self.html_name, data, attrs=attrs)
File "/usr/lib/python2.5/site-packages/django/newforms/widgets.py", line
165, in render
value.strftime(self.format), attrs)
AttributeError: 'NoneType' object has no attribute 'strftime'
}}}
The attached patch fixes this behavior, but it might not be the best
solution...
Comment:
Wow. I'm an idiot. Not sure how I missed testing that case. Sorry about
that.
Your patch looks like the right idea.
--
Ticket URL: <http://code.djangoproject.com/ticket/5794#comment:1>
Django Code <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
-~----------~----~----~----~------~----~------~--~---