Refactoring
* adds simple getter methods for UserActionLogEntry * replaces manual creation of UserActionLogEntry with new methods
This commit is contained in:
@@ -10,7 +10,6 @@ from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import transaction
|
||||
from django.urls import reverse, reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
@@ -19,7 +18,7 @@ from codelist.settings import CODELIST_PROCESS_TYPE_ID, CODELIST_LAW_ID, \
|
||||
from intervention.inputs import GenerateInput
|
||||
from intervention.models import Intervention, Legal, Responsibility
|
||||
from konova.forms import BaseForm, SimpleGeomForm
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class NewInterventionForm(BaseForm):
|
||||
@@ -214,10 +213,7 @@ class NewInterventionForm(BaseForm):
|
||||
comment = self.cleaned_data.get("comment", None)
|
||||
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED,
|
||||
)
|
||||
action = UserActionLogEntry.get_created_action(user)
|
||||
|
||||
# Create legal data object (without M2M laws first)
|
||||
legal_data = Legal.objects.create(
|
||||
@@ -337,11 +333,7 @@ class EditInterventionForm(NewInterventionForm):
|
||||
self.instance.responsible.conservation_file_number = conservation_file_number
|
||||
self.instance.responsible.save()
|
||||
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
timestamp=timezone.now(),
|
||||
action=UserAction.EDITED,
|
||||
)
|
||||
user_action = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
geometry = geom_form.save(user_action)
|
||||
self.instance.geometry = geometry
|
||||
@@ -356,8 +348,10 @@ class EditInterventionForm(NewInterventionForm):
|
||||
self.instance.save()
|
||||
|
||||
# Uncheck and unrecord intervention due to changed data
|
||||
self.instance.set_unchecked()
|
||||
self.instance.set_unrecorded(user)
|
||||
if self.instance.checked:
|
||||
self.instance.set_unchecked()
|
||||
if self.instance.recorded:
|
||||
self.instance.set_unrecorded(user)
|
||||
|
||||
return self.instance
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ from intervention.utils.quality import InterventionQualityChecker
|
||||
from konova.models import generate_document_file_upload_path, AbstractDocument, Geometry, BaseObject, ShareableObjectMixin, \
|
||||
RecordableObjectMixin, CheckableObjectMixin
|
||||
from konova.settings import LANIS_LINK_TEMPLATE, LANIS_ZOOM_LUT, DEFAULT_SRID_RLP
|
||||
from user.models import UserAction, UserActionLogEntry
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, CheckableObjectMixin):
|
||||
@@ -189,15 +189,9 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
form_data = form.cleaned_data
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED,
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added payment"),
|
||||
)
|
||||
created_action = UserActionLogEntry.get_created_action(user)
|
||||
edited_action = UserActionLogEntry.get_edited_action(user, _("Added payment"))
|
||||
|
||||
pay = Payment.objects.create(
|
||||
created=created_action,
|
||||
amount=form_data.get("amount", -1),
|
||||
@@ -222,14 +216,9 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
form_data = form.cleaned_data
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED
|
||||
)
|
||||
created_action = UserActionLogEntry.get_created_action(user)
|
||||
edited_action = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
revocation = Revocation.objects.create(
|
||||
date=form_data["date"],
|
||||
legal=self.legal,
|
||||
@@ -264,14 +253,9 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec
|
||||
|
||||
with transaction.atomic():
|
||||
# Create log entry
|
||||
user_action_edit = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED
|
||||
)
|
||||
user_action_create = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
user_action_edit = UserActionLogEntry.get_edited_action(user)
|
||||
user_action_create = UserActionLogEntry.get_created_action(user)
|
||||
|
||||
self.log.add(user_action_edit)
|
||||
self.modified = user_action_edit
|
||||
self.save()
|
||||
|
||||
@@ -356,10 +356,7 @@ class InterventionWorkflowTestCase(BaseWorkflowTestCase):
|
||||
# Prepare the account for a working situation (enough deductable surface, recorded and shared)
|
||||
self.eco_account.deductable_surface = 10000.00
|
||||
if self.eco_account.recorded is None:
|
||||
rec_action = UserActionLogEntry.objects.create(
|
||||
user=self.superuser,
|
||||
action=UserAction.RECORDED
|
||||
)
|
||||
rec_action = UserActionLogEntry.get_recorded_action(self.superuser)
|
||||
self.eco_account.recorded = rec_action
|
||||
self.eco_account.share_with_list([self.superuser])
|
||||
self.eco_account.save()
|
||||
|
||||
Reference in New Issue
Block a user