[Python-modules-commits] [django-floppyforms] 01/05: Import django-floppyforms_1.6.2+dfsg.orig.tar.gz

Michael Fladischer fladi at moszumanska.debian.org
Sat Apr 23 18:08:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch master
in repository django-floppyforms.

commit 688d62b54403dfa26c9c14fb333683d72aa10800
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Sat Apr 23 12:08:45 2016 +0200

    Import django-floppyforms_1.6.2+dfsg.orig.tar.gz
---
 CHANGES.rst                                        | 10 +++++++
 floppyforms/__init__.py                            |  2 +-
 .../templates/floppyforms/clearable_input.html     |  6 ++--
 floppyforms/widgets.py                             |  7 +++++
 tests/test_widgets.py                              | 32 ++++++++++++++++++++++
 5 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index 250a524..4c32ff1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,16 @@
 Changelog
 ---------
 
+1.6.2
+~~~~~
+
+* `#169`_: Use the attributes ``ClearableFileInput.initial_text``,
+  ``ClearableFileInput.input_text``,
+  ``ClearableFileInput.clear_checkbox_label`` to determine the used text in the
+  template. This was inconsistent so far with Django's behaviour.
+
+.. _#169: https://github.com/gregmuellegger/django-floppyforms/issues/169
+
 1.6.1
 ~~~~~
 
diff --git a/floppyforms/__init__.py b/floppyforms/__init__.py
index e0d7b82..ef953a5 100644
--- a/floppyforms/__init__.py
+++ b/floppyforms/__init__.py
@@ -20,4 +20,4 @@ except Exception:
     warnings.warn(
         "Unable to import floppyforms.gis, geometry widgets not available")
 
-__version__ = '1.6.1'
+__version__ = '1.6.2'
diff --git a/floppyforms/templates/floppyforms/clearable_input.html b/floppyforms/templates/floppyforms/clearable_input.html
index abd91c9..1cfda74 100644
--- a/floppyforms/templates/floppyforms/clearable_input.html
+++ b/floppyforms/templates/floppyforms/clearable_input.html
@@ -1,8 +1,8 @@
-{% load i18n %}{% if value.url %}{% trans "Currently:" %} <a target="_blank" href="{{ value.url }}">{{ value }}</a>
+{% load i18n %}{% if value.url %}{{ initial_text }}: <a target="_blank" href="{{ value.url }}">{{ value }}</a>
 {% if not required %}
 <input type="checkbox" name="{{ checkbox_name }}" id="{{ checkbox_id }}">
-<label for="{{ checkbox_id }}">{% trans "Clear" %}</label>
+<label for="{{ checkbox_id }}">{{ clear_checkbox_label }}</label>
 {% endif %}<br />
-{% trans "Change:" %}
+{{ input_text }}:
 {% endif %}
 <input type="{{ type }}" name="{{ name }}"{% if required %} required{% endif %}{% include "floppyforms/attrs.html" %}>
diff --git a/floppyforms/widgets.py b/floppyforms/widgets.py
index f8d9f38..c890a6e 100644
--- a/floppyforms/widgets.py
+++ b/floppyforms/widgets.py
@@ -221,6 +221,10 @@ class ClearableFileInput(FileInput):
     template_name = 'floppyforms/clearable_input.html'
     omit_value = False
 
+    initial_text = _('Currently')
+    input_text = _('Change')
+    clear_checkbox_label = _('Clear')
+
     def clear_checkbox_name(self, name):
         return name + '-clear'
 
@@ -232,6 +236,9 @@ class ClearableFileInput(FileInput):
                                                               attrs)
         ccb_name = self.clear_checkbox_name(name)
         context.update({
+            'clear_checkbox_label': self.clear_checkbox_label,
+            'initial_text': self.initial_text,
+            'input_text': self.input_text,
             'checkbox_name': ccb_name,
             'checkbox_id': self.clear_checkbox_id(ccb_name),
         })
diff --git a/tests/test_widgets.py b/tests/test_widgets.py
index 881c644..6abe8aa 100644
--- a/tests/test_widgets.py
+++ b/tests/test_widgets.py
@@ -1182,6 +1182,38 @@ class WidgetRenderingTest(TestCase):
             <input type="file" name="file_" id="id_file_">
         </p>""")
 
+    def test_clearable_file_input_with_custom_labels(self):
+        class MyFileInput(forms.ClearableFileInput):
+            initial_text = 'INITIAL_TEXT'
+            input_text = 'INPUT_TEXT'
+            clear_checkbox_label = 'CLEAR_CHECKBOX_LABEL'
+
+        class Form(forms.Form):
+            file_ = forms.FileField(required=False, widget=MyFileInput)
+
+        fake_instance = {'url': 'test test'}
+        rendered = Form(initial={'file_': fake_instance}).as_p()
+        self.assertHTMLEqual(rendered, """
+        <p>
+            <label for="id_file_">File :</label>
+            INITIAL_TEXT: <a target="_blank" href="test test">{'url': 'test test'}</a>
+            <input type="checkbox" name="file_-clear" id="file_-clear_id">
+            <label for="file_-clear_id">CLEAR_CHECKBOX_LABEL</label><br>INPUT_TEXT:
+            <input type="file" name="file_" id="id_file_">
+        </p>""")
+
+        form = Form(initial={'file_': fake_instance},
+                    data={'file_-clear': True})
+        self.assertTrue(form.is_valid())
+        self.assertHTMLEqual(rendered, """
+        <p>
+            <label for="id_file_">File :</label>
+            INITIAL_TEXT: <a target="_blank" href="test test">{'url': 'test test'}</a>
+            <input type="checkbox" name="file_-clear" id="file_-clear_id">
+            <label for="file_-clear_id">CLEAR_CHECKBOX_LABEL</label><br>INPUT_TEXT:
+            <input type="file" name="file_" id="id_file_">
+        </p>""")
+
     def test_rendered_file_input(self):
         class Form(forms.Form):
             file_ = forms.FileField()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-floppyforms.git



More information about the Python-modules-commits mailing list