Refactoring
* renames model ResponsibilityData into Responsibility * renames model LegalData into Legal * moves form->object saving logic into model * refactors NewDocumentForm into special types for intervention, compensation, eco account and ema *
This commit is contained in:
@@ -16,7 +16,7 @@ from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID
|
||||
from compensation.models import Compensation, EcoAccount
|
||||
from intervention.inputs import GenerateInput
|
||||
from intervention.models import Intervention, ResponsibilityData, LegalData
|
||||
from intervention.models import Intervention, Responsibility, Legal
|
||||
from konova.forms import BaseForm, SimpleGeomForm
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
@@ -371,13 +371,13 @@ class NewEcoAccountForm(AbstractCompensationForm, CompensationResponsibleFormMix
|
||||
# Process the geometry form
|
||||
geometry = geom_form.save(action)
|
||||
|
||||
responsible = ResponsibilityData.objects.create(
|
||||
responsible = Responsibility.objects.create(
|
||||
handler=handler,
|
||||
conservation_file_number=conservation_file_number,
|
||||
conservation_office=conservation_office,
|
||||
)
|
||||
|
||||
legal = LegalData.objects.create(
|
||||
legal = Legal.objects.create(
|
||||
registration_date=registration_date
|
||||
)
|
||||
|
||||
|
||||
@@ -9,19 +9,17 @@ from bootstrap_modal_forms.utils import is_ajax
|
||||
from dal import autocomplete
|
||||
from django import forms
|
||||
from django.contrib import messages
|
||||
from django.db import transaction
|
||||
from django.http import HttpRequest, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.utils.translation import pgettext_lazy as _con, gettext_lazy as _
|
||||
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_COMPENSATION_ACTION_ID
|
||||
from compensation.models import Payment, CompensationState, UnitChoices, CompensationAction
|
||||
from compensation.models import CompensationDocument, EcoAccountDocument
|
||||
from konova.contexts import BaseContext
|
||||
from konova.forms import BaseModalForm
|
||||
from konova.models import DeadlineType, Deadline
|
||||
from konova.forms import BaseModalForm, NewDocumentForm
|
||||
from konova.models import DeadlineType
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
from user.models import UserActionLogEntry, UserAction
|
||||
|
||||
|
||||
class NewPaymentForm(BaseModalForm):
|
||||
@@ -99,27 +97,8 @@ class NewPaymentForm(BaseModalForm):
|
||||
return super_valid
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CREATED,
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added payment"),
|
||||
)
|
||||
pay = Payment.objects.create(
|
||||
created=created_action,
|
||||
amount=self.cleaned_data.get("amount", -1),
|
||||
due_on=self.cleaned_data.get("due", None),
|
||||
comment=self.cleaned_data.get("comment", None),
|
||||
intervention=self.intervention,
|
||||
)
|
||||
self.intervention.log.add(edited_action)
|
||||
self.intervention.modified = edited_action
|
||||
self.intervention.save()
|
||||
return pay
|
||||
pay = self.instance.add_payment(self)
|
||||
return pay
|
||||
|
||||
|
||||
class NewStateModalForm(BaseModalForm):
|
||||
@@ -167,24 +146,7 @@ class NewStateModalForm(BaseModalForm):
|
||||
self.form_caption = _("Insert data for the new state")
|
||||
|
||||
def save(self, is_before_state: bool = False):
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added state")
|
||||
)
|
||||
self.instance.log.add(user_action)
|
||||
self.instance.modified = user_action
|
||||
self.instance.save()
|
||||
|
||||
state = CompensationState.objects.create(
|
||||
biotope_type=self.cleaned_data["biotope_type"],
|
||||
surface=self.cleaned_data["surface"],
|
||||
)
|
||||
if is_before_state:
|
||||
self.instance.before_states.add(state)
|
||||
else:
|
||||
self.instance.after_states.add(state)
|
||||
state = self.instance.add_state(self, is_before_state)
|
||||
return state
|
||||
|
||||
def process_request(self, request: HttpRequest, msg_success: str = _("Object removed"), msg_error: str = FORM_INVALID, redirect_url: str = None):
|
||||
@@ -287,26 +249,7 @@ class NewDeadlineModalForm(BaseModalForm):
|
||||
self.form_caption = _("Insert data for the new deadline")
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
created_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CREATED
|
||||
)
|
||||
deadline = Deadline.objects.create(
|
||||
type=self.cleaned_data["type"],
|
||||
date=self.cleaned_data["date"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
created=created_action,
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added deadline")
|
||||
)
|
||||
self.instance.modified = edited_action
|
||||
self.instance.save()
|
||||
self.instance.log.add(edited_action)
|
||||
self.instance.deadlines.add(deadline)
|
||||
deadline = self.instance.add_new_deadline(self)
|
||||
return deadline
|
||||
|
||||
|
||||
@@ -318,6 +261,7 @@ class NewActionModalForm(BaseModalForm):
|
||||
(not in the process logic in Konova, but in the real world).
|
||||
|
||||
"""
|
||||
from compensation.models import UnitChoices
|
||||
action_type = forms.ModelChoiceField(
|
||||
label=_("Action Type"),
|
||||
label_suffix="",
|
||||
@@ -381,25 +325,13 @@ class NewActionModalForm(BaseModalForm):
|
||||
self.form_caption = _("Insert data for the new action")
|
||||
|
||||
def save(self):
|
||||
with transaction.atomic():
|
||||
user_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.CREATED,
|
||||
)
|
||||
comp_action = CompensationAction.objects.create(
|
||||
action_type=self.cleaned_data["action_type"],
|
||||
amount=self.cleaned_data["amount"],
|
||||
unit=self.cleaned_data["unit"],
|
||||
comment=self.cleaned_data["comment"],
|
||||
created=user_action,
|
||||
)
|
||||
edited_action = UserActionLogEntry.objects.create(
|
||||
user=self.user,
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added action"),
|
||||
)
|
||||
self.instance.modified = edited_action
|
||||
self.instance.save()
|
||||
self.instance.log.add(edited_action)
|
||||
self.instance.actions.add(comp_action)
|
||||
return comp_action
|
||||
action = self.instance.add_new_action(self)
|
||||
return action
|
||||
|
||||
|
||||
class NewCompensationDocumentForm(NewDocumentForm):
|
||||
document_model = CompensationDocument
|
||||
|
||||
|
||||
class NewEcoAccountDocumentForm(NewDocumentForm):
|
||||
document_model = EcoAccountDocument
|
||||
Reference in New Issue
Block a user