From b0fe08d5ee14c7dc60715818762e977ba9bc98d4 Mon Sep 17 00:00:00 2001 From: Sonny Date: Sun, 26 Jul 2020 13:19:50 +0200 Subject: [PATCH] Dont't overwrite default checkbox This caused issues in the admin --- src/newsreader/core/forms.py | 9 +++++++++ src/newsreader/news/collection/forms.py | 5 ++++- .../news/core/templates/news/core/widgets/rule.html | 2 +- src/newsreader/templates/components/form/checkbox.html | 9 +++------ src/newsreader/templates/components/form/input.html | 2 +- src/newsreader/templates/django/forms/widgets/attrs.html | 1 - .../templates/django/forms/widgets/checkbox.html | 1 - 7 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/newsreader/core/forms.py delete mode 120000 src/newsreader/templates/django/forms/widgets/attrs.html delete mode 120000 src/newsreader/templates/django/forms/widgets/checkbox.html diff --git a/src/newsreader/core/forms.py b/src/newsreader/core/forms.py new file mode 100644 index 0000000..ca3fe22 --- /dev/null +++ b/src/newsreader/core/forms.py @@ -0,0 +1,9 @@ +from django import forms + + +class CheckboxInput(forms.CheckboxInput): + template_name = "components/form/checkbox.html" + + def get_context(self, name, value, attrs): + context = super().get_context(name, value, attrs) + return {**context, **attrs} diff --git a/src/newsreader/news/collection/forms.py b/src/newsreader/news/collection/forms.py index 604500d..c79a867 100644 --- a/src/newsreader/news/collection/forms.py +++ b/src/newsreader/news/collection/forms.py @@ -5,6 +5,7 @@ from django.utils.translation import gettext_lazy as _ import pytz +from newsreader.core.forms import CheckboxInput from newsreader.news.collection.choices import RuleTypeChoices from newsreader.news.collection.models import CollectionRule from newsreader.news.collection.reddit import REDDIT_API_URL @@ -95,4 +96,6 @@ class SubRedditRuleForm(CollectionRuleForm): class OPMLImportForm(forms.Form): file = forms.FileField(allow_empty_file=False) - skip_existing = forms.BooleanField(initial=False, required=False) + skip_existing = forms.BooleanField( + initial=False, required=False, widget=CheckboxInput + ) 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 c8535e8..beebe29 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 widget=option checked=option.selected id_for_label=id_for_label only %} + {% include "components/form/checkbox.html" with name=option.name value=option.value checked=option.selected id=id_for_label only %} {% endwith %} {% if option.instance.favicon %} diff --git a/src/newsreader/templates/components/form/checkbox.html b/src/newsreader/templates/components/form/checkbox.html index 42ac691..c36d5f6 100644 --- a/src/newsreader/templates/components/form/checkbox.html +++ b/src/newsreader/templates/components/form/checkbox.html @@ -1,10 +1,7 @@
- {% 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 index 08f32e1..1ecfaaf 100644 --- a/src/newsreader/templates/components/form/input.html +++ b/src/newsreader/templates/components/form/input.html @@ -3,5 +3,5 @@ type="{{ widget.type }}" name="{{ widget.name }}" {% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %} {% endif %} - {% include "django/forms/widgets/attrs.html" %}> + {% include "components/form/attrs.html" %}> {% endspaceless %} diff --git a/src/newsreader/templates/django/forms/widgets/attrs.html b/src/newsreader/templates/django/forms/widgets/attrs.html deleted file mode 120000 index 595204e..0000000 --- a/src/newsreader/templates/django/forms/widgets/attrs.html +++ /dev/null @@ -1 +0,0 @@ -../../../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 deleted file mode 120000 index f939869..0000000 --- a/src/newsreader/templates/django/forms/widgets/checkbox.html +++ /dev/null @@ -1 +0,0 @@ -../../../components/form/checkbox.html \ No newline at end of file