From 4ee04ddae61c891575b575116c3fa47caf68e8b6 Mon Sep 17 00:00:00 2001 From: Dylan Verheul Date: Sun, 11 Apr 2021 08:39:50 +0200 Subject: [PATCH] Remove buttons tag (#37) * Remove buttons tag * Update documentation --- CHANGELOG.md | 1 + MIGRATE.md | 24 +++++++ README.md | 5 +- docs/example_template.rst | 10 +-- docs/migrate.rst | 23 +------ example/templates/app/form.html | 1 - example/templates/app/form_by_field.html | 6 +- example/templates/app/form_horizontal.html | 5 +- example/templates/app/form_inline.html | 5 +- example/templates/app/form_with_files.html | 5 +- example/templates/app/formset.html | 5 +- .../templatetags/django_bootstrap5.py | 64 +------------------ tests/test_bootstrap_form.py | 6 -- 13 files changed, 55 insertions(+), 105 deletions(-) create mode 100644 MIGRATE.md diff --git a/CHANGELOG.md b/CHANGELOG.md index ff3d1ab2..d03ad9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [0.3.0] - In development +- Remove `buttons` tag. - Drop support for Django 3.0, extended support stopped on 2021-04-01). - Add support for Django 3.2. diff --git a/MIGRATE.md b/MIGRATE.md new file mode 100644 index 00000000..43ac4dd1 --- /dev/null +++ b/MIGRATE.md @@ -0,0 +1,24 @@ +# Migration Guide + +Below is a list of caveats when migrating from `django-bootstrap4` (Bootstrap 4) to `django-bootstrap5` (Bootstrap 5). + +This document only considers the differences between `django-bootstrap4` and `django-bootstrap5`. For the migration +guide from Bootstrap 3 to 4, please look at the Bootstrap docs, especially the `Migration section `_. + +## Removed templatetags + +### buttons + +The `{% buttons %} ... {% endbuttons %}` tag has bene removed. To create buttons, use the `{% bootstrap_button %}` tag. + +## jQuery + +Bootstrap 5 does not depend on jQuery. Every function and tag referencing jQuery has been removed. + +If you need jQuery, you will have to include it yourself. + +## Popper + +We use the bundled version of Bootstrap 5 JavaScript that includes Popper. + +If you need a separate Popper.js file, do not use the `{% bootstrap_javascript %}` tag, but load the JavaScript yourself. \ No newline at end of file diff --git a/README.md b/README.md index 0b560606..63d4e796 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,8 @@ The full documentation is at https://django-bootstrap5.readthedocs.io/
{% csrf_token %} {% bootstrap_form form %} - {% buttons %} - - {% endbuttons %} + {% bootstrap_button button_type="submit" content="OK" %} + {% bootstrap_button button_type="reset" content="Cancel" %}
``` diff --git a/docs/example_template.rst b/docs/example_template.rst index 1b47364a..7918fb3f 100644 --- a/docs/example_template.rst +++ b/docs/example_template.rst @@ -13,12 +13,12 @@ {# Display a form #}
{% csrf_token %} + {% bootstrap_form form %} - {% buttons %} - - {% endbuttons %} + + {% bootstrap_button button_type="submit" content="OK" %} + {% bootstrap_button button_type="reset" content="Cancel" %} +
{# Read the documentation for more information #} diff --git a/docs/migrate.rst b/docs/migrate.rst index bbc7f8e7..aff377ed 100644 --- a/docs/migrate.rst +++ b/docs/migrate.rst @@ -1,22 +1 @@ -========= -Migration -========= - -Below is a list of caveats when migrating from `django-bootstrap4` (Bootstrap 4) to `django-bootstrap5` (Bootstrap 5). - -This document only considers the differences between `django-bootstrap4` and `django-bootstrap5`. For the migration -guide from Bootstrap 3 to 4, please look at the Bootstrap docs, especially the `Migration section `_. - -jQuery ------- - -Bootstrap 5 does not depend on jQuery. Every function and tag referencing jQuery has been removed. - -If you need jQuery, you will have to include it yourself. - -Popper ------- - -We use the Bootstrap 5 JavaScript that has bundled Popper. - -If you want a separate Popper.js file, do not use the `{% bootstrap_javascript %}` tag, but load the JavaScript yourself. \ No newline at end of file +.. mdinclude:: ../MIGRATE.md \ No newline at end of file diff --git a/example/templates/app/form.html b/example/templates/app/form.html index ed7c7016..23cfc106 100644 --- a/example/templates/app/form.html +++ b/example/templates/app/form.html @@ -14,7 +14,6 @@ {% bootstrap_button button_type="submit" content="OK" %} {% bootstrap_button button_type="reset" content="Cancel" %} - {% endblock %} diff --git a/example/templates/app/form_by_field.html b/example/templates/app/form_by_field.html index 6f6bcc8b..80a2b80a 100644 --- a/example/templates/app/form_by_field.html +++ b/example/templates/app/form_by_field.html @@ -10,10 +10,14 @@
{% csrf_token %} + {% bootstrap_form_errors form type='non_fields' %} + {% bootstrap_field form.subject layout='horizontal' size='sm' %} {% bootstrap_field form.message placeholder='bonkers' %} - {% buttons submit='OK' reset="Cancel" %}{% endbuttons %} + + {% bootstrap_button button_type="submit" content="OK" %} + {% bootstrap_button button_type="reset" content="Cancel" %}
{% endblock %} diff --git a/example/templates/app/form_horizontal.html b/example/templates/app/form_horizontal.html index 947b8bf9..da1c37d7 100644 --- a/example/templates/app/form_horizontal.html +++ b/example/templates/app/form_horizontal.html @@ -10,8 +10,11 @@
{% csrf_token %} + {% bootstrap_form form layout="horizontal" %} - {% buttons submit='OK' reset='Cancel' layout='horizontal' %}{% endbuttons %} + + {% bootstrap_button button_type="submit" content="OK" %} + {% bootstrap_button button_type="reset" content="Cancel" %}
{% endblock %} diff --git a/example/templates/app/form_inline.html b/example/templates/app/form_inline.html index 47362ab7..283b09ee 100644 --- a/example/templates/app/form_inline.html +++ b/example/templates/app/form_inline.html @@ -10,8 +10,11 @@
{% csrf_token %} + {% bootstrap_form form layout='inline' %} - {% buttons submit='OK' reset='Cancel' layout='inline' %}{% endbuttons %} + + {% bootstrap_button button_type="submit" content="OK" %} + {% bootstrap_button button_type="reset" content="Cancel" %}
{% endblock %} diff --git a/example/templates/app/form_with_files.html b/example/templates/app/form_with_files.html index 011a9ea3..16197d15 100644 --- a/example/templates/app/form_with_files.html +++ b/example/templates/app/form_with_files.html @@ -10,8 +10,11 @@
{% csrf_token %} + {% bootstrap_form form layout=layout %} - {% buttons submit='OK' reset="Cancel" %}{% endbuttons %} + + {% bootstrap_button button_type="submit" content="OK" %} + {% bootstrap_button button_type="reset" content="Cancel" %}
{% endblock %} diff --git a/example/templates/app/formset.html b/example/templates/app/formset.html index 27a6548b..06db9886 100644 --- a/example/templates/app/formset.html +++ b/example/templates/app/formset.html @@ -10,8 +10,11 @@ {% bootstrap_formset_errors form %}
{% csrf_token %} + {% bootstrap_formset form %} - {% buttons submit='OK' reset="Cancel" %}{% endbuttons %} + + {% bootstrap_button button_type="submit" content="OK" %} + {% bootstrap_button button_type="reset" content="Cancel" %}
{% endblock %} diff --git a/src/django_bootstrap5/templatetags/django_bootstrap5.py b/src/django_bootstrap5/templatetags/django_bootstrap5.py index c9bcdb2a..b7c49c75 100644 --- a/src/django_bootstrap5/templatetags/django_bootstrap5.py +++ b/src/django_bootstrap5/templatetags/django_bootstrap5.py @@ -12,16 +12,14 @@ from ..forms import ( render_button, render_field, - render_field_and_label, render_form, render_form_errors, - render_form_group, render_formset, render_formset_errors, render_label, ) from ..html import render_link_tag, render_script_tag -from ..utils import handle_var, parse_token_contents, render_template_file, url_replace_param +from ..utils import render_template_file, url_replace_param MESSAGE_ALERT_TYPES = { message_constants.DEBUG: "warning", @@ -614,66 +612,6 @@ def bootstrap_alert(content, alert_type="info", dismissible=True, extra_classes= return render_alert(content, alert_type, dismissible, extra_classes) -@register.tag("buttons") -def bootstrap_buttons(parser, token): - """ - Render buttons for form. - - **Tag name**:: - - buttons - - **Parameters**:: - - submit - Text for a submit button - - reset - Text for a reset button - - **Usage**:: - - {% buttons %}{% endbuttons %} - - **Example**:: - - {% buttons submit='OK' reset="Cancel" %}{% endbuttons %} - """ - kwargs = parse_token_contents(parser, token) - kwargs["nodelist"] = parser.parse(("endbuttons",)) - parser.delete_first_token() - return ButtonsNode(**kwargs) - - -class ButtonsNode(template.Node): - def __init__(self, nodelist, args, kwargs, asvar, **kwargs2): - self.nodelist = nodelist - self.args = args - self.kwargs = kwargs - self.asvar = asvar - - def render(self, context): - output_kwargs = {} - for key in self.kwargs: - output_kwargs[key] = handle_var(self.kwargs[key], context) - buttons = [] - submit = output_kwargs.get("submit", None) - reset = output_kwargs.get("reset", None) - if submit: - buttons.append(bootstrap_button(submit, "submit")) - if reset: - buttons.append(bootstrap_button(reset, "reset")) - buttons = " ".join(buttons) + self.nodelist.render(context) - output_kwargs.update({"label": None, "field": buttons}) - css_class = output_kwargs.pop("wrapper_class", "form-group") - output = render_form_group(render_field_and_label(**output_kwargs), css_class=css_class) - if self.asvar: - context[self.asvar] = output - return "" - else: - return output - - @register.simple_tag(takes_context=True) def bootstrap_messages(context, *args, **kwargs): """ diff --git a/tests/test_bootstrap_form.py b/tests/test_bootstrap_form.py index 0c1043f5..a36c50a8 100644 --- a/tests/test_bootstrap_form.py +++ b/tests/test_bootstrap_form.py @@ -51,12 +51,6 @@ def test_exclude(self): # self.assertIn("hlabel", res) # self.assertIn("hfield", res) - def test_buttons_tag(self): - form = TestForm() - res = render_template_with_form('{% buttons layout="horizontal" %}{% endbuttons %}', {"form": form}) - self.assertIn("col-md-3", res) - self.assertIn("col-md-9", res) - def test_error_class(self): form = TestForm({"sender": "sender"}) res = render_template_with_form("{% bootstrap_form form %}", {"form": form})