|
|
@@ -12,7 +12,6 @@ from django.db.models import Q
|
|
|
from django.http import HttpResponse
|
|
|
from django.template import Template, Context
|
|
|
from django.urls import reverse
|
|
|
-from django.utils.safestring import mark_safe
|
|
|
|
|
|
from dcim.constants import CONNECTION_STATUS_CONNECTED
|
|
|
from utilities.utils import foreground_color
|
|
|
@@ -842,100 +841,3 @@ class ObjectChange(models.Model):
|
|
|
self.object_repr,
|
|
|
self.object_data,
|
|
|
)
|
|
|
-
|
|
|
-
|
|
|
-#
|
|
|
-# User actions
|
|
|
-#
|
|
|
-
|
|
|
-class UserActionManager(models.Manager):
|
|
|
-
|
|
|
- # Actions affecting a single object
|
|
|
- def log_action(self, user, obj, action, message):
|
|
|
- self.model.objects.create(
|
|
|
- content_type=ContentType.objects.get_for_model(obj),
|
|
|
- object_id=obj.pk,
|
|
|
- user=user,
|
|
|
- action=action,
|
|
|
- message=message,
|
|
|
- )
|
|
|
-
|
|
|
- def log_create(self, user, obj, message=''):
|
|
|
- self.log_action(user, obj, ACTION_CREATE, message)
|
|
|
-
|
|
|
- def log_edit(self, user, obj, message=''):
|
|
|
- self.log_action(user, obj, ACTION_EDIT, message)
|
|
|
-
|
|
|
- def log_delete(self, user, obj, message=''):
|
|
|
- self.log_action(user, obj, ACTION_DELETE, message)
|
|
|
-
|
|
|
- # Actions affecting multiple objects
|
|
|
- def log_bulk_action(self, user, content_type, action, message):
|
|
|
- self.model.objects.create(
|
|
|
- content_type=content_type,
|
|
|
- user=user,
|
|
|
- action=action,
|
|
|
- message=message,
|
|
|
- )
|
|
|
-
|
|
|
- def log_import(self, user, content_type, message=''):
|
|
|
- self.log_bulk_action(user, content_type, ACTION_IMPORT, message)
|
|
|
-
|
|
|
- def log_bulk_create(self, user, content_type, message=''):
|
|
|
- self.log_bulk_action(user, content_type, ACTION_BULK_CREATE, message)
|
|
|
-
|
|
|
- def log_bulk_edit(self, user, content_type, message=''):
|
|
|
- self.log_bulk_action(user, content_type, ACTION_BULK_EDIT, message)
|
|
|
-
|
|
|
- def log_bulk_delete(self, user, content_type, message=''):
|
|
|
- self.log_bulk_action(user, content_type, ACTION_BULK_DELETE, message)
|
|
|
-
|
|
|
-
|
|
|
-# TODO: Remove UserAction, which has been replaced by ObjectChange.
|
|
|
-class UserAction(models.Model):
|
|
|
- """
|
|
|
- DEPRECATED: A record of an action (add, edit, or delete) performed on an object by a User.
|
|
|
- """
|
|
|
- time = models.DateTimeField(
|
|
|
- auto_now_add=True,
|
|
|
- editable=False
|
|
|
- )
|
|
|
- user = models.ForeignKey(
|
|
|
- to=User,
|
|
|
- on_delete=models.CASCADE,
|
|
|
- related_name='actions'
|
|
|
- )
|
|
|
- content_type = models.ForeignKey(
|
|
|
- to=ContentType,
|
|
|
- on_delete=models.CASCADE
|
|
|
- )
|
|
|
- object_id = models.PositiveIntegerField(
|
|
|
- blank=True,
|
|
|
- null=True
|
|
|
- )
|
|
|
- action = models.PositiveSmallIntegerField(
|
|
|
- choices=ACTION_CHOICES
|
|
|
- )
|
|
|
- message = models.TextField(
|
|
|
- blank=True
|
|
|
- )
|
|
|
-
|
|
|
- objects = UserActionManager()
|
|
|
-
|
|
|
- class Meta:
|
|
|
- ordering = ['-time']
|
|
|
-
|
|
|
- def __str__(self):
|
|
|
- if self.message:
|
|
|
- return '{} {}'.format(self.user, self.message)
|
|
|
- return '{} {} {}'.format(self.user, self.get_action_display(), self.content_type)
|
|
|
-
|
|
|
- def icon(self):
|
|
|
- if self.action in [ACTION_CREATE, ACTION_BULK_CREATE, ACTION_IMPORT]:
|
|
|
- return mark_safe('<i class="glyphicon glyphicon-plus text-success"></i>')
|
|
|
- elif self.action in [ACTION_EDIT, ACTION_BULK_EDIT]:
|
|
|
- return mark_safe('<i class="glyphicon glyphicon-pencil text-warning"></i>')
|
|
|
- elif self.action in [ACTION_DELETE, ACTION_BULK_DELETE]:
|
|
|
- return mark_safe('<i class="glyphicon glyphicon-remove text-danger"></i>')
|
|
|
- else:
|
|
|
- return ''
|