mirror of
https://github.com/SectorLabs/django-localized-fields.git
synced 2025-04-24 19:32:53 +03:00
Merge pull request #36 from MELScience/issue35
Fix non-valid HTML tags attributes
This commit is contained in:
commit
084f5dd0b6
@ -3,12 +3,12 @@
|
||||
<ul class="localized-fields-widget tabs">
|
||||
{% for widget in widget.subwidgets %}
|
||||
<li class="localized-fields-widget tab">
|
||||
<a href="#{{ widget_id }}_{{ widget.attrs.lang_code }}">{{ widget.attrs.lang_name|capfirst }}</a>
|
||||
<a href="#{{ widget_id }}_{{ widget.lang_code }}">{{ widget.lang_name|capfirst }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% for widget in widget.subwidgets %}
|
||||
<div role="tabpanel" id="{{ widget_id }}_{{ widget.attrs.lang_code }}">
|
||||
<div role="tabpanel" id="{{ widget_id }}_{{ widget.lang_code }}">
|
||||
{% include widget.template_name %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -1,4 +1,4 @@
|
||||
{% for widget in widget.subwidgets %}
|
||||
<label for="{{ widget.attrs.id }}">{{ widget.attrs.lang_name }}</label>
|
||||
<label for="{{ widget.attrs.id }}">{{ widget.lang_name }}</label>
|
||||
{% include widget.template_name %}
|
||||
{% endfor %}
|
||||
|
@ -23,8 +23,9 @@ class LocalizedFieldWidget(forms.MultiWidget):
|
||||
super().__init__(initial_widgets, *args, **kwargs)
|
||||
|
||||
for ((lang_code, lang_name), widget) in zip(settings.LANGUAGES, self.widgets):
|
||||
widget.attrs['lang_code'] = lang_code
|
||||
widget.attrs['lang_name'] = lang_name
|
||||
widget.attrs['lang'] = lang_code
|
||||
widget.lang_code = lang_code
|
||||
widget.lang_name = lang_name
|
||||
|
||||
def decompress(self, value: LocalizedValue) -> List[str]:
|
||||
"""Decompresses the specified value so
|
||||
@ -76,7 +77,12 @@ class LocalizedFieldWidget(forms.MultiWidget):
|
||||
else:
|
||||
widget_attrs = final_attrs
|
||||
widget_attrs = self.build_widget_attrs(widget, widget_value, widget_attrs)
|
||||
subwidgets.append(widget.get_context(widget_name, widget_value, widget_attrs)['widget'])
|
||||
widget_context = widget.get_context(widget_name, widget_value, widget_attrs)['widget']
|
||||
widget_context.update(dict(
|
||||
lang_code=widget.lang_code,
|
||||
lang_name=widget.lang_name
|
||||
))
|
||||
subwidgets.append(widget_context)
|
||||
context['widget']['subwidgets'] = subwidgets
|
||||
return context
|
||||
|
||||
|
@ -45,7 +45,7 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
||||
assert not value
|
||||
|
||||
@staticmethod
|
||||
def test_get_context():
|
||||
def test_get_context_required():
|
||||
"""Tests whether the :see:get_context correctly
|
||||
handles 'required' attribute, separately for each subwidget."""
|
||||
|
||||
@ -57,6 +57,21 @@ class LocalizedFieldWidgetTestCase(TestCase):
|
||||
assert context['widget']['subwidgets'][0]['attrs']['required']
|
||||
assert 'required' not in context['widget']['subwidgets'][1]['attrs']
|
||||
|
||||
@staticmethod
|
||||
def test_get_context_langs():
|
||||
"""Tests whether the :see:get_context contains 'lang_code' and
|
||||
'lang_name' attribute for each subwidget."""
|
||||
|
||||
widget = LocalizedFieldWidget()
|
||||
context = widget.get_context(name='test', value=LocalizedValue(),
|
||||
attrs=dict())
|
||||
subwidgets_context = context['widget']['subwidgets']
|
||||
for widget, context in zip(widget.widgets, subwidgets_context):
|
||||
assert 'lang_code' in context
|
||||
assert 'lang_name' in context
|
||||
assert widget.lang_code == context['lang_code']
|
||||
assert widget.lang_name == context['lang_name']
|
||||
|
||||
@staticmethod
|
||||
def test_render():
|
||||
"""Tests whether the :see:LocalizedFieldWidget correctly
|
||||
|
Loading…
x
Reference in New Issue
Block a user