From ca0e7be637beabcaf9df41584302e36c72b8ef9b Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Fri, 5 May 2023 06:57:09 -0700 Subject: [PATCH] Adds bulk import for journal entry (#12485) * adds bulk import for journal entry #12122 * lint fix * Add kind as CSVChoiceField on JournalEntryImportForm --------- Co-authored-by: jeremystretch --- netbox/extras/forms/bulk_import.py | 21 ++++++++++++++++++++- netbox/extras/urls.py | 1 + netbox/extras/views.py | 7 ++++++- netbox/netbox/navigation/menu.py | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/netbox/extras/forms/bulk_import.py b/netbox/extras/forms/bulk_import.py index c344a32148a..818b8a52fa5 100644 --- a/netbox/extras/forms/bulk_import.py +++ b/netbox/extras/forms/bulk_import.py @@ -4,9 +4,10 @@ from django.utils.safestring import mark_safe from django.utils.translation import gettext as _ -from extras.choices import CustomFieldVisibilityChoices, CustomFieldTypeChoices +from extras.choices import CustomFieldVisibilityChoices, CustomFieldTypeChoices, JournalEntryKindChoices from extras.models import * from extras.utils import FeatureQuery +from netbox.forms import NetBoxModelImportForm from utilities.forms import CSVModelForm from utilities.forms.fields import CSVChoiceField, CSVContentTypeField, CSVMultipleContentTypeField, SlugField @@ -15,6 +16,7 @@ 'CustomFieldImportForm', 'CustomLinkImportForm', 'ExportTemplateImportForm', + 'JournalEntryImportForm', 'SavedFilterImportForm', 'TagImportForm', 'WebhookImportForm', @@ -132,3 +134,20 @@ class Meta: help_texts = { 'color': mark_safe(_('RGB color in hexadecimal (e.g. 00ff00)')), } + + +class JournalEntryImportForm(NetBoxModelImportForm): + assigned_object_type = CSVContentTypeField( + queryset=ContentType.objects.all(), + label=_('Assigned object type'), + ) + kind = CSVChoiceField( + choices=JournalEntryKindChoices, + help_text=_('The classification of entry') + ) + + class Meta: + model = JournalEntry + fields = ( + 'assigned_object_type', 'assigned_object_id', 'created_by', 'kind', 'comments', 'tags' + ) diff --git a/netbox/extras/urls.py b/netbox/extras/urls.py index e516da091a4..c4fc3d938f8 100644 --- a/netbox/extras/urls.py +++ b/netbox/extras/urls.py @@ -82,6 +82,7 @@ path('journal-entries/add/', views.JournalEntryEditView.as_view(), name='journalentry_add'), path('journal-entries/edit/', views.JournalEntryBulkEditView.as_view(), name='journalentry_bulk_edit'), path('journal-entries/delete/', views.JournalEntryBulkDeleteView.as_view(), name='journalentry_bulk_delete'), + path('journal-entries/import/', views.JournalEntryBulkImportView.as_view(), name='journalentry_import'), path('journal-entries//', include(get_model_urls('extras', 'journalentry'))), # Change logging diff --git a/netbox/extras/views.py b/netbox/extras/views.py index e695c39f065..6cbadf09d99 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -625,7 +625,7 @@ class JournalEntryListView(generic.ObjectListView): filterset = filtersets.JournalEntryFilterSet filterset_form = forms.JournalEntryFilterForm table = tables.JournalEntryTable - actions = ('export', 'bulk_edit', 'bulk_delete') + actions = ('import', 'export', 'bulk_edit', 'bulk_delete') @register_model_view(JournalEntry) @@ -674,6 +674,11 @@ class JournalEntryBulkDeleteView(generic.BulkDeleteView): table = tables.JournalEntryTable +class JournalEntryBulkImportView(generic.BulkImportView): + queryset = JournalEntry.objects.all() + model_form = forms.JournalEntryImportForm + + # # Dashboard & widgets # diff --git a/netbox/netbox/navigation/menu.py b/netbox/netbox/navigation/menu.py index b96c275eabf..6e5bcfc23f4 100644 --- a/netbox/netbox/navigation/menu.py +++ b/netbox/netbox/navigation/menu.py @@ -337,7 +337,7 @@ MenuGroup( label=_('Logging'), items=( - get_model_item('extras', 'journalentry', _('Journal Entries'), actions=[]), + get_model_item('extras', 'journalentry', _('Journal Entries'), actions=['import']), get_model_item('extras', 'objectchange', _('Change Log'), actions=[]), ), ),