Created|Deleted refactoring

* refactors base attributes created and deleted into UserActionLogEntry foreign keys
* refactors all related queries and process logic
* fixes binding_on into binding_date in intervention/detail/view.html
* adds basic __str__ for some models
*
This commit is contained in:
mipel
2021-08-02 11:52:20 +02:00
parent 6bc8ada286
commit 0797a6b99f
17 changed files with 138 additions and 60 deletions

View File

@@ -7,8 +7,8 @@ class InterventionAdmin(admin.ModelAdmin):
list_display = [
"id",
"title",
"created_on",
"deleted_on",
"created",
"deleted",
]

View File

@@ -15,10 +15,12 @@ from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from intervention.models import Intervention
from konova.enums import UserActionLogEntryEnum
from konova.forms import BaseForm, BaseModalForm
from konova.models import Document
from konova.settings import DEFAULT_LAT, DEFAULT_LON, DEFAULT_ZOOM
from organisation.models import Organisation
from user.models import UserActionLogEntry
class NewInterventionForm(BaseForm):
@@ -115,6 +117,10 @@ class NewInterventionForm(BaseForm):
geometry = self.cleaned_data.get("geometry", Polygon())
documents = self.cleaned_data.get("documents", []) or []
action = UserActionLogEntry.objects.create(
user=user,
action=UserActionLogEntryEnum.CREATED.value,
)
intervention = Intervention(
identifier=identifier,
title=title,
@@ -124,7 +130,7 @@ class NewInterventionForm(BaseForm):
data_provider=data_provider,
data_provider_detail=data_provider_detail,
geometry=geometry,
created_by=user,
created=action,
)
intervention.save()
for doc in documents:

View File

@@ -12,6 +12,7 @@ from django.utils import timezone
from django.utils.timezone import now
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
from konova.enums import UserActionLogEntryEnum
from konova.models import BaseObject, Geometry, UuidModel
from konova.utils import generators
from konova.utils.generators import generate_random_string
@@ -30,6 +31,13 @@ class ResponsibilityData(UuidModel):
conservation_file_number = models.CharField(max_length=1000, blank=True, null=True)
handler = models.CharField(max_length=500, null=True, blank=True, help_text="Refers to 'Eingriffsverursacher'")
def __str__(self):
return "ZB: {} | ETS: {} | Handler: {}".format(
self.registration_office,
self.conservation_office,
self.handler
)
class LegalData(UuidModel):
"""
@@ -44,6 +52,13 @@ class LegalData(UuidModel):
process_type = models.CharField(max_length=500, null=True, blank=True)
law = models.CharField(max_length=500, null=True, blank=True)
def __str__(self):
return "{} | {} | {}".format(
self.process_type,
self.law,
self.id
)
class Intervention(BaseObject):
"""
@@ -121,13 +136,20 @@ class Intervention(BaseObject):
with transaction.atomic():
# "Delete" related compensations as well
coms = self.compensations.all()
action = UserActionLogEntry.objects.create(
user=_user,
timestamp=_now,
action=UserActionLogEntryEnum.DELETED.value
)
for com in coms:
com.deleted_on = _now
com.deleted_by = _user
com.deleted = action
#com.deleted_on = _now
#com.deleted_by = _user
com.save()
self.deleted_on = _now
self.deleted_by = _user
self.deleted = action
#self.deleted_on = _now
#self.deleted_by = _user
self.save()
@staticmethod

View File

@@ -50,7 +50,7 @@ class InterventionTable(BaseTable):
lm = tables.Column(
verbose_name=_("Last edit"),
orderable=True,
accessor="created_on",
accessor="created__timestamp",
)
"""
# ToDo: Decide to keep actions column or to dismiss them

View File

@@ -122,15 +122,15 @@
</tr>
<tr>
<th scope="row">{% trans 'Binding on' %}</th>
<td class="align-middle">{{intervention.legal.binding_on|default_if_none:""}}</td>
<td class="align-middle">{{intervention.legal.binding_date|default_if_none:""}}</td>
</tr>
<tr>
<th scope="row">{% trans 'Last modified' %}</th>
<td class="align-middle">
{{intervention.created_on|default_if_none:""|naturalday}}
{{intervention.created.timestamp|default_if_none:""|naturalday}}
<br>
{% trans 'by' %}
{{intervention.created_by|default_if_none:""}}
{{intervention.created.user|default_if_none:""}}
</td>
</tr>
</table>

View File

@@ -28,10 +28,10 @@ def index_view(request: HttpRequest):
# Filtering by user access is performed in table filter inside of InterventionTableFilter class
interventions = Intervention.objects.filter(
deleted_on=None, # not deleted
deleted=None, # not deleted
next_version=None, # only newest versions
).order_by(
"-created_on"
"-created__timestamp"
)
table = InterventionTable(
request=request,
@@ -128,8 +128,7 @@ def open_view(request: HttpRequest, id: str):
# Fetch data, filter out deleted related data
intervention = get_object_or_404(Intervention, id=id)
compensations = intervention.compensations.filter(
deleted_on=None,
deleted_by=None,
deleted=None,
)
has_access = intervention.has_access(user=request.user)