diff --git a/scipost/templates/widgets/checkbox_as_btn.html b/scipost/templates/widgets/checkbox_as_btn.html new file mode 100644 index 0000000000000000000000000000000000000000..b4ea0363aafd9f5ee9f6301682ff7d6b94aca1a6 --- /dev/null +++ b/scipost/templates/widgets/checkbox_as_btn.html @@ -0,0 +1,7 @@ +{% with id=widget.attrs.id %} + {% for group, options, index in widget.optgroups %} + {% for option in options %} + {% include 'widgets/checkbox_option_as_btn.html' with widget=option %} + {% endfor %} + {% endfor %} +{% endwith %} diff --git a/scipost/templates/widgets/checkbox_option_as_btn.html b/scipost/templates/widgets/checkbox_option_as_btn.html new file mode 100644 index 0000000000000000000000000000000000000000..191c44ea168836f19bac6b0fda9740e47dd1e0cc --- /dev/null +++ b/scipost/templates/widgets/checkbox_option_as_btn.html @@ -0,0 +1,4 @@ + +{% include "django/forms/widgets/input.html" %} +<label{% if widget.attrs.id %} class="btn btn-info" for="{{ widget.attrs.id }}"{% endif %}> +{{ widget.label }}</label> diff --git a/scipost/templatetags/extra_form_widgets.py b/scipost/templatetags/extra_form_widgets.py new file mode 100644 index 0000000000000000000000000000000000000000..3d05ac0b95df1ff8aa7934b97abe4d748378d8c4 --- /dev/null +++ b/scipost/templatetags/extra_form_widgets.py @@ -0,0 +1,12 @@ +from django import template + +from ..widgets import SelectButtonWidget + + +register = template.Library() + + +@register.filter +def checkboxes_as_btn(field): + w = field.field.widget + return field.as_widget(SelectButtonWidget(attrs=w.attrs, choices=w.choices)) diff --git a/scipost/widgets.py b/scipost/widgets.py new file mode 100644 index 0000000000000000000000000000000000000000..93602aef98bc498f1d6081e6cba02cfbb7e60aa6 --- /dev/null +++ b/scipost/widgets.py @@ -0,0 +1,5 @@ +from django.forms.widgets import CheckboxSelectMultiple + + +class SelectButtonWidget(CheckboxSelectMultiple): + template_name = 'widgets/checkbox_as_btn.html' diff --git a/templates/search/search.html b/templates/search/search.html index c3d2cce40d8a339208017a0025e546b60df95041..053dd3a4dda6adc3323fa5e5b14b1e4fe86e73ab 100644 --- a/templates/search/search.html +++ b/templates/search/search.html @@ -1,7 +1,7 @@ {% extends 'scipost/base.html' %} {% load bootstrap %} -{# {% load highlight %}#} +{% load extra_form_widgets %} {% block pagetitle %}: list{% endblock pagetitle %} @@ -22,13 +22,7 @@ <label>Type</label> </div> <div class="form-group checkboxes auto-submit"> - {% for field in form.models %} - <input type="checkbox" name="{{field.name}}" id="{{field.id_for_label}}" value="{{field.choice_value|stringformat:'s'}}" {% if field.choice_value in form.models.value %}checked="checked"{% endif %}> - <label class="btn btn-info" for="{{field.id_for_label}}"> - {{field.choice_label}} - </label> - - {% endfor %} + {{form.models|checkboxes_as_btn}} </div> <label>Date from</label>