Skip to content

Commit ca0e7be

Browse files
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 <[email protected]>
1 parent 4234670 commit ca0e7be

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

netbox/extras/forms/bulk_import.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
from django.utils.safestring import mark_safe
55
from django.utils.translation import gettext as _
66

7-
from extras.choices import CustomFieldVisibilityChoices, CustomFieldTypeChoices
7+
from extras.choices import CustomFieldVisibilityChoices, CustomFieldTypeChoices, JournalEntryKindChoices
88
from extras.models import *
99
from extras.utils import FeatureQuery
10+
from netbox.forms import NetBoxModelImportForm
1011
from utilities.forms import CSVModelForm
1112
from utilities.forms.fields import CSVChoiceField, CSVContentTypeField, CSVMultipleContentTypeField, SlugField
1213

@@ -15,6 +16,7 @@
1516
'CustomFieldImportForm',
1617
'CustomLinkImportForm',
1718
'ExportTemplateImportForm',
19+
'JournalEntryImportForm',
1820
'SavedFilterImportForm',
1921
'TagImportForm',
2022
'WebhookImportForm',
@@ -132,3 +134,20 @@ class Meta:
132134
help_texts = {
133135
'color': mark_safe(_('RGB color in hexadecimal (e.g. <code>00ff00</code>)')),
134136
}
137+
138+
139+
class JournalEntryImportForm(NetBoxModelImportForm):
140+
assigned_object_type = CSVContentTypeField(
141+
queryset=ContentType.objects.all(),
142+
label=_('Assigned object type'),
143+
)
144+
kind = CSVChoiceField(
145+
choices=JournalEntryKindChoices,
146+
help_text=_('The classification of entry')
147+
)
148+
149+
class Meta:
150+
model = JournalEntry
151+
fields = (
152+
'assigned_object_type', 'assigned_object_id', 'created_by', 'kind', 'comments', 'tags'
153+
)

netbox/extras/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
path('journal-entries/add/', views.JournalEntryEditView.as_view(), name='journalentry_add'),
8383
path('journal-entries/edit/', views.JournalEntryBulkEditView.as_view(), name='journalentry_bulk_edit'),
8484
path('journal-entries/delete/', views.JournalEntryBulkDeleteView.as_view(), name='journalentry_bulk_delete'),
85+
path('journal-entries/import/', views.JournalEntryBulkImportView.as_view(), name='journalentry_import'),
8586
path('journal-entries/<int:pk>/', include(get_model_urls('extras', 'journalentry'))),
8687

8788
# Change logging

netbox/extras/views.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ class JournalEntryListView(generic.ObjectListView):
625625
filterset = filtersets.JournalEntryFilterSet
626626
filterset_form = forms.JournalEntryFilterForm
627627
table = tables.JournalEntryTable
628-
actions = ('export', 'bulk_edit', 'bulk_delete')
628+
actions = ('import', 'export', 'bulk_edit', 'bulk_delete')
629629

630630

631631
@register_model_view(JournalEntry)
@@ -674,6 +674,11 @@ class JournalEntryBulkDeleteView(generic.BulkDeleteView):
674674
table = tables.JournalEntryTable
675675

676676

677+
class JournalEntryBulkImportView(generic.BulkImportView):
678+
queryset = JournalEntry.objects.all()
679+
model_form = forms.JournalEntryImportForm
680+
681+
677682
#
678683
# Dashboard & widgets
679684
#

netbox/netbox/navigation/menu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
MenuGroup(
338338
label=_('Logging'),
339339
items=(
340-
get_model_item('extras', 'journalentry', _('Journal Entries'), actions=[]),
340+
get_model_item('extras', 'journalentry', _('Journal Entries'), actions=['import']),
341341
get_model_item('extras', 'objectchange', _('Change Log'), actions=[]),
342342
),
343343
),

0 commit comments

Comments
 (0)