Add labels to localized subwidgets

This commit is contained in:
Unai Zalakain 2017-07-10 15:30:03 +02:00 committed by Swen Kooij
parent d4c24dea97
commit e8e044f6e2
2 changed files with 9 additions and 0 deletions

View File

@ -0,0 +1,4 @@
{% for widget in widget.subwidgets %}
<label for="{{ widget.attrs.id }}">{{ widget.attrs.lang_name }}</label>
{% include widget.template_name %}
{% endfor %}

View File

@ -10,6 +10,7 @@ from .value import LocalizedValue
class LocalizedFieldWidget(forms.MultiWidget):
"""Widget that has an input box for every language."""
template_name = 'localized_fields/multiwidget.html'
widget = forms.Textarea
def __init__(self, *args, **kwargs):
@ -22,6 +23,10 @@ class LocalizedFieldWidget(forms.MultiWidget):
super().__init__(initial_widgets, *args, **kwargs)
for ((lc, ln), w) in zip(settings.LANGUAGES, self.widgets):
w.attrs['lang_code'] = lc
w.attrs['lang_name'] = ln
def decompress(self, value: LocalizedValue) -> List[str]:
"""Decompresses the specified value so
it can be spread over the internal widgets.