From 52886544e023a4134b1f54a223650c9d9d7cfa2a Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Fri, 24 Sep 2021 21:19:53 +0100 Subject: [PATCH 1/2] Remove duplicate url paths introduced in 848b2d0d4b081bc431876950d6aab9332ba302fa --- nautobot_device_lifecycle_mgmt/urls.py | 32 -------------------------- 1 file changed, 32 deletions(-) diff --git a/nautobot_device_lifecycle_mgmt/urls.py b/nautobot_device_lifecycle_mgmt/urls.py index 15487e88..64a08f88 100644 --- a/nautobot_device_lifecycle_mgmt/urls.py +++ b/nautobot_device_lifecycle_mgmt/urls.py @@ -106,36 +106,4 @@ kwargs={"model": ContactLCM}, ), path("contact/import/", views.ContactLCMBulkImportView.as_view(), name="contactlcm_import"), - # Software LifeCycle Management URLs - path("software/", views.SoftwareLCMListView.as_view(), name="softwarelcm_list"), - path("software//", views.SoftwareLCMView.as_view(), name="softwarelcm"), - path("software/add/", views.SoftwareLCMCreateView.as_view(), name="softwarelcm_add"), - path("software//delete/", views.SoftwareLCMDeleteView.as_view(), name="softwarelcm_delete"), - path("software//edit/", views.SoftwareLCMEditView.as_view(), name="softwarelcm_edit"), - path( - "software//changelog/", - ObjectChangeLogView.as_view(), - name="softwarelcm_changelog", - kwargs={"model": SoftwareLCM}, - ), - # ValidatedSoftware - path("validated-software/", views.ValidatedSoftwareLCMListView.as_view(), name="validatedsoftwarelcm_list"), - path("validated-software//", views.ValidatedSoftwareLCMView.as_view(), name="validatedsoftwarelcm"), - path("validated-software/add/", views.ValidatedSoftwareLCMEditView.as_view(), name="validatedsoftwarelcm_add"), - path( - "validated-software//delete/", - views.ValidatedSoftwareLCMDeleteView.as_view(), - name="validatedsoftwarelcm_delete", - ), - path( - "validated-software//edit/", - views.ValidatedSoftwareLCMEditView.as_view(), - name="validatedsoftwarelcm_edit", - ), - path( - "validated-software//changelog/", - ObjectChangeLogView.as_view(), - name="validatedsoftwarelcm_changelog", - kwargs={"model": ValidatedSoftwareLCM}, - ), ] From e2c3633aea8add13d8b33a9bf5c4c09818d0c88b Mon Sep 17 00:00:00 2001 From: Przemek Rogala Date: Mon, 27 Sep 2021 10:33:32 +0100 Subject: [PATCH 2/2] Add csv import/export for Software LCM models. --- nautobot_device_lifecycle_mgmt/forms.py | 36 ++++++++++++++++++++ nautobot_device_lifecycle_mgmt/models.py | 6 ++-- nautobot_device_lifecycle_mgmt/navigation.py | 28 +++++++++++++++ nautobot_device_lifecycle_mgmt/urls.py | 7 +++- nautobot_device_lifecycle_mgmt/views.py | 24 +++++++++++++ 5 files changed, 97 insertions(+), 4 deletions(-) diff --git a/nautobot_device_lifecycle_mgmt/forms.py b/nautobot_device_lifecycle_mgmt/forms.py index 6a36eb4a..b2bdba67 100644 --- a/nautobot_device_lifecycle_mgmt/forms.py +++ b/nautobot_device_lifecycle_mgmt/forms.py @@ -1,6 +1,7 @@ """Forms implementation for the LifeCycle Management plugin.""" import logging from django import forms +from django.contrib.contenttypes.models import ContentType from nautobot.utilities.forms import BootstrapMixin, DatePicker, DynamicModelMultipleChoiceField from nautobot.dcim.models import Device, DeviceType, InventoryItem, Platform @@ -16,6 +17,7 @@ StaticSelect2, BOOLEAN_WITH_BLANK_CHOICES, add_blank_choice, + CSVModelChoiceField, ) from nautobot_device_lifecycle_mgmt.choices import ContractTypeChoices, CurrencyChoices, PoCTypeChoices, CountryCodes from nautobot_device_lifecycle_mgmt.models import ( @@ -214,6 +216,23 @@ class Meta: } +class SoftwareLCMCSVForm(CustomFieldModelCSVForm): + """Form for bulk creating SoftwareLCM objects.""" + + device_platform = CSVModelChoiceField( + queryset=Platform.objects.all(), + required=True, + to_field_name="slug", + help_text="Device platform", + ) + + class Meta: + """Meta attributes for the SoftwareLCMCSVForm class.""" + + model = SoftwareLCM + fields = SoftwareLCM.csv_headers + + class ValidatedSoftwareLCMForm(BootstrapMixin, CustomFieldModelForm, RelationshipModelForm): """ValidatedSoftwareLCM creation/edit form.""" @@ -331,6 +350,23 @@ class Meta: ] +class ValidatedSoftwareLCMCSVForm(CustomFieldModelCSVForm): + """Form for bulk creating ValidatedSoftwareLCM objects.""" + + assigned_to_content_type = CSVModelChoiceField( + queryset=ContentType.objects.all(), + required=True, + to_field_name="model", + help_text="Assigned to object type", + ) + + class Meta: + """Meta attributes for the ValidatedSoftwareLCM class.""" + + model = ValidatedSoftwareLCM + fields = ValidatedSoftwareLCM.csv_headers + + class ContractLCMForm(BootstrapMixin, CustomFieldModelForm, RelationshipModelForm): """Device LifeCycle Contracts creation/edit form.""" diff --git a/nautobot_device_lifecycle_mgmt/models.py b/nautobot_device_lifecycle_mgmt/models.py index 94ba7c30..7c3ccd94 100644 --- a/nautobot_device_lifecycle_mgmt/models.py +++ b/nautobot_device_lifecycle_mgmt/models.py @@ -204,7 +204,7 @@ def get_absolute_url(self): def to_csv(self): """Return fields for bulk view.""" return ( - self.device_platform, + self.device_platform.slug, self.version, self.alias, self.release_date, @@ -288,8 +288,8 @@ def valid(self): def to_csv(self): """Return fields for bulk view.""" return ( - self.software, - self.assigned_to_content_type, + self.software.id, + self.assigned_to_content_type.model, self.assigned_to_object_id, self.start, self.end, diff --git a/nautobot_device_lifecycle_mgmt/navigation.py b/nautobot_device_lifecycle_mgmt/navigation.py index 0a2ffb95..a6f1789b 100644 --- a/nautobot_device_lifecycle_mgmt/navigation.py +++ b/nautobot_device_lifecycle_mgmt/navigation.py @@ -54,6 +54,13 @@ "nautobot_device_lifecycle_mgmt.add_softwarelcm", ], ), + NavMenuButton( + link="plugins:nautobot_device_lifecycle_mgmt:softwarelcm_import", + title="Import", + icon_class="mdi mdi-database-import-outline", + button_class=ButtonColorChoices.BLUE, + permissions=["nautobot_device_lifecycle_mgmt.add_softwarelcm"], + ), ), permissions=[ "nautobot_device_lifecycle_mgmt.view_softwarelcm", @@ -72,6 +79,13 @@ "nautobot_device_lifecycle_mgmt.add_validatedsoftwarelcm", ], ), + NavMenuButton( + link="plugins:nautobot_device_lifecycle_mgmt:validatedsoftwarelcm_import", + title="Import", + icon_class="mdi mdi-database-import-outline", + button_class=ButtonColorChoices.BLUE, + permissions=["nautobot_device_lifecycle_mgmt.add_validatedsoftwarelcm"], + ), ), permissions=[ "nautobot_device_lifecycle_mgmt.view_validatedsoftwarelcm", @@ -246,6 +260,13 @@ color=ButtonColorChoices.GREEN, permissions=["nautobot_device_lifecycle_mgmt.add_softwarelcm"], ), + PluginMenuButton( + link="plugins:nautobot_device_lifecycle_mgmt:softwarelcm_import", + title="Import", + icon_class="mdi mdi-database-import-outline", + color=ButtonColorChoices.BLUE, + permissions=["nautobot_device_lifecycle_mgmt.add_softwarelcm"], + ), ), ), PluginMenuItem( @@ -259,6 +280,13 @@ color=ButtonColorChoices.GREEN, permissions=["nautobot_device_lifecycle_mgmt.add_validatedsoftwarelcm"], ), + PluginMenuButton( + link="plugins:nautobot_device_lifecycle_mgmt:validatedsoftwarelcm_import", + title="Import", + icon_class="mdi mdi-database-import-outline", + color=ButtonColorChoices.BLUE, + permissions=["nautobot_device_lifecycle_mgmt.add_validatedsoftwarelcm"], + ), ), ), ) diff --git a/nautobot_device_lifecycle_mgmt/urls.py b/nautobot_device_lifecycle_mgmt/urls.py index 64a08f88..d46f588e 100644 --- a/nautobot_device_lifecycle_mgmt/urls.py +++ b/nautobot_device_lifecycle_mgmt/urls.py @@ -40,6 +40,7 @@ name="softwarelcm_changelog", kwargs={"model": SoftwareLCM}, ), + path("software/import/", views.SoftwareLCMBulkImportView.as_view(), name="softwarelcm_import"), # ValidatedSoftware path("validated-software/", views.ValidatedSoftwareLCMListView.as_view(), name="validatedsoftwarelcm_list"), path("validated-software//", views.ValidatedSoftwareLCMView.as_view(), name="validatedsoftwarelcm"), @@ -60,7 +61,11 @@ name="validatedsoftwarelcm_changelog", kwargs={"model": ValidatedSoftwareLCM}, ), - path("hardware/import/", views.HardwareLCMBulkImportView.as_view(), name="hardwarelcm_import"), + path( + "validated-software/import/", + views.ValidatedSoftwareLCMBulkImportView.as_view(), + name="validatedsoftwarelcm_import", + ), # Contract LifeCycle Management URLs path("contract/", views.ContractLCMListView.as_view(), name="contractlcm_list"), path("contract//", views.ContractLCMView.as_view(), name="contractlcm"), diff --git a/nautobot_device_lifecycle_mgmt/views.py b/nautobot_device_lifecycle_mgmt/views.py index 8d38eb60..a3dbbfd0 100644 --- a/nautobot_device_lifecycle_mgmt/views.py +++ b/nautobot_device_lifecycle_mgmt/views.py @@ -24,8 +24,10 @@ HardwareLCMCSVForm, SoftwareLCMForm, SoftwareLCMFilterForm, + SoftwareLCMCSVForm, ValidatedSoftwareLCMForm, ValidatedSoftwareLCMFilterForm, + ValidatedSoftwareLCMCSVForm, ContractLCMForm, ContractLCMBulkEditForm, ContractLCMFilterForm, @@ -150,6 +152,8 @@ class SoftwareLCMListView(generic.ObjectListView): action_buttons = ( "add", "delete", + "import", + "export", ) @@ -186,6 +190,15 @@ class SoftwareLCMEditView(generic.ObjectEditView): default_return_url = URL.SoftwareLCM.View +class SoftwareLCMBulkImportView(generic.BulkImportView): + """View for bulk import of SoftwareLCM.""" + + queryset = SoftwareLCM.objects.prefetch_related("device_platform") + model_form = SoftwareLCMCSVForm + table = SoftwareLCMTable + default_return_url = "plugins:nautobot_device_lifecycle_mgmt:softwarelcm_list" + + class ValidatedSoftwareLCMListView(generic.ObjectListView): """ValidatedSoftware List view.""" @@ -196,6 +209,8 @@ class ValidatedSoftwareLCMListView(generic.ObjectListView): action_buttons = ( "add", "delete", + "import", + "export", ) @@ -224,6 +239,15 @@ class ValidatedSoftwareLCMDeleteView(generic.ObjectDeleteView): template_name = "nautobot_device_lifecycle_mgmt/validatedsoftwarelcm_delete.html" +class ValidatedSoftwareLCMBulkImportView(generic.BulkImportView): + """View for bulk import of ValidatedSoftwareLCM.""" + + queryset = ValidatedSoftwareLCM.objects.all() + model_form = ValidatedSoftwareLCMCSVForm + table = ValidatedSoftwareLCMTable + default_return_url = "plugins:nautobot_device_lifecycle_mgmt:validatedsoftwarelcm_list" + + # --------------------------------------------------------------------------------- # Contract LifeCycle Management Views # ---------------------------------------------------------------------------------