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:
parent
287e0b4068
commit
4647be958b
@ -31,7 +31,7 @@ class CompensationTableFilter(InterventionTableFilter):
|
||||
"""
|
||||
if not value:
|
||||
return queryset.filter(
|
||||
intervention__recorded_on=None,
|
||||
intervention__recorded=None,
|
||||
)
|
||||
else:
|
||||
return queryset
|
||||
|
@ -34,13 +34,13 @@ class CompensationTable(BaseTable):
|
||||
verbose_name=_("Checked"),
|
||||
orderable=True,
|
||||
empty_values=[],
|
||||
accessor="intervention__checked_on",
|
||||
accessor="intervention__checked",
|
||||
)
|
||||
r = tables.Column(
|
||||
verbose_name=_("Recorded"),
|
||||
orderable=True,
|
||||
empty_values=[],
|
||||
accessor="intervention__recorded_on",
|
||||
accessor="intervention__recorded",
|
||||
)
|
||||
e = tables.Column(
|
||||
verbose_name=_("Editable"),
|
||||
@ -90,7 +90,7 @@ class CompensationTable(BaseTable):
|
||||
def render_c(self, value, record: Compensation):
|
||||
""" Renders the checked column for a compensation
|
||||
|
||||
checked_on is set by the main object Intervention
|
||||
checked is set by the main object Intervention
|
||||
|
||||
Args:
|
||||
value (str): The identifier value
|
||||
@ -103,9 +103,10 @@ class CompensationTable(BaseTable):
|
||||
checked = value is not None
|
||||
tooltip = _("Not checked yet")
|
||||
if checked:
|
||||
value = value.timestamp
|
||||
value = localtime(value)
|
||||
checked_on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
||||
tooltip = _("Checked on {} by {}").format(checked_on, record.intervention.checked_by)
|
||||
tooltip = _("Checked on {} by {}").format(checked_on, record.intervention.checked.user)
|
||||
html += self.render_checked_star(
|
||||
tooltip=tooltip,
|
||||
icn_filled=checked,
|
||||
@ -126,9 +127,10 @@ class CompensationTable(BaseTable):
|
||||
checked = value is not None
|
||||
tooltip = _("Not registered yet")
|
||||
if checked:
|
||||
value = value.timestamp
|
||||
value = localtime(value)
|
||||
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
||||
tooltip = _("Registered on {} by {}").format(on, record.intervention.recorded_by)
|
||||
tooltip = _("Registered on {} by {}").format(on, record.intervention.recorded.user)
|
||||
html += self.render_bookmark(
|
||||
tooltip=tooltip,
|
||||
icn_filled=checked,
|
||||
|
@ -117,7 +117,7 @@ class InterventionTableFilter(django_filters.FilterSet):
|
||||
"""
|
||||
if not value:
|
||||
return queryset.filter(
|
||||
recorded_on=None,
|
||||
recorded=None,
|
||||
)
|
||||
else:
|
||||
return queryset
|
||||
|
@ -15,6 +15,7 @@ from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_I
|
||||
from konova.models import BaseObject, Geometry
|
||||
from konova.utils.generators import generate_random_string
|
||||
from organisation.models import Organisation
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class Intervention(BaseObject):
|
||||
@ -32,27 +33,35 @@ class Intervention(BaseObject):
|
||||
geometry = models.ForeignKey(Geometry, null=True, blank=True, on_delete=models.SET_NULL)
|
||||
documents = models.ManyToManyField("konova.Document", blank=True)
|
||||
|
||||
# Checks
|
||||
checked_on = models.DateTimeField(default=None, null=True, blank=True)
|
||||
checked_by = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL, related_name='+')
|
||||
|
||||
# Refers to "zugelassen am"
|
||||
registration_date = models.DateField(null=True, blank=True)
|
||||
|
||||
# Refers to "Bestandskraft am"
|
||||
binding_on = models.DateField(null=True, blank=True)
|
||||
|
||||
# Checks - Refers to "Genehmigen" but optional
|
||||
checked = models.OneToOneField(
|
||||
UserActionLogEntry,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Holds data on user and timestamp of this action",
|
||||
related_name="+"
|
||||
)
|
||||
|
||||
# Refers to "verzeichnen"
|
||||
recorded_on = models.DateTimeField(default=None, null=True, blank=True)
|
||||
recorded_by = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL, related_name='+')
|
||||
recorded = models.OneToOneField(
|
||||
UserActionLogEntry,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Holds data on user and timestamp of this action",
|
||||
related_name="+"
|
||||
)
|
||||
|
||||
# Holds which intervention is simply a newer version of this dataset
|
||||
next_version = models.ForeignKey("Intervention", null=True, blank=True, on_delete=models.DO_NOTHING)
|
||||
|
||||
# Compensation or payments, one-directional
|
||||
#payments = models.ManyToManyField(Payment, related_name="+", blank=True)
|
||||
#compensations = models.ManyToManyField(Compensation, related_name="+", blank=True)
|
||||
|
||||
# Users having access on this object
|
||||
users = models.ManyToManyField(User)
|
||||
|
||||
|
@ -33,13 +33,13 @@ class InterventionTable(BaseTable):
|
||||
verbose_name=_("Checked"),
|
||||
orderable=True,
|
||||
empty_values=[],
|
||||
accessor="checked_on",
|
||||
accessor="checked",
|
||||
)
|
||||
r = tables.Column(
|
||||
verbose_name=_("Recorded"),
|
||||
orderable=True,
|
||||
empty_values=[],
|
||||
accessor="recorded_on",
|
||||
accessor="recorded",
|
||||
)
|
||||
e = tables.Column(
|
||||
verbose_name=_("Editable"),
|
||||
@ -110,9 +110,10 @@ class InterventionTable(BaseTable):
|
||||
checked = value is not None
|
||||
tooltip = _("Not checked yet")
|
||||
if checked:
|
||||
value = value.timestamp
|
||||
value = localtime(value)
|
||||
checked_on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
||||
tooltip = _("Checked on {} by {}").format(checked_on, record.checked_by)
|
||||
tooltip = _("Checked on {} by {}").format(checked_on, record.checked.user)
|
||||
html += self.render_checked_star(
|
||||
tooltip=tooltip,
|
||||
icn_filled=checked,
|
||||
@ -133,9 +134,10 @@ class InterventionTable(BaseTable):
|
||||
checked = value is not None
|
||||
tooltip = _("Not registered yet")
|
||||
if checked:
|
||||
value = value.timestamp
|
||||
value = localtime(value)
|
||||
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
||||
tooltip = _("Registered on {} by {}").format(on, record.recorded_by)
|
||||
tooltip = _("Registered on {} by {}").format(on, record.recorded.user)
|
||||
html += self.render_bookmark(
|
||||
tooltip=tooltip,
|
||||
icn_filled=checked,
|
||||
|
@ -93,7 +93,7 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans 'Checked' %}</th>
|
||||
<td class="align-middle">
|
||||
{% if intervention.checked_on is None %}
|
||||
{% if intervention.checked is None %}
|
||||
<span>
|
||||
{% fa5_icon 'star' 'far' %}
|
||||
</span>
|
||||
@ -107,7 +107,7 @@
|
||||
<tr>
|
||||
<th scope="row">{% trans 'Recorded' %}</th>
|
||||
<td class="align-middle">
|
||||
{% if intervention.recorded_on is None %}
|
||||
{% if intervention.recorded is None %}
|
||||
<span>
|
||||
{% fa5_icon 'bookmark' 'far' %}
|
||||
</span>
|
||||
|
@ -47,3 +47,11 @@ class ServerMessageImportance(BaseEnum):
|
||||
DEFAULT = "DEFAULT"
|
||||
INFO = "INFO"
|
||||
WARNING = "WARNING"
|
||||
|
||||
|
||||
class UserActionLogEntryEnum(BaseEnum):
|
||||
"""
|
||||
Defines different possible user actions for UserActionLogEntry
|
||||
"""
|
||||
CHECKED = "Checked"
|
||||
RECORDED = "Recorded"
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user