Intervention model refactoring
* adds UserActionLogEntry model to user/models.py * wraps user and timestamp info * can be extended for more information in the future * refactors all filtering and accessing on values
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from user.models import UserNotification, KonovaUserExtension
|
||||
from user.models import UserNotification, KonovaUserExtension, UserActionLogEntry
|
||||
|
||||
|
||||
class UserNotificationAdmin(admin.ModelAdmin):
|
||||
@@ -17,5 +17,15 @@ class KonovaUserExtensionAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
class UserActionLogEntryAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"user",
|
||||
"timestamp",
|
||||
"action",
|
||||
]
|
||||
|
||||
|
||||
admin.site.register(UserNotification, UserNotificationAdmin)
|
||||
admin.site.register(KonovaUserExtension, KonovaUserExtensionAdmin)
|
||||
admin.site.register(UserActionLogEntry, UserActionLogEntryAdmin)
|
||||
@@ -1,6 +1,9 @@
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
from konova.enums import UserActionLogEntryEnum
|
||||
from user.enums import UserNotificationEnum
|
||||
|
||||
|
||||
@@ -36,3 +39,27 @@ class KonovaUserExtension(models.Model):
|
||||
"""
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
notifications = models.ManyToManyField(UserNotification, related_name="+")
|
||||
|
||||
|
||||
class UserActionLogEntry(models.Model):
|
||||
""" Wraps a user action log entry
|
||||
|
||||
Can be used for workflow related attributes like checking or recording.
|
||||
|
||||
"""
|
||||
id = models.UUIDField(
|
||||
primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
)
|
||||
user = models.ForeignKey(User, related_name='+', on_delete=models.CASCADE, help_text="Performing user")
|
||||
timestamp = models.DateTimeField(auto_now_add=True, help_text="Timestamp of performed action")
|
||||
action = models.CharField(
|
||||
max_length=255,
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Short name for performed action - optional",
|
||||
choices=UserActionLogEntryEnum.as_choices(drop_empty_choice=True),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return "{} | {} | {}".format(self.user.username, self.timestamp, self.action)
|
||||
Reference in New Issue
Block a user