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

Add kind field to JournalEntry

This commit is contained in:
Jeremy Stretch
2021-03-17 12:51:39 -04:00
parent bd95d2b852
commit 82fbd975f1
8 changed files with 60 additions and 5 deletions

View File

@ -192,12 +192,16 @@ class JournalEntrySerializer(ValidatedModelSerializer):
queryset=ContentType.objects.all()
)
assigned_object = serializers.SerializerMethodField(read_only=True)
kind = ChoiceField(
choices=JournalEntryKindChoices,
required=False
)
class Meta:
model = JournalEntry
fields = [
'id', 'url', 'display', 'assigned_object_type', 'assigned_object_id', 'assigned_object', 'created',
'created_by', 'comments',
'created_by', 'kind', 'comments',
]
def validate(self, data):

View File

@ -87,6 +87,32 @@ class ObjectChangeActionChoices(ChoiceSet):
}
#
# Jounral entries
#
class JournalEntryKindChoices(ChoiceSet):
KIND_INFO = 'info'
KIND_SUCCESS = 'success'
KIND_WARNING = 'warning'
KIND_DANGER = 'danger'
CHOICES = (
(KIND_INFO, 'Info'),
(KIND_SUCCESS, 'Success'),
(KIND_WARNING, 'Warning'),
(KIND_DANGER, 'Danger'),
)
CSS_CLASSES = {
KIND_INFO: 'default',
KIND_SUCCESS: 'success',
KIND_WARNING: 'warning',
KIND_DANGER: 'danger',
}
#
# Log Levels for Reports and Scripts
#

View File

@ -379,7 +379,7 @@ class JournalEntryForm(BootstrapMixin, forms.ModelForm):
class Meta:
model = JournalEntry
fields = ['assigned_object_type', 'assigned_object_id', 'comments']
fields = ['assigned_object_type', 'assigned_object_id', 'kind', 'comments']
widgets = {
'assigned_object_type': forms.HiddenInput,
'assigned_object_id': forms.HiddenInput,
@ -391,6 +391,10 @@ class JournalEntryBulkEditForm(BootstrapMixin, BulkEditForm):
queryset=JournalEntry.objects.all(),
widget=forms.MultipleHiddenInput
)
kind = forms.ChoiceField(
choices=JournalEntryKindChoices,
required=False
)
comments = forms.CharField(
required=False,
widget=forms.Textarea()
@ -432,6 +436,11 @@ class JournalEntryFilterForm(BootstrapMixin, forms.Form):
api_url='/api/extras/content-types/',
)
)
kind = forms.ChoiceField(
choices=add_blank_choice(JournalEntryKindChoices),
required=False,
widget=StaticSelect2()
)
#

View File

@ -18,6 +18,7 @@ class Migration(migrations.Migration):
('id', models.BigAutoField(primary_key=True, serialize=False)),
('assigned_object_id', models.PositiveIntegerField()),
('created', models.DateTimeField(auto_now_add=True)),
('kind', models.CharField(default='info', max_length=30)),
('comments', models.TextField()),
('assigned_object_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')),
('created_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),

View File

@ -399,6 +399,11 @@ class JournalEntry(BigIDModel):
blank=True,
null=True
)
kind = models.CharField(
max_length=30,
choices=JournalEntryKindChoices,
default=JournalEntryKindChoices.KIND_INFO
)
comments = models.TextField()
objects = RestrictedQuerySet.as_manager()
@ -408,7 +413,10 @@ class JournalEntry(BigIDModel):
verbose_name_plural = 'journal entries'
def __str__(self):
return f"{self.created}"
return f"{self.created} - {self.get_kind_display()}"
def get_kind_class(self):
return JournalEntryKindChoices.CSS_CLASSES.get(self.kind)
#

View File

@ -111,6 +111,7 @@ class JournalEntryTable(BaseTable):
orderable=False,
verbose_name='Object'
)
kind = ChoiceFieldColumn()
actions = ButtonsColumn(
model=JournalEntry,
buttons=('edit', 'delete')
@ -118,7 +119,9 @@ class JournalEntryTable(BaseTable):
class Meta(BaseTable.Meta):
model = JournalEntry
fields = ('pk', 'created', 'created_by', 'assigned_object_type', 'assigned_object', 'comments', 'actions')
fields = (
'pk', 'created', 'created_by', 'assigned_object_type', 'assigned_object', 'kind', 'comments', 'actions'
)
class ObjectJournalTable(BaseTable):
@ -128,6 +131,7 @@ class ObjectJournalTable(BaseTable):
created = tables.DateTimeColumn(
format=settings.SHORT_DATETIME_FORMAT
)
kind = ChoiceFieldColumn()
actions = ButtonsColumn(
model=JournalEntry,
buttons=('edit', 'delete')
@ -135,4 +139,4 @@ class ObjectJournalTable(BaseTable):
class Meta(BaseTable.Meta):
model = JournalEntry
fields = ('created', 'created_by', 'comments', 'actions')
fields = ('created', 'created_by', 'kind', 'comments', 'actions')

View File

@ -154,10 +154,12 @@ class JournalEntryTestCase(
cls.form_data = {
'assigned_object_type': site_ct.pk,
'assigned_object_id': site.pk,
'kind': 'info',
'comments': 'A new entry',
}
cls.bulk_edit_data = {
'kind': 'success',
'comments': 'Overwritten',
}

View File

@ -16,6 +16,7 @@
{% endfor %}
<div class="row panel-body">
<div class="col-md-10">
{% render_field form.kind %}
{% render_field form.comments %}
</div>
<div class="col-md-9 col-md-offset-3">