From a760bd618816ac9489ac3456c20eeaf3232fad9e Mon Sep 17 00:00:00 2001 From: sonny Date: Tue, 2 Jun 2020 20:34:29 +0200 Subject: [PATCH] Use overridden input.html & attrs.html --- .../core/templates/news/core/widgets/rule.html | 2 +- .../templates/components/form/attrs.html | 18 ++++++++++++++++++ .../templates/components/form/checkbox.html | 10 ++++------ .../templates/components/form/input.html | 7 +++++++ .../templates/django/forms/widgets/attrs.html | 1 + .../django/forms/widgets/checkbox.html | 1 + 6 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 src/newsreader/templates/components/form/attrs.html create mode 100644 src/newsreader/templates/components/form/input.html create mode 120000 src/newsreader/templates/django/forms/widgets/attrs.html create mode 120000 src/newsreader/templates/django/forms/widgets/checkbox.html diff --git a/src/newsreader/news/core/templates/news/core/widgets/rule.html b/src/newsreader/news/core/templates/news/core/widgets/rule.html index 11cdef5..c8535e8 100644 --- a/src/newsreader/news/core/templates/news/core/widgets/rule.html +++ b/src/newsreader/news/core/templates/news/core/widgets/rule.html @@ -1,7 +1,7 @@ {% load filters %} {% with option.instance|id_for_label:"category" as id_for_label %} - {% include "components/form/checkbox.html" with name=option.name value=option.value|stringformat:'s' id=id_for_label id_for_label=id_for_label checked=option.selected only %} + {% include "components/form/checkbox.html" with widget=option checked=option.selected id_for_label=id_for_label only %} {% endwith %} {% if option.instance.favicon %} diff --git a/src/newsreader/templates/components/form/attrs.html b/src/newsreader/templates/components/form/attrs.html new file mode 100644 index 0000000..50aec9b --- /dev/null +++ b/src/newsreader/templates/components/form/attrs.html @@ -0,0 +1,18 @@ +{% spaceless %} + {% for name, value in widget.attrs.items %} + {% if value is not False %} + {{ name }} + + {% if value is not True %} + ="{{ value|stringformat:'s' }}" + {% endif %} + {% endif %} + {% endfor %} + + {% if id %} id="{{ id }}"{% endif %} + {% if type %} type="{{ type }}"{% endif %} + {% if value %} value="{{ value }}"{% endif %} + {% if name %} name="{{ name }}"{% endif %} + {% if data_input %} data-input="{{ data_input }}"{% endif %} + {% if checked %} checked {% endif %} +{% endspaceless %} diff --git a/src/newsreader/templates/components/form/checkbox.html b/src/newsreader/templates/components/form/checkbox.html index 5840ae2..42ac691 100644 --- a/src/newsreader/templates/components/form/checkbox.html +++ b/src/newsreader/templates/components/form/checkbox.html @@ -1,12 +1,10 @@
- {% if field %} - {{ field }} + {% if widget %} + {% include "components/form/input.html" with widget=widget %} {% else %} - + {% include "components/form/input.html" with id=id name=name type="checkbox" value=value data_input=data_input checked=checked %} {% endif %} -
diff --git a/src/newsreader/templates/components/form/input.html b/src/newsreader/templates/components/form/input.html new file mode 100644 index 0000000..08f32e1 --- /dev/null +++ b/src/newsreader/templates/components/form/input.html @@ -0,0 +1,7 @@ +{% spaceless %} + +{% endspaceless %} diff --git a/src/newsreader/templates/django/forms/widgets/attrs.html b/src/newsreader/templates/django/forms/widgets/attrs.html new file mode 120000 index 0000000..595204e --- /dev/null +++ b/src/newsreader/templates/django/forms/widgets/attrs.html @@ -0,0 +1 @@ +../../../components/form/attrs.html \ No newline at end of file diff --git a/src/newsreader/templates/django/forms/widgets/checkbox.html b/src/newsreader/templates/django/forms/widgets/checkbox.html new file mode 120000 index 0000000..f939869 --- /dev/null +++ b/src/newsreader/templates/django/forms/widgets/checkbox.html @@ -0,0 +1 @@ +../../../components/form/checkbox.html \ No newline at end of file