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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user