1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Add bulk edit, delete views for journal entries

This commit is contained in:
Jeremy Stretch
2021-03-17 10:41:06 -04:00
parent 7f1d9aeaf8
commit 956e2728c2
5 changed files with 34 additions and 4 deletions

View File

@ -8,7 +8,7 @@ from dcim.models import DeviceRole, Platform, Region, Site, SiteGroup
from tenancy.models import Tenant, TenantGroup from tenancy.models import Tenant, TenantGroup
from utilities.forms import ( from utilities.forms import (
add_blank_choice, APISelectMultiple, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect, ColorSelect, 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, BOOLEAN_WITH_BLANK_CHOICES,
) )
from virtualization.models import Cluster, ClusterGroup from virtualization.models import Cluster, ClusterGroup
@ -386,6 +386,20 @@ class JournalEntryForm(BootstrapMixin, forms.ModelForm):
} }
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): class JournalEntryFilterForm(BootstrapMixin, forms.Form):
model = JournalEntry model = JournalEntry
q = forms.CharField( q = forms.CharField(

View File

@ -99,6 +99,7 @@ class ObjectChangeTable(BaseTable):
class JournalEntryTable(BaseTable): class JournalEntryTable(BaseTable):
pk = ToggleColumn()
created = tables.DateTimeColumn( created = tables.DateTimeColumn(
format=settings.SHORT_DATETIME_FORMAT format=settings.SHORT_DATETIME_FORMAT
) )
@ -117,7 +118,7 @@ class JournalEntryTable(BaseTable):
class Meta(BaseTable.Meta): class Meta(BaseTable.Meta):
model = JournalEntry 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): class ObjectJournalTable(BaseTable):

View File

@ -133,8 +133,8 @@ class JournalEntryTestCase(
ViewTestCases.EditObjectViewTestCase, ViewTestCases.EditObjectViewTestCase,
ViewTestCases.DeleteObjectViewTestCase, ViewTestCases.DeleteObjectViewTestCase,
ViewTestCases.ListObjectsViewTestCase, ViewTestCases.ListObjectsViewTestCase,
# ViewTestCases.BulkEditObjectsViewTestCase, ViewTestCases.BulkEditObjectsViewTestCase,
# ViewTestCases.BulkDeleteObjectsViewTestCase ViewTestCases.BulkDeleteObjectsViewTestCase
): ):
model = JournalEntry model = JournalEntry

View File

@ -34,6 +34,8 @@ urlpatterns = [
# Journal entries # Journal entries
path('journal-entries/', views.JournalEntryListView.as_view(), name='journalentry_list'), path('journal-entries/', views.JournalEntryListView.as_view(), name='journalentry_list'),
path('journal-entries/add/', views.JournalEntryEditView.as_view(), name='journalentry_add'), 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>/edit/', views.JournalEntryEditView.as_view(), name='journalentry_edit'),
path('journal-entries/<int:pk>/delete/', views.JournalEntryDeleteView.as_view(), name='journalentry_delete'), path('journal-entries/<int:pk>/delete/', views.JournalEntryDeleteView.as_view(), name='journalentry_delete'),

View File

@ -320,6 +320,19 @@ class JournalEntryDeleteView(generic.ObjectDeleteView):
return reverse(viewname, kwargs={'pk': obj.pk}) 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): class ObjectJournalView(View):
""" """
Show all journal entries for an object. Show all journal entries for an object.