jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
839 stars 145 forks source link

Floppyforms incompatible with pgettext_lazy #64

Closed poswald closed 9 years ago

poswald commented 11 years ago

In the past I've been able to add translation context with this pattern on models:

from django.utils.translation import pgettext_lazy
....

my_thing = models.CharField(
    pgettext_lazy('Context for this widget','Name'),
    blank=True,
    max_length=200)

When you try to render a model form with this I get:

{% load floppyforms %}
{% form my_form %}

...
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/floppyforms/templatetags/floppyforms.py" in render
  462.             output = nodelist.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/test/utils.py" in instrumented_test_render
  62.     return self.nodelist.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  53.             result = self.nodelist.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  185.                         nodelist.append(node.render(context))
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/defaulttags.py" in render
  476.         output = self.nodelist.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  53.             result = self.nodelist.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/template/debug.py" in render
  87.             output = force_unicode(output)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/utils/encoding.py" in force_unicode
  71.                 s = unicode(s)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/utils/functional.py" in __unicode_cast
  121.             return func(*self.__args, **self.__kw)
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/utils/text.py" in <lambda>
  17. capfirst = lambda x: x and force_unicode(x)[0].upper() + force_unicode(x)[1:]
File "/Users/poswald/Projects/env/lib/python2.7/site-packages/django/utils/functional.py" in __wrapper__
  112.                 raise TypeError("Lazy object returned unexpected type.")
gregmuellegger commented 11 years ago

This issue seems to go away, when you pass in a unicode literal as the second argument to pgettext_lazy:

my_thing = models.CharField(
    pgettext_lazy('Context for this widget', u'Name'),
    blank=True,
    max_length=200)

But I cannot say exactly yet why this is happening. Might be a django related issue though..

gregmuellegger commented 9 years ago

Is this still relevant for you? I will close it since it sits there already for a long time without response. Feel free to reopen this ticket or create a new one if you think this is a still valid bug in django-floppyforms.