# 63 Refactoring
* refactors django User model to custom User model to provide further attributes and methods directly on the user model
This commit is contained in:
@@ -6,5 +6,5 @@ Created on: 15.11.21
|
||||
|
||||
"""
|
||||
from .user_action import *
|
||||
from .konova_user import *
|
||||
from .user import *
|
||||
from .notification import *
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
"""
|
||||
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="+")
|
||||
28
user/models/user.py
Normal file
28
user/models/user.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""
|
||||
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 AbstractUser
|
||||
|
||||
from django.db import models
|
||||
|
||||
from konova.utils.mailer import Mailer
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
notifications = models.ManyToManyField("user.UserNotification", related_name="+", blank=True)
|
||||
|
||||
def send_mail_shared_access_removed(self, obj):
|
||||
""" Sends a mail to the user in case of removed shared access
|
||||
|
||||
Args:
|
||||
obj ():
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
mailer = Mailer()
|
||||
mailer.send_mail_shared_access_removed(obj, self)
|
||||
@@ -7,7 +7,6 @@ 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 _
|
||||
|
||||
@@ -34,7 +33,7 @@ class UserActionLogEntry(models.Model):
|
||||
primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
)
|
||||
user = models.ForeignKey(User, related_name='+', on_delete=models.CASCADE, help_text="Performing user")
|
||||
user = models.ForeignKey("user.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,
|
||||
@@ -69,7 +68,7 @@ class UserActionLogEntry(models.Model):
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_created_action(cls, user: User, comment: str = None):
|
||||
def get_created_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED,
|
||||
@@ -78,7 +77,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_edited_action(cls, user: User, comment: str = None):
|
||||
def get_edited_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
@@ -87,7 +86,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_deleted_action(cls, user: User, comment: str = None):
|
||||
def get_deleted_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.DELETED,
|
||||
@@ -96,7 +95,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_checked_action(cls, user: User, comment: str = None):
|
||||
def get_checked_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CHECKED,
|
||||
@@ -105,7 +104,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_recorded_action(cls, user: User, comment: str = None):
|
||||
def get_recorded_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.RECORDED,
|
||||
@@ -114,7 +113,7 @@ class UserActionLogEntry(models.Model):
|
||||
return action
|
||||
|
||||
@classmethod
|
||||
def get_unrecorded_action(cls, user: User, comment: str = None):
|
||||
def get_unrecorded_action(cls, user, comment: str = None):
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.UNRECORDED,
|
||||
|
||||
Reference in New Issue
Block a user