Skip to content

Commit

Permalink
Adds bulk import for journal entry (#12485)
Browse files Browse the repository at this point in the history
* adds bulk import for journal entry #12122

* lint fix

* Add kind as CSVChoiceField on JournalEntryImportForm

---------

Co-authored-by: jeremystretch <[email protected]>
  • Loading branch information
abhi1693 and jeremystretch authored May 5, 2023
1 parent 4234670 commit ca0e7be
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
21 changes: 20 additions & 1 deletion netbox/extras/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -15,6 +16,7 @@
'CustomFieldImportForm',
'CustomLinkImportForm',
'ExportTemplateImportForm',
'JournalEntryImportForm',
'SavedFilterImportForm',
'TagImportForm',
'WebhookImportForm',
Expand Down Expand Up @@ -132,3 +134,20 @@ class Meta:
help_texts = {
'color': mark_safe(_('RGB color in hexadecimal (e.g. <code>00ff00</code>)')),
}


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'
)
1 change: 1 addition & 0 deletions netbox/extras/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:pk>/', include(get_model_urls('extras', 'journalentry'))),

# Change logging
Expand Down
7 changes: 6 additions & 1 deletion netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
#
Expand Down
2 changes: 1 addition & 1 deletion netbox/netbox/navigation/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[]),
),
),
Expand Down

0 comments on commit ca0e7be

Please sign in to comment.