From bc0ef97df9b5d5e4d984c96c32c27fd3f2cb9460 Mon Sep 17 00:00:00 2001 From: Marc Lebreuil Date: Mon, 9 Dec 2024 22:01:42 +0000 Subject: [PATCH] Add selectors when required --- CHANGELOG.md | 4 ++ src/netbox_contract/forms.py | 75 +++++++++++++++++++++++++----------- src/netbox_contract/views.py | 12 +++--- 3 files changed, 63 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c84f69..166aa61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ ## Version 2 +### Version 2.2.8 + +* [167](https://github.com/mlebreuil/netbox-contract/issues/167) Add selector to object dynamic selection box. + ### Version 2.2.7 * fix migration dependency diff --git a/src/netbox_contract/forms.py b/src/netbox_contract/forms.py index e7682b3..db4c1c5 100644 --- a/src/netbox_contract/forms.py +++ b/src/netbox_contract/forms.py @@ -65,8 +65,12 @@ class ContractForm(NetBoxModelForm): widget=HTMXSelect(), ) external_partie_object = forms.ModelChoiceField(queryset=None) - tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False) - parent = DynamicModelChoiceField(queryset=Contract.objects.all(), required=False) + tenant = DynamicModelChoiceField( + queryset=Tenant.objects.all(), required=False, selector=True + ) + parent = DynamicModelChoiceField( + queryset=Contract.objects.all(), required=False, selector=True + ) accounting_dimensions = Dimensions(required=False) def __init__(self, *args, **kwargs): @@ -157,15 +161,19 @@ def clean(self): ) -class ContractFilterSetForm(NetBoxModelFilterSetForm): +class ContractFilterForm(NetBoxModelFilterSetForm): model = Contract - tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False) + tenant = DynamicModelChoiceField( + queryset=Tenant.objects.all(), required=False, selector=True + ) external_reference = forms.CharField(required=False) internal_partie = forms.ChoiceField(choices=InternalEntityChoices, required=False) status = forms.ChoiceField(choices=StatusChoices, required=False) currency = forms.ChoiceField(choices=CurrencyChoices, required=False) - parent = DynamicModelChoiceField(queryset=Contract.objects.all(), required=False) + parent = DynamicModelChoiceField( + queryset=Contract.objects.all(), required=False, selector=True + ) tag = TagFilterField(model) @@ -233,10 +241,18 @@ class ContractBulkEditForm(NetBoxModelBulkEditForm): name = forms.CharField(max_length=100, required=False) external_reference = forms.CharField(max_length=100, required=False) internal_partie = forms.ChoiceField(choices=InternalEntityChoices, required=False) - tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False) + tenant = DynamicModelChoiceField( + queryset=Tenant.objects.all(), + required=False, + selector=True, + ) accounting_dimensions = Dimensions(required=False) comments = CommentField(required=False) - parent = DynamicModelChoiceField(queryset=Contract.objects.all(), required=False) + parent = DynamicModelChoiceField( + queryset=Contract.objects.all(), + required=False, + selector=True, + ) nullable_fields = ( 'accounting_dimensions', @@ -254,7 +270,7 @@ class InvoiceForm(NetBoxModelForm): help_text='Invoice template name will be overriden to _invoice_template_contract name', ) contracts = DynamicModelMultipleChoiceField( - queryset=Contract.objects.all(), required=False + queryset=Contract.objects.all(), required=False, selector=True ) accounting_dimensions = Dimensions(required=False) @@ -360,7 +376,7 @@ class Meta: } -class InvoiceFilterSetForm(NetBoxModelFilterSetForm): +class InvoiceFilterForm(NetBoxModelFilterSetForm): model = Invoice number = forms.CharField(required=False) template = forms.NullBooleanField( @@ -368,7 +384,9 @@ class InvoiceFilterSetForm(NetBoxModelFilterSetForm): ) currency = forms.ChoiceField(choices=CurrencyChoices, required=False) contracts = DynamicModelMultipleChoiceField( - queryset=Contract.objects.all(), required=False + queryset=Contract.objects.all(), + required=False, + selector=True, ) tag = TagFilterField(model) @@ -403,7 +421,9 @@ class InvoiceBulkEditForm(NetBoxModelBulkEditForm): template = forms.BooleanField(required=False) date = forms.DateField(required=False) contracts = DynamicModelMultipleChoiceField( - queryset=Contract.objects.all(), required=False + queryset=Contract.objects.all(), + required=False, + selector=True, ) period_start = forms.DateField(required=False) period_end = forms.DateField(required=False) @@ -432,7 +452,7 @@ class Meta: fields = ('name', 'slug', 'portal_url', 'comments', 'tags') -class ServiceProviderFilterSetForm(NetBoxModelFilterSetForm): +class ServiceProviderFilterForm(NetBoxModelFilterSetForm): model = ServiceProvider name = forms.CharField(required=False) tag = TagFilterField(model) @@ -458,7 +478,7 @@ class ServiceProviderBulkEditForm(NetBoxModelBulkEditForm): class ContractAssignmentForm(NetBoxModelForm): - contract = DynamicModelChoiceField(queryset=Contract.objects.all()) + contract = DynamicModelChoiceField(queryset=Contract.objects.all(), selector=True) class Meta: model = ContractAssignment @@ -469,9 +489,12 @@ class Meta: } -class ContractAssignmentFilterSetForm(NetBoxModelFilterSetForm): +class ContractAssignmentFilterForm(NetBoxModelFilterSetForm): model = ContractAssignment - contract = DynamicModelChoiceField(queryset=Contract.objects.all()) + contract = DynamicModelChoiceField( + queryset=Contract.objects.all(), + selector=True, + ) class ContractAssignmentImportForm(NetBoxModelImportForm): @@ -492,9 +515,9 @@ class Meta: class InvoiceLineForm(NetBoxModelForm): - invoice = DynamicModelChoiceField(queryset=Invoice.objects.all()) + invoice = DynamicModelChoiceField(queryset=Invoice.objects.all(), selector=True) accounting_dimensions = DynamicModelMultipleChoiceField( - queryset=AccountingDimension.objects.all(), required=False + queryset=AccountingDimension.objects.all(), required=False, selector=True ) def clean(self): @@ -527,11 +550,17 @@ class Meta: ] -class InvoiceLineFilterSetForm(NetBoxModelFilterSetForm): +class InvoiceLineFilterForm(NetBoxModelFilterSetForm): model = InvoiceLine - invoice = DynamicModelChoiceField(queryset=Invoice.objects.all(), required=False) + invoice = DynamicModelChoiceField( + queryset=Invoice.objects.all(), + required=False, + selector=True, + ) accounting_dimensions = DynamicModelMultipleChoiceField( - queryset=AccountingDimension.objects.all(), required=False + queryset=AccountingDimension.objects.all(), + required=False, + selector=True, ) currency = forms.ChoiceField(choices=CurrencyChoices, required=False) tag = TagFilterField(model) @@ -564,7 +593,9 @@ class Meta: class InvoiceLineBulkEditForm(NetBoxModelBulkEditForm): invoice = DynamicModelChoiceField(queryset=Invoice.objects.all(), required=False) accounting_dimensions = DynamicModelMultipleChoiceField( - queryset=AccountingDimension.objects.all(), required=False + queryset=AccountingDimension.objects.all(), + required=False, + selector=True, ) model = InvoiceLine @@ -584,7 +615,7 @@ class Meta: ] -class AccountingDimensionFilterSetForm(NetBoxModelFilterSetForm): +class AccountingDimensionFilterForm(NetBoxModelFilterSetForm): model = AccountingDimension name = forms.CharField(required=False) diff --git a/src/netbox_contract/views.py b/src/netbox_contract/views.py index 4a969ca..d70113f 100644 --- a/src/netbox_contract/views.py +++ b/src/netbox_contract/views.py @@ -42,7 +42,7 @@ class ServiceProviderListView(generic.ObjectListView): queryset = ServiceProvider.objects.all() table = tables.ServiceProviderListTable filterset = filtersets.ServiceProviderFilterSet - filterset_form = forms.ServiceProviderFilterSetForm + filterset_form = forms.ServiceProviderFilterForm class ServiceProviderEditView(generic.ObjectEditView): @@ -84,7 +84,7 @@ class ContractAssignmentListView(generic.ObjectListView): queryset = ContractAssignment.objects.all() table = tables.ContractAssignmentListTable filterset = filtersets.ContractAssignmentFilterSet - filterset_form = forms.ContractAssignmentFilterSetForm + filterset_form = forms.ContractAssignmentFilterForm actions = { 'import': {'add'}, 'export': set(), @@ -184,7 +184,7 @@ class ContractListView(generic.ObjectListView): ) table = tables.ContractListTable filterset = filtersets.ContractFilterSet - filterset_form = forms.ContractFilterSetForm + filterset_form = forms.ContractFilterForm class ContractEditView(generic.ObjectEditView): @@ -270,7 +270,7 @@ class InvoiceListView(generic.ObjectListView): queryset = Invoice.objects.all() table = tables.InvoiceListTable filterset = filtersets.InvoiceFilterSet - filterset_form = forms.InvoiceFilterSetForm + filterset_form = forms.InvoiceFilterForm class InvoiceEditView(generic.ObjectEditView): @@ -377,7 +377,7 @@ class InvoiceLineListView(generic.ObjectListView): queryset = InvoiceLine.objects.all() table = tables.InvoiceLineListTable filterset = filtersets.InvoiceLineFilterSet - filterset_form = forms.InvoiceLineFilterSetForm + filterset_form = forms.InvoiceLineFilterForm class InvoiceLineEditView(generic.ObjectEditView): @@ -453,7 +453,7 @@ class AccountingDimensionListView(generic.ObjectListView): queryset = AccountingDimension.objects.all() table = tables.AccountingDimensionListTable filterset = filtersets.AccountingDimensionFilterSet - filterset_form = forms.AccountingDimensionFilterSetForm + filterset_form = forms.AccountingDimensionFilterForm class AccountingDimensionEditView(generic.ObjectEditView):