Merge pull request #51 from SectorLabs/multiwidget

Copy the widget for each language
This commit is contained in:
Swen Kooij 2018-06-28 12:39:02 +03:00 committed by GitHub
commit 588f32086b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -1,4 +1,16 @@
{% for widget in widget.subwidgets %}
<label for="{{ widget.attrs.id }}">{{ widget.lang_name }}</label>
{% include widget.template_name %}
{% endfor %}
{% with widget_id=widget.attrs.id %}
<div class="localized-fields-widget" role="tabs" data-synctabs="translation">
<ul class="localized-fields-widget tabs">
{% for widget in widget.subwidgets %}
<li class="localized-fields-widget tab">
<label for="{{ widget_id }}_{{ widget.lang_code }}">{{ widget.lang_name|capfirst }}</label>
</li>
{% endfor %}
</ul>
{% for widget in widget.subwidgets %}
<div role="tabpanel" id="{{ widget_id }}_{{ widget.lang_code }}">
{% include widget.template_name %}
</div>
{% endfor %}
</div>
{% endwith %}

View File

@ -1,3 +1,5 @@
import copy
from typing import List
from django.conf import settings
@ -16,7 +18,7 @@ class LocalizedFieldWidget(forms.MultiWidget):
"""Initializes a new instance of :see:LocalizedFieldWidget."""
initial_widgets = [
self.widget
copy.copy(self.widget)
for _ in settings.LANGUAGES
]

View File

@ -16,6 +16,7 @@ class LocalizedFieldWidgetTestCase(TestCase):
widget = LocalizedFieldWidget()
assert len(widget.widgets) == len(settings.LANGUAGES)
assert len(set(widget.widgets)) == len(widget.widgets)
@staticmethod
def test_decompress():