From ab89d12fe66d6b0954963c190bf62d2d219c01ec Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 8 Nov 2024 16:25:29 +0100 Subject: [PATCH 1/4] Rename parameter and add type hint --- python/nav/web/seeddb/forms/__init__.py | 4 ++-- python/nav/web/seeddb/page/management_profile/forms.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/nav/web/seeddb/forms/__init__.py b/python/nav/web/seeddb/forms/__init__.py index e2170eef9a..54befbe69c 100644 --- a/python/nav/web/seeddb/forms/__init__.py +++ b/python/nav/web/seeddb/forms/__init__.py @@ -129,7 +129,7 @@ def cut_branch(field, klass, pk): # non-crispy helpers -def get_single_layout(heading, row): +def get_single_layout(heading, filter_fields: list): """Get default layout for a single filter""" return set_flat_form_attributes( form_class="custom", @@ -140,7 +140,7 @@ def get_single_layout(heading, row): fields=[ FormRow( fields=[ - FormColumn(fields=[row], css_classes="medium-8"), + FormColumn(fields=filter_fields, css_classes="medium-8"), FormColumn( fields=[ SubmitField( diff --git a/python/nav/web/seeddb/page/management_profile/forms.py b/python/nav/web/seeddb/page/management_profile/forms.py index 4c27665584..c6904ed9ac 100644 --- a/python/nav/web/seeddb/page/management_profile/forms.py +++ b/python/nav/web/seeddb/page/management_profile/forms.py @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs): super(ManagementProfileFilterForm, self).__init__(*args, **kwargs) self.attrs = get_single_layout( - heading="Filter connection profiles", row=self["protocol"] + heading="Filter connection profiles", filter_fields=[self["protocol"]] ) From fd88b5c64190136e27ad56bf154fd93033af2ccf Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Fri, 8 Nov 2024 16:26:53 +0100 Subject: [PATCH 2/4] Define form attrs inside dunder init This make filter fields render correctly --- python/nav/web/seeddb/forms/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/python/nav/web/seeddb/forms/__init__.py b/python/nav/web/seeddb/forms/__init__.py index 54befbe69c..a73db4a143 100644 --- a/python/nav/web/seeddb/forms/__init__.py +++ b/python/nav/web/seeddb/forms/__init__.py @@ -169,7 +169,12 @@ class RoomFilterForm(forms.Form): Location.objects.order_by('id').all(), required=False ) location.widget.attrs.update({"class": "select"}) - attrs = get_single_layout(heading="Filter rooms", row=[location]) + + def __init__(self, *args, **kwargs): + super(RoomFilterForm, self).__init__(*args, **kwargs) + self.attrs = get_single_layout( + heading="Filter rooms", filter_fields=[self["location"]] + ) class RoomForm(forms.ModelForm): @@ -285,7 +290,12 @@ class NetboxTypeFilterForm(forms.Form): """Form for filtering a netbox type by vendor""" vendor = forms.ModelChoiceField(Vendor.objects.order_by('id').all(), required=False) - attrs = get_single_layout(heading="Filter types", row=[vendor]) + + def __init__(self, *args, **kwargs): + super(NetboxTypeFilterForm, self).__init__(*args, **kwargs) + self.attrs = get_single_layout( + heading="Filter types", filter_fields=[self["vendor"]] + ) class NetboxTypeForm(forms.ModelForm): From 7cb665a3d6b0224cd148e09e53e2c38a8e8577cf Mon Sep 17 00:00:00 2001 From: Ilona Podliashanyk Date: Thu, 14 Nov 2024 14:30:30 +0100 Subject: [PATCH 3/4] Drop field list and only allow single field --- python/nav/web/seeddb/forms/__init__.py | 6 +++--- python/nav/web/seeddb/page/management_profile/forms.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/nav/web/seeddb/forms/__init__.py b/python/nav/web/seeddb/forms/__init__.py index a73db4a143..3b3ac2d8c7 100644 --- a/python/nav/web/seeddb/forms/__init__.py +++ b/python/nav/web/seeddb/forms/__init__.py @@ -129,7 +129,7 @@ def cut_branch(field, klass, pk): # non-crispy helpers -def get_single_layout(heading, filter_fields: list): +def get_single_layout(heading, filter_field): """Get default layout for a single filter""" return set_flat_form_attributes( form_class="custom", @@ -140,7 +140,7 @@ def get_single_layout(heading, filter_fields: list): fields=[ FormRow( fields=[ - FormColumn(fields=filter_fields, css_classes="medium-8"), + FormColumn(fields=[filter_field], css_classes="medium-8"), FormColumn( fields=[ SubmitField( @@ -294,7 +294,7 @@ class NetboxTypeFilterForm(forms.Form): def __init__(self, *args, **kwargs): super(NetboxTypeFilterForm, self).__init__(*args, **kwargs) self.attrs = get_single_layout( - heading="Filter types", filter_fields=[self["vendor"]] + heading="Filter types", filter_field=self["vendor"] ) diff --git a/python/nav/web/seeddb/page/management_profile/forms.py b/python/nav/web/seeddb/page/management_profile/forms.py index c6904ed9ac..c6e71696d1 100644 --- a/python/nav/web/seeddb/page/management_profile/forms.py +++ b/python/nav/web/seeddb/page/management_profile/forms.py @@ -32,7 +32,7 @@ def __init__(self, *args, **kwargs): super(ManagementProfileFilterForm, self).__init__(*args, **kwargs) self.attrs = get_single_layout( - heading="Filter connection profiles", filter_fields=[self["protocol"]] + heading="Filter connection profiles", filter_field=self["protocol"] ) From 111e075cb6a9b41164816231e7056669c7e92d6e Mon Sep 17 00:00:00 2001 From: podliashanyk <60876078+podliashanyk@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:37:58 +0100 Subject: [PATCH 4/4] Update python/nav/web/seeddb/forms/__init__.py Co-authored-by: Johanna England --- python/nav/web/seeddb/forms/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/nav/web/seeddb/forms/__init__.py b/python/nav/web/seeddb/forms/__init__.py index 3b3ac2d8c7..0f5e1bcae2 100644 --- a/python/nav/web/seeddb/forms/__init__.py +++ b/python/nav/web/seeddb/forms/__init__.py @@ -173,7 +173,7 @@ class RoomFilterForm(forms.Form): def __init__(self, *args, **kwargs): super(RoomFilterForm, self).__init__(*args, **kwargs) self.attrs = get_single_layout( - heading="Filter rooms", filter_fields=[self["location"]] + heading="Filter rooms", filter_field=self["location"] )