From f5e08d55f71af8849dc331b3048b6d7e3bdfdba5 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Wed, 1 Apr 2020 13:26:15 +0200 Subject: [PATCH] Restore SelectWidgetBootstrap but simplify it to almost nothing --- src/wiki/forms.py | 50 ++++++++----------- src/wiki/templates/wiki/forms/select.html | 15 ------ .../templates/wiki/forms/select_option.html | 1 - 3 files changed, 22 insertions(+), 44 deletions(-) delete mode 100644 src/wiki/templates/wiki/forms/select.html delete mode 100644 src/wiki/templates/wiki/forms/select_option.html diff --git a/src/wiki/forms.py b/src/wiki/forms.py index 26d37076..2d781bd9 100644 --- a/src/wiki/forms.py +++ b/src/wiki/forms.py @@ -149,7 +149,7 @@ class SpamProtectionMixin: gettext( "Spam protection: You are only allowed to create or edit %(revisions)d article(s) per %(interval_name)s." ) - % {"revisions": max_count, "interval_name": interval_name,} + % {"revisions": max_count, "interval_name": interval_name} ) if not settings.LOG_IPS_ANONYMOUS: @@ -323,35 +323,22 @@ class EditForm(forms.Form, SpamProtectionMixin): class SelectWidgetBootstrap(forms.Select): """ - http://twitter.github.com/bootstrap/components.html#buttonDropdowns - Needs bootstrap and jquery + Formerly, we used Bootstrap 3's dropdowns. They look nice. But to + reduce bugs and reliance on JavaScript, it's now been replaced by + a conventional system platform drop-down. + + https://getbootstrap.com/docs/4.4/components/dropdowns/ """ - template_name = "wiki/forms/select.html" - option_template_name = "wiki/forms/select_option.html" + def __init__(self, attrs=None, choices=()): + if attrs is None: + attrs = {"class": ""} + elif "class" not in attrs: + attrs["class"] = "" + attrs["class"] += " form-control" - def __init__(self, attrs={}, choices=(), disabled=False): - attrs["class"] = "btn-group float-left btn-group-form" - self.disabled = disabled - self.noscript_widget = forms.Select(attrs={}, choices=choices) super().__init__(attrs, choices) - def __setattr__(self, k, value): - super().__setattr__(k, value) - if k not in ("attrs", "disabled"): - self.noscript_widget.__setattr__(k, value) - - def get_context(self, name, value, attrs): - context = super().get_context(name, value, attrs) - context["label"] = _("Select an option") - context["noscript"] = self.noscript_widget.render(name, value, {}) - context["disabled"] = " disabled" if self.disabled else "" - return context - - class Media(forms.Media): - - js = ("wiki/js/forms.js",) - class TextInputPrepend(forms.TextInput): template_name = "wiki/forms/text.html" @@ -447,9 +434,14 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm): help_text=_("Enter the username of the owner."), ) group = forms.ModelChoiceField( - Group.objects.all(), empty_label=_("(none)"), label=_("Group"), required=False, - widget=forms.Select(attrs={"class": "form-control"}) + Group.objects.all(), + empty_label=_("(none)"), + label=_("Group"), + required=False, + widget=forms.Select(attrs={"class": "form-control"}), ) + if settings.USE_BOOTSTRAP_SELECT_WIDGET: + group.widget = SelectWidgetBootstrap() recursive = forms.BooleanField( label=_("Inherit permissions"), @@ -510,7 +502,9 @@ class PermissionsForm(PluginSettingsFormMixin, forms.ModelForm): else Group.objects.none(), empty_label=_("(none)"), required=False, - widget=forms.Select(attrs={"disabled": True}), + widget=SelectWidgetBootstrap(disabled=True) + if settings.USE_BOOTSTRAP_SELECT_WIDGET + else forms.Select(attrs={"disabled": True}), ) self.fields["group_read"].widget = forms.HiddenInput() self.fields["group_write"].widget = forms.HiddenInput() diff --git a/src/wiki/templates/wiki/forms/select.html b/src/wiki/templates/wiki/forms/select.html deleted file mode 100644 index c0a2e615..00000000 --- a/src/wiki/templates/wiki/forms/select.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - diff --git a/src/wiki/templates/wiki/forms/select_option.html b/src/wiki/templates/wiki/forms/select_option.html deleted file mode 100644 index 30ff9787..00000000 --- a/src/wiki/templates/wiki/forms/select_option.html +++ /dev/null @@ -1 +0,0 @@ -
  • {{ widget.label }}
  • -- 2.45.2