# Renaming
* renames certain classes to match their content * splits larger files into smaller ones
This commit is contained in:
@@ -237,7 +237,11 @@ class EditEcoAccountForm(NewEcoAccountForm):
|
||||
|
||||
|
||||
class RemoveEcoAccountModalForm(RemoveModalForm):
|
||||
""" Form class
|
||||
|
||||
Provides a form for deleting eco accounts
|
||||
|
||||
"""
|
||||
def is_valid(self):
|
||||
super_valid = super().is_valid()
|
||||
has_deductions = self.instance.deductions.exists()
|
||||
|
||||
@@ -6,29 +6,26 @@ Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpRequest, JsonResponse
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.urls import reverse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.forms.compensation import EditCompensationForm, NewCompensationForm
|
||||
from compensation.models import Compensation
|
||||
from compensation.tables.compensation import CompensationTable
|
||||
from intervention.models import Intervention
|
||||
from konova.decorators import shared_access_required, default_group_required, login_required_modal
|
||||
from konova.forms.modals import RemoveModalForm
|
||||
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE, \
|
||||
from konova.utils.message_templates import DATA_CHECKED_PREVIOUSLY_TEMPLATE, \
|
||||
RECORDED_BLOCKS_EDIT, PARAMS_INVALID
|
||||
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView, BaseNewSpatialLocatedObjectFormView, \
|
||||
BaseEditSpatialLocatedObjectFormView
|
||||
from konova.views.identifier import AbstractIdentifierGeneratorView
|
||||
from konova.views.form import AbstractNewGeometryFormView, AbstractEditGeometryFormView
|
||||
from konova.views.index import AbstractIndexView
|
||||
from konova.views.detail import BaseDetailView
|
||||
from konova.views.remove import BaseRemoveModalFormView
|
||||
|
||||
|
||||
class CompensationIndexView(LoginRequiredMixin, BaseIndexView):
|
||||
class CompensationIndexView(LoginRequiredMixin, AbstractIndexView):
|
||||
_TAB_TITLE = _("Compensations - Overview")
|
||||
_INDEX_TABLE_CLS = CompensationTable
|
||||
|
||||
@@ -42,7 +39,7 @@ class CompensationIndexView(LoginRequiredMixin, BaseIndexView):
|
||||
return qs
|
||||
|
||||
|
||||
class NewCompensationFormView(BaseNewSpatialLocatedObjectFormView):
|
||||
class NewCompensationFormView(AbstractNewGeometryFormView):
|
||||
_FORM_CLS = NewCompensationForm
|
||||
_MODEL_CLS = Compensation
|
||||
_TEMPLATE = "compensation/form/view.html"
|
||||
@@ -82,7 +79,7 @@ class NewCompensationFormView(BaseNewSpatialLocatedObjectFormView):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
class EditCompensationFormView(BaseEditSpatialLocatedObjectFormView):
|
||||
class EditCompensationFormView(AbstractEditGeometryFormView):
|
||||
_MODEL_CLS = Compensation
|
||||
_FORM_CLS = EditCompensationForm
|
||||
_TEMPLATE = "compensation/form/view.html"
|
||||
@@ -93,7 +90,7 @@ class EditCompensationFormView(BaseEditSpatialLocatedObjectFormView):
|
||||
return user.is_default_user()
|
||||
|
||||
|
||||
class CompensationIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGeneratorView):
|
||||
class CompensationIdentifierGeneratorView(LoginRequiredMixin, AbstractIdentifierGeneratorView):
|
||||
_MODEL_CLS = Compensation
|
||||
_REDIRECT_URL = "compensation:index"
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ from django.urls import reverse
|
||||
from compensation.models import Compensation
|
||||
from konova.sub_settings.django_settings import BASE_URL
|
||||
from konova.utils.qrcode import QrCode
|
||||
from konova.views.report import BaseReportView
|
||||
from konova.views.report import AbstractReportView
|
||||
|
||||
|
||||
class BaseCompensationReportView(BaseReportView):
|
||||
class BaseCompensationReportView(AbstractReportView):
|
||||
def _get_compensation_report_context(self, obj):
|
||||
# Order states by surface
|
||||
before_states = obj.before_states.all().order_by("-surface").prefetch_related("biotope_type")
|
||||
|
||||
@@ -5,31 +5,24 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
|
||||
Created on: 19.08.22
|
||||
|
||||
"""
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.forms.eco_account import EditEcoAccountForm, NewEcoAccountForm, RemoveEcoAccountModalForm
|
||||
from compensation.models import EcoAccount
|
||||
from compensation.tables.eco_account import EcoAccountTable
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import shared_access_required, default_group_required, login_required_modal
|
||||
from konova.forms import SimpleGeomForm
|
||||
from konova.settings import ETS_GROUP
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \
|
||||
IDENTIFIER_REPLACED, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView, BaseNewSpatialLocatedObjectFormView, \
|
||||
BaseEditSpatialLocatedObjectFormView
|
||||
from konova.views.identifier import AbstractIdentifierGeneratorView
|
||||
from konova.views.form import AbstractNewGeometryFormView, AbstractEditGeometryFormView
|
||||
from konova.views.index import AbstractIndexView
|
||||
from konova.views.detail import BaseDetailView
|
||||
from konova.views.remove import BaseRemoveModalFormView
|
||||
|
||||
|
||||
class EcoAccountIndexView(LoginRequiredMixin, BaseIndexView):
|
||||
class EcoAccountIndexView(LoginRequiredMixin, AbstractIndexView):
|
||||
""" View class for indexing eco accounts
|
||||
|
||||
"""
|
||||
_INDEX_TABLE_CLS = EcoAccountTable
|
||||
_TAB_TITLE = _("Eco-account - Overview")
|
||||
|
||||
@@ -42,7 +35,12 @@ class EcoAccountIndexView(LoginRequiredMixin, BaseIndexView):
|
||||
return qs
|
||||
|
||||
|
||||
class NewEcoAccountFormView(BaseNewSpatialLocatedObjectFormView):
|
||||
class NewEcoAccountFormView(AbstractNewGeometryFormView):
|
||||
""" Form view class
|
||||
|
||||
Renders a form for new eco accounts
|
||||
|
||||
"""
|
||||
_FORM_CLS = NewEcoAccountForm
|
||||
_MODEL_CLS = EcoAccount
|
||||
_TEMPLATE = "compensation/form/view.html"
|
||||
@@ -54,7 +52,12 @@ class NewEcoAccountFormView(BaseNewSpatialLocatedObjectFormView):
|
||||
return user.is_default_user()
|
||||
|
||||
|
||||
class EditEcoAccountFormView(BaseEditSpatialLocatedObjectFormView):
|
||||
class EditEcoAccountFormView(AbstractEditGeometryFormView):
|
||||
""" Form view class
|
||||
|
||||
Renders a form for editing of eco accounts
|
||||
|
||||
"""
|
||||
_FORM_CLS = EditEcoAccountForm
|
||||
_MODEL_CLS = EcoAccount
|
||||
_TEMPLATE = "compensation/form/view.html"
|
||||
@@ -65,129 +68,20 @@ class EditEcoAccountFormView(BaseEditSpatialLocatedObjectFormView):
|
||||
return user.is_default_user()
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def new_view(request: HttpRequest):
|
||||
"""
|
||||
Renders a view for a new eco account creation
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
|
||||
Returns:
|
||||
class EcoAccountIdentifierGeneratorView(LoginRequiredMixin, AbstractIdentifierGeneratorView):
|
||||
""" View class for identifier generation on eco accounts
|
||||
|
||||
"""
|
||||
template = "compensation/form/view.html"
|
||||
data_form = NewEcoAccountForm(request.POST or None)
|
||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False)
|
||||
if request.method == "POST":
|
||||
if data_form.is_valid() and geom_form.is_valid():
|
||||
generated_identifier = data_form.cleaned_data.get("identifier", None)
|
||||
acc = data_form.save(request.user, geom_form)
|
||||
if generated_identifier != acc.identifier:
|
||||
messages.info(
|
||||
request,
|
||||
IDENTIFIER_REPLACED.format(
|
||||
generated_identifier,
|
||||
acc.identifier
|
||||
)
|
||||
)
|
||||
messages.success(request, _("Eco-Account {} added").format(acc.identifier))
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("compensation:acc:detail", id=acc.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
else:
|
||||
# For clarification: nothing in this case
|
||||
pass
|
||||
context = {
|
||||
"form": data_form,
|
||||
"geom_form": geom_form,
|
||||
TAB_TITLE_IDENTIFIER: _("New Eco-Account"),
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
class EcoAccountIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGeneratorView):
|
||||
_MODEL_CLS = EcoAccount
|
||||
_REDIRECT_URL = "compensation:acc:index"
|
||||
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def edit_view(request: HttpRequest, id: str):
|
||||
"""
|
||||
Renders a view for editing compensations
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
template = "compensation/form/view.html"
|
||||
# Get object from db
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
if acc.is_recorded:
|
||||
messages.info(
|
||||
request,
|
||||
RECORDED_BLOCKS_EDIT
|
||||
)
|
||||
return redirect("compensation:acc:detail", id=id)
|
||||
|
||||
# Create forms, initialize with values from db/from POST request
|
||||
data_form = EditEcoAccountForm(request.POST or None, instance=acc)
|
||||
geom_form = SimpleGeomForm(request.POST or None, read_only=False, instance=acc)
|
||||
if request.method == "POST":
|
||||
data_form_valid = data_form.is_valid()
|
||||
geom_form_valid = geom_form.is_valid()
|
||||
if data_form_valid and geom_form_valid:
|
||||
# The data form takes the geom form for processing, as well as the performing user
|
||||
acc = data_form.save(request.user, geom_form)
|
||||
messages.success(request, _("Eco-Account {} edited").format(acc.identifier))
|
||||
if geom_form.has_geometry_simplified():
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRY_SIMPLIFIED
|
||||
)
|
||||
|
||||
num_ignored_geometries = geom_form.get_num_geometries_ignored()
|
||||
if num_ignored_geometries > 0:
|
||||
messages.info(
|
||||
request,
|
||||
GEOMETRIES_IGNORED_TEMPLATE.format(num_ignored_geometries)
|
||||
)
|
||||
|
||||
return redirect("compensation:acc:detail", id=acc.id)
|
||||
else:
|
||||
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||
else:
|
||||
# For clarification: nothing in this case
|
||||
pass
|
||||
context = {
|
||||
"form": data_form,
|
||||
"geom_form": geom_form,
|
||||
TAB_TITLE_IDENTIFIER: _("Edit {}").format(acc.identifier),
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
class EcoAccountDetailView(BaseDetailView):
|
||||
""" Detail view class
|
||||
|
||||
Renders details of an eco account
|
||||
|
||||
"""
|
||||
_MODEL_CLS = EcoAccount
|
||||
_TEMPLATE = "compensation/detail/eco_account/view.html"
|
||||
|
||||
@@ -256,6 +150,11 @@ class EcoAccountDetailView(BaseDetailView):
|
||||
|
||||
|
||||
class RemoveEcoAccountView(LoginRequiredMixin, BaseRemoveModalFormView):
|
||||
""" Form view class
|
||||
|
||||
Renders a form for removing eco accounts
|
||||
|
||||
"""
|
||||
_MODEL_CLS = EcoAccount
|
||||
_FORM_CLS = RemoveEcoAccountModalForm
|
||||
_REDIRECT_URL = "compensation:acc:index"
|
||||
|
||||
@@ -10,10 +10,10 @@ from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from compensation.forms.modals.payment import NewPaymentForm, RemovePaymentModalForm, EditPaymentModalForm
|
||||
from intervention.models import Intervention
|
||||
from konova.utils.message_templates import PAYMENT_ADDED, PAYMENT_REMOVED, PAYMENT_EDITED
|
||||
from konova.views.base import BaseModalFormView
|
||||
from konova.views.modal import AbstractModalFormView
|
||||
|
||||
|
||||
class BasePaymentView(LoginRequiredMixin, BaseModalFormView):
|
||||
class BasePaymentView(LoginRequiredMixin, AbstractModalFormView):
|
||||
_MODEL_CLS = Intervention
|
||||
_REDIRECT_URL = "intervention:detail"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user