From 8339f1ee4d914c20c67c7b18f1f40e518eba367f Mon Sep 17 00:00:00 2001 From: Johanna England Date: Wed, 9 Oct 2024 12:53:06 +0200 Subject: [PATCH] Use newer way of uncrispifying forms This removes our old idea of adding templates and uses the new way that reimplemented crispy fields --- python/nav/web/seeddb/forms/__init__.py | 4 +++- python/nav/web/templates/seeddb/_form_fields.html | 3 --- python/nav/web/templates/seeddb/edit.html | 6 ++---- 3 files changed, 5 insertions(+), 8 deletions(-) delete mode 100644 python/nav/web/templates/seeddb/_form_fields.html diff --git a/python/nav/web/seeddb/forms/__init__.py b/python/nav/web/seeddb/forms/__init__.py index 5c1f8bb21d..4919dae8c6 100644 --- a/python/nav/web/seeddb/forms/__init__.py +++ b/python/nav/web/seeddb/forms/__init__.py @@ -33,6 +33,7 @@ ) from nav.models.cabling import Cabling from nav.oids import OID +from nav.web.crispyforms import set_flat_form_attributes _logger = logging.getLogger(__name__) @@ -312,7 +313,6 @@ class DeviceGroupForm(forms.ModelForm): queryset=Netbox.objects.all(), required=False ) netboxes.widget.attrs.update({"class": "select2"}) - no_crispy = True def __init__(self, *args, **kwargs): # If the form is based on an existing model instance, populate the @@ -322,6 +322,8 @@ def __init__(self, *args, **kwargs): initial['netboxes'] = [n.pk for n in kwargs['instance'].netboxes.all()] forms.ModelForm.__init__(self, *args, **kwargs) + self.attrs = set_flat_form_attributes() + class Meta(object): model = NetboxGroup fields = '__all__' diff --git a/python/nav/web/templates/seeddb/_form_fields.html b/python/nav/web/templates/seeddb/_form_fields.html deleted file mode 100644 index a7f47e9f4a..0000000000 --- a/python/nav/web/templates/seeddb/_form_fields.html +++ /dev/null @@ -1,3 +0,0 @@ -{% for field in form %} - {% include "foundation-5/field.html" %} -{% endfor %} diff --git a/python/nav/web/templates/seeddb/edit.html b/python/nav/web/templates/seeddb/edit.html index b411845138..0c68208a30 100644 --- a/python/nav/web/templates/seeddb/edit.html +++ b/python/nav/web/templates/seeddb/edit.html @@ -41,10 +41,8 @@

{{ title }}
Attributes - {% if form.no_crispy %} - {% block formfields %} - {% include "seeddb/_form_fields.html" %} - {% endblock %} + {% if form.attrs %} + {% include 'custom_crispy_templates/_form_content.html' %} {% else %} {% block crispyfields %} {{ form|crispy }}