Refactoring
* splits ema/models.py into subpackage * splits konova/models.py into subpackage * splits user/models.py into subpackage
This commit is contained in:
10
user/models/__init__.py
Normal file
10
user/models/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from .user_action import *
|
||||
from .konova_user import *
|
||||
from .notification import *
|
||||
19
user/models/konova_user.py
Normal file
19
user/models/konova_user.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
|
||||
|
||||
class KonovaUserExtension(models.Model):
|
||||
""" Extension model for additional ksp features
|
||||
|
||||
Extends the default user model for some extras
|
||||
|
||||
"""
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
notifications = models.ManyToManyField("user.UserNotification", related_name="+")
|
||||
34
user/models/notification.py
Normal file
34
user/models/notification.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from django.db import models
|
||||
|
||||
from user.enums import UserNotificationEnum
|
||||
|
||||
|
||||
class UserNotification(models.Model):
|
||||
""" Notifications for users
|
||||
|
||||
"""
|
||||
id = models.CharField(
|
||||
max_length=500,
|
||||
null=False,
|
||||
blank=False,
|
||||
choices=UserNotificationEnum.as_choices(drop_empty_choice=True),
|
||||
primary_key=True,
|
||||
)
|
||||
name = models.CharField(
|
||||
max_length=500,
|
||||
null=False,
|
||||
blank=False,
|
||||
unique=True,
|
||||
help_text="Human readable name"
|
||||
)
|
||||
is_active = models.BooleanField(default=True, help_text="Can be toggle to enable/disable this notification for all users")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
69
user/models/user_action.py
Normal file
69
user/models/user_action.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
||||
Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 15.11.21
|
||||
|
||||
"""
|
||||
import uuid
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
class UserAction(models.TextChoices):
|
||||
"""
|
||||
Defines different possible user actions for UserActionLogEntry
|
||||
"""
|
||||
CHECKED = "checked", _("Checked")
|
||||
RECORDED = "recorded", _("Recorded")
|
||||
UNRECORDED = "unrecorded", _("Unrecorded")
|
||||
CREATED = "created", _("Created")
|
||||
EDITED = "edited", _("Edited")
|
||||
DELETED = "deleted", _("Deleted")
|
||||
|
||||
|
||||
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=UserAction.choices,
|
||||
)
|
||||
comment = models.CharField(max_length=255, null=True, blank=True, help_text="Additional comment on this entry")
|
||||
|
||||
class Meta:
|
||||
ordering = (
|
||||
"-timestamp",
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return "{} | {} | {}".format(self.user.username, self.timestamp, self.action)
|
||||
|
||||
@property
|
||||
def action_humanize(self):
|
||||
""" Returns humanized version of enum
|
||||
|
||||
Used for template rendering
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
choices = UserAction.choices
|
||||
for choice in choices:
|
||||
if choice[0] == self.action:
|
||||
return choice[1]
|
||||
return None
|
||||
Reference in New Issue
Block a user