Refactoring
* adds simple getter methods for UserActionLogEntry * replaces manual creation of UserActionLogEntry with new methods
This commit is contained in:
@@ -18,7 +18,7 @@ from compensation.models import Compensation, EcoAccount
|
||||
from intervention.inputs import GenerateInput
|
||||
from intervention.models import Intervention, Responsibility, Legal
|
||||
from konova.forms import BaseForm, SimpleGeomForm
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class AbstractCompensationForm(BaseForm):
|
||||
@@ -210,10 +210,7 @@ class NewCompensationForm(AbstractCompensationForm, CEFCompensationFormMixin, Co
|
||||
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)
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
@@ -270,10 +267,7 @@ class EditCompensationForm(NewCompensationForm):
|
||||
comment = self.cleaned_data.get("comment", None)
|
||||
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
)
|
||||
action = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
@@ -364,10 +358,7 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
||||
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)
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
@@ -444,10 +435,8 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
||||
comment = self.cleaned_data.get("comment", None)
|
||||
|
||||
# Create log entry
|
||||
action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
)
|
||||
action = UserActionLogEntry.get_edited_action(user)
|
||||
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ from compensation.models import CompensationState, CompensationAction
|
||||
from compensation.utils.quality import CompensationQualityChecker
|
||||
from konova.models import BaseObject, AbstractDocument, Geometry, Deadline, generate_document_file_upload_path
|
||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class AbstractCompensation(BaseObject):
|
||||
@@ -57,21 +57,16 @@ class AbstractCompensation(BaseObject):
|
||||
form_data = form.cleaned_data
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
created_action = UserActionLogEntry.get_created_action(user)
|
||||
edited_action = UserActionLogEntry.get_edited_action(user, _("Added deadline"))
|
||||
|
||||
deadline = Deadline.objects.create(
|
||||
type=form_data["type"],
|
||||
date=form_data["date"],
|
||||
comment=form_data["comment"],
|
||||
created=created_action,
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added deadline")
|
||||
)
|
||||
|
||||
self.modified = edited_action
|
||||
self.save()
|
||||
self.log.add(edited_action)
|
||||
@@ -90,10 +85,9 @@ class AbstractCompensation(BaseObject):
|
||||
form_data = form.cleaned_data
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.CREATED,
|
||||
)
|
||||
user_action = UserActionLogEntry.get_created_action(user)
|
||||
edited_action = UserActionLogEntry.get_edited_action(user, _("Added action"))
|
||||
|
||||
comp_action = CompensationAction.objects.create(
|
||||
action_type=form_data["action_type"],
|
||||
amount=form_data["amount"],
|
||||
@@ -101,11 +95,6 @@ class AbstractCompensation(BaseObject):
|
||||
comment=form_data["comment"],
|
||||
created=user_action,
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added action"),
|
||||
)
|
||||
self.modified = edited_action
|
||||
self.save()
|
||||
self.log.add(edited_action)
|
||||
@@ -267,11 +256,7 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin):
|
||||
form_data = form.cleaned_data
|
||||
user = form.user
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added state")
|
||||
)
|
||||
user_action = UserActionLogEntry.get_edited_action(user, _("Added state"))
|
||||
self.log.add(user_action)
|
||||
self.modified = user_action
|
||||
self.save()
|
||||
|
||||
@@ -19,7 +19,7 @@ from compensation.utils.quality import EcoAccountQualityChecker
|
||||
from konova.models import ShareableObjectMixin, RecordableObjectMixin, AbstractDocument, BaseResource, \
|
||||
generate_document_file_upload_path
|
||||
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
from user.models import UserActionLogEntry
|
||||
|
||||
|
||||
class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin):
|
||||
@@ -178,14 +178,8 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
||||
|
||||
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_create = UserActionLogEntry.get_created_action(user)
|
||||
user_action_edit = UserActionLogEntry.get_edited_action(user)
|
||||
self.log.add(user_action_edit)
|
||||
self.modified = user_action_edit
|
||||
self.save()
|
||||
|
||||
Reference in New Issue
Block a user