Skip to content

Commit

Permalink
Add bulk edit, delete views for journal entries
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Mar 17, 2021
1 parent 7f1d9ae commit 956e272
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
16 changes: 15 additions & 1 deletion netbox/extras/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tenancy.models import Tenant, TenantGroup
from utilities.forms import (
add_blank_choice, APISelectMultiple, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect, ColorSelect,
CSVModelForm, DateTimePicker, DynamicModelMultipleChoiceField, JSONField, SlugField, StaticSelect2,
CommentField, CSVModelForm, DateTimePicker, DynamicModelMultipleChoiceField, JSONField, SlugField, StaticSelect2,
BOOLEAN_WITH_BLANK_CHOICES,
)
from virtualization.models import Cluster, ClusterGroup
Expand Down Expand Up @@ -386,6 +386,20 @@ class Meta:
}


class JournalEntryBulkEditForm(BootstrapMixin, BulkEditForm):
pk = forms.ModelMultipleChoiceField(
queryset=JournalEntry.objects.all(),
widget=forms.MultipleHiddenInput
)
comments = forms.CharField(
required=False,
widget=forms.Textarea()
)

class Meta:
nullable_fields = []


class JournalEntryFilterForm(BootstrapMixin, forms.Form):
model = JournalEntry
q = forms.CharField(
Expand Down
3 changes: 2 additions & 1 deletion netbox/extras/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class Meta(BaseTable.Meta):


class JournalEntryTable(BaseTable):
pk = ToggleColumn()
created = tables.DateTimeColumn(
format=settings.SHORT_DATETIME_FORMAT
)
Expand All @@ -117,7 +118,7 @@ class JournalEntryTable(BaseTable):

class Meta(BaseTable.Meta):
model = JournalEntry
fields = ('created', 'created_by', 'assigned_object_type', 'assigned_object', 'comments', 'actions')
fields = ('pk', 'created', 'created_by', 'assigned_object_type', 'assigned_object', 'comments', 'actions')


class ObjectJournalTable(BaseTable):
Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ class JournalEntryTestCase(
ViewTestCases.EditObjectViewTestCase,
ViewTestCases.DeleteObjectViewTestCase,
ViewTestCases.ListObjectsViewTestCase,
# ViewTestCases.BulkEditObjectsViewTestCase,
# ViewTestCases.BulkDeleteObjectsViewTestCase
ViewTestCases.BulkEditObjectsViewTestCase,
ViewTestCases.BulkDeleteObjectsViewTestCase
):
model = JournalEntry

Expand Down
2 changes: 2 additions & 0 deletions netbox/extras/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
# Journal entries
path('journal-entries/', views.JournalEntryListView.as_view(), name='journalentry_list'),
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/<int:pk>/edit/', views.JournalEntryEditView.as_view(), name='journalentry_edit'),
path('journal-entries/<int:pk>/delete/', views.JournalEntryDeleteView.as_view(), name='journalentry_delete'),

Expand Down
13 changes: 13 additions & 0 deletions netbox/extras/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@ def get_return_url(self, request, instance):
return reverse(viewname, kwargs={'pk': obj.pk})


class JournalEntryBulkEditView(generic.BulkEditView):
queryset = JournalEntry.objects.prefetch_related('created_by')
filterset = filters.JournalEntryFilterSet
table = tables.JournalEntryTable
form = forms.JournalEntryBulkEditForm


class JournalEntryBulkDeleteView(generic.BulkDeleteView):
queryset = JournalEntry.objects.prefetch_related('created_by')
filterset = filters.JournalEntryFilterSet
table = tables.JournalEntryTable


class ObjectJournalView(View):
"""
Show all journal entries for an object.
Expand Down

0 comments on commit 956e272

Please sign in to comment.