Render plurals

This commit is contained in:
Michal Čihař 2012-03-01 13:35:31 +01:00
parent 3c384e17c0
commit e658c65b19

View File

@ -1,13 +1,23 @@
from django import forms from django import forms
from django.utils.translation import ugettext_lazy, ugettext as _ from django.utils.translation import ugettext_lazy, ugettext as _
from django.utils.safestring import mark_safe
class PluralTextarea(forms.Textarea): class PluralTextarea(forms.Textarea):
''' '''
Text area extension which possibly handles plurals. Text area extension which possibly handles plurals.
''' '''
def render(self, name, value, attrs=None): def render(self, name, value, attrs=None):
ret = super(PluralTextarea, self).render(name, value, attrs) if type(value) != list:
return ret return super(PluralTextarea, self).render(name, value, attrs)
ret = []
print value
for idx, val in enumerate(value):
if idx > 0:
fieldname = '%s_%d' % (name, idx)
else:
fieldname = name
ret.append(super(PluralTextarea, self).render(fieldname, val, attrs))
return mark_safe('<br />'.join(ret))
class TranslationForm(forms.Form): class TranslationForm(forms.Form):
checksum = forms.CharField(widget = forms.HiddenInput) checksum = forms.CharField(widget = forms.HiddenInput)