Răsfoiți Sursa

Add bulk edit, delete views for journal entries

Jeremy Stretch 4 ani în urmă
părinte
comite
956e2728c2

+ 15 - 1
netbox/extras/forms.py

@@ -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(

+ 2 - 1
netbox/extras/tables.py

@@ -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):

+ 2 - 2
netbox/extras/tests/test_views.py

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

+ 2 - 0
netbox/extras/urls.py

@@ -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'),
 
 

+ 13 - 0
netbox/extras/views.py

@@ -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.