# NewEcoAccount EditEcoAccount view
* refactors new and edit eco account views from function to class based * removes info message if checked intervention is altered and loses the current checked state * updates comments/documentation * removes code duplicates * fixes display error where modal form was hidden behind menu bar of map client * fixes bug where compensation could not be created directly from intervention
This commit is contained in:
parent
73178b3fd2
commit
a86d86b731
@ -510,12 +510,6 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin, PikMixin):
|
|||||||
|
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
@property
|
|
||||||
def checked(self):
|
|
||||||
if self.intervention:
|
|
||||||
return self.intervention.checked
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
class CompensationDocument(AbstractDocument):
|
class CompensationDocument(AbstractDocument):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -8,8 +8,9 @@ Created on: 24.08.21
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from compensation.autocomplete.eco_account import EcoAccountAutocomplete
|
from compensation.autocomplete.eco_account import EcoAccountAutocomplete
|
||||||
from compensation.views.eco_account.eco_account import new_view, edit_view, remove_view, \
|
from compensation.views.eco_account.eco_account import remove_view, \
|
||||||
EcoAccountIndexView, EcoAccountIdentifierGeneratorView, EcoAccountDetailView
|
EcoAccountIndexView, EcoAccountIdentifierGeneratorView, EcoAccountDetailView, NewEcoAccountFormView, \
|
||||||
|
EditEcoAccountFormView
|
||||||
from compensation.views.eco_account.log import EcoAccountLogView
|
from compensation.views.eco_account.log import EcoAccountLogView
|
||||||
from compensation.views.eco_account.record import EcoAccountRecordView
|
from compensation.views.eco_account.record import EcoAccountRecordView
|
||||||
from compensation.views.eco_account.report import EcoAccountReportView
|
from compensation.views.eco_account.report import EcoAccountReportView
|
||||||
@ -29,13 +30,13 @@ from compensation.views.eco_account.deduction import NewEcoAccountDeductionView,
|
|||||||
app_name = "acc"
|
app_name = "acc"
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", EcoAccountIndexView.as_view(), name="index"),
|
path("", EcoAccountIndexView.as_view(), name="index"),
|
||||||
path('new/', new_view, name='new'),
|
path('new/', NewEcoAccountFormView.as_view(), name='new'),
|
||||||
path('new/id', EcoAccountIdentifierGeneratorView.as_view(), name='new-id'),
|
path('new/id', EcoAccountIdentifierGeneratorView.as_view(), name='new-id'),
|
||||||
path('<id>', EcoAccountDetailView.as_view(), name='detail'),
|
path('<id>', EcoAccountDetailView.as_view(), name='detail'),
|
||||||
path('<id>/log', EcoAccountLogView.as_view(), name='log'),
|
path('<id>/log', EcoAccountLogView.as_view(), name='log'),
|
||||||
path('<id>/record', EcoAccountRecordView.as_view(), name='record'),
|
path('<id>/record', EcoAccountRecordView.as_view(), name='record'),
|
||||||
path('<id>/report', EcoAccountReportView.as_view(), name='report'),
|
path('<id>/report', EcoAccountReportView.as_view(), name='report'),
|
||||||
path('<id>/edit', edit_view, name='edit'),
|
path('<id>/edit', EditEcoAccountFormView.as_view(), name='edit'),
|
||||||
path('<id>/remove', remove_view, name='remove'),
|
path('<id>/remove', remove_view, name='remove'),
|
||||||
path('<id>/resub', EcoAccountResubmissionView.as_view(), name='resubmission-create'),
|
path('<id>/resub', EcoAccountResubmissionView.as_view(), name='resubmission-create'),
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ class EditCompensationFormView(BaseEditSpatialLocatedObjectFormView):
|
|||||||
_REDIRECT_URL = "compensation:detail"
|
_REDIRECT_URL = "compensation:detail"
|
||||||
|
|
||||||
def _user_has_permission(self, user):
|
def _user_has_permission(self, user):
|
||||||
# User has to be an ets user
|
# User has to be a default user
|
||||||
return user.is_default_user()
|
return user.is_default_user()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,8 @@ from konova.settings import ETS_GROUP
|
|||||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
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, \
|
from konova.utils.message_templates import CANCEL_ACC_RECORDED_OR_DEDUCTED, RECORDED_BLOCKS_EDIT, FORM_INVALID, \
|
||||||
IDENTIFIER_REPLACED, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
IDENTIFIER_REPLACED, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||||
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView
|
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView, BaseNewSpatialLocatedObjectFormView, \
|
||||||
|
BaseEditSpatialLocatedObjectFormView
|
||||||
from konova.views.detail import BaseDetailView
|
from konova.views.detail import BaseDetailView
|
||||||
|
|
||||||
|
|
||||||
@ -40,6 +41,29 @@ class EcoAccountIndexView(LoginRequiredMixin, BaseIndexView):
|
|||||||
return qs
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
class NewEcoAccountFormView(BaseNewSpatialLocatedObjectFormView):
|
||||||
|
_FORM_CLS = NewEcoAccountForm
|
||||||
|
_MODEL_CLS = EcoAccount
|
||||||
|
_TEMPLATE = "compensation/form/view.html"
|
||||||
|
_TAB_TITLE = _("New Eco-Account")
|
||||||
|
_REDIRECT_URL = "compensation:acc:detail"
|
||||||
|
|
||||||
|
def _user_has_permission(self, user):
|
||||||
|
# User has to be a default user
|
||||||
|
return user.is_default_user()
|
||||||
|
|
||||||
|
|
||||||
|
class EditEcoAccountFormView(BaseEditSpatialLocatedObjectFormView):
|
||||||
|
_FORM_CLS = EditEcoAccountForm
|
||||||
|
_MODEL_CLS = EcoAccount
|
||||||
|
_TEMPLATE = "compensation/form/view.html"
|
||||||
|
_REDIRECT_URL = "compensation:acc:detail"
|
||||||
|
|
||||||
|
def _user_has_permission(self, user):
|
||||||
|
# User has to be a default user
|
||||||
|
return user.is_default_user()
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
def new_view(request: HttpRequest):
|
def new_view(request: HttpRequest):
|
||||||
|
|||||||
@ -46,10 +46,6 @@ class NewEmaFormView(BaseNewSpatialLocatedObjectFormView):
|
|||||||
# User has to be an ets user
|
# User has to be an ets user
|
||||||
return user.is_ets_user()
|
return user.is_ets_user()
|
||||||
|
|
||||||
def _user_has_shared_access(self, user, **kwargs):
|
|
||||||
# No specific share constraint for creatin EMA entries
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class EditEmaFormView(BaseEditSpatialLocatedObjectFormView):
|
class EditEmaFormView(BaseEditSpatialLocatedObjectFormView):
|
||||||
_MODEL_CLS = Ema
|
_MODEL_CLS = Ema
|
||||||
|
|||||||
@ -48,7 +48,7 @@ class BaseForm(forms.Form):
|
|||||||
self.__check_valid_label_input_ratio()
|
self.__check_valid_label_input_ratio()
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def save(self):
|
def save(self, *arg, **kwargs):
|
||||||
# To be implemented in subclasses!
|
# To be implemented in subclasses!
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@ -289,3 +289,7 @@ Overwrites netgis.css attributes
|
|||||||
*/
|
*/
|
||||||
background: var(--rlp-red) !important;
|
background: var(--rlp-red) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.modal{
|
||||||
|
z-index: 100000;
|
||||||
|
}
|
||||||
@ -18,7 +18,7 @@ from konova.forms import BaseForm, SimpleGeomForm
|
|||||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||||
from konova.utils.general import check_user_is_in_any_group
|
from konova.utils.general import check_user_is_in_any_group
|
||||||
from konova.utils.message_templates import MISSING_GROUP_PERMISSION, DATA_UNSHARED, IDENTIFIER_REPLACED, \
|
from konova.utils.message_templates import MISSING_GROUP_PERMISSION, DATA_UNSHARED, IDENTIFIER_REPLACED, \
|
||||||
GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE, RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET
|
GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE, RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET, FORM_INVALID
|
||||||
|
|
||||||
|
|
||||||
class BaseView(View):
|
class BaseView(View):
|
||||||
@ -152,7 +152,15 @@ class BaseFormView(BaseView):
|
|||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def _get_additional_context_data(self, **kwargs):
|
def _get_additional_context(self, **kwargs):
|
||||||
|
"""
|
||||||
|
|
||||||
|
Args:
|
||||||
|
**kwargs ():
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
"""
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
@ -173,11 +181,11 @@ class BaseNewSpatialLocatedObjectFormView(BaseSpatialLocatedObjectFormView):
|
|||||||
# There is no shared access control since nothing exists yet
|
# There is no shared access control since nothing exists yet
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get(self, request: HttpRequest):
|
def get(self, request: HttpRequest, **kwargs):
|
||||||
form: BaseForm = self._FORM_CLS(None, user=request.user)
|
form: BaseForm = self._FORM_CLS(None, **kwargs, user=request.user)
|
||||||
geom_form: SimpleGeomForm = self._GEOMETRY_FORM_CLS(None, user=request.user, read_only=False)
|
geom_form: SimpleGeomForm = self._GEOMETRY_FORM_CLS(None, user=request.user, read_only=False)
|
||||||
|
|
||||||
context = self._get_additional_context_data()
|
context = self._get_additional_context()
|
||||||
context = BaseContext(request, additional_context=context).context
|
context = BaseContext(request, additional_context=context).context
|
||||||
context.update(
|
context.update(
|
||||||
{
|
{
|
||||||
@ -188,8 +196,8 @@ class BaseNewSpatialLocatedObjectFormView(BaseSpatialLocatedObjectFormView):
|
|||||||
)
|
)
|
||||||
return render(request, self._TEMPLATE, context)
|
return render(request, self._TEMPLATE, context)
|
||||||
|
|
||||||
def post(self, request: HttpRequest):
|
def post(self, request: HttpRequest, **kwargs):
|
||||||
form: BaseForm = self._FORM_CLS(request.POST or None, user=request.user)
|
form: BaseForm = self._FORM_CLS(request.POST or None, **kwargs, user=request.user)
|
||||||
geom_form: SimpleGeomForm = self._GEOMETRY_FORM_CLS(request.POST or None, user=request.user, read_only=False)
|
geom_form: SimpleGeomForm = self._GEOMETRY_FORM_CLS(request.POST or None, user=request.user, read_only=False)
|
||||||
|
|
||||||
if form.is_valid() and geom_form.is_valid():
|
if form.is_valid() and geom_form.is_valid():
|
||||||
@ -222,7 +230,8 @@ class BaseNewSpatialLocatedObjectFormView(BaseSpatialLocatedObjectFormView):
|
|||||||
|
|
||||||
return redirect(obj_redirect_url)
|
return redirect(obj_redirect_url)
|
||||||
else:
|
else:
|
||||||
context = self._get_additional_context_data()
|
context = self._get_additional_context()
|
||||||
|
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||||
|
|
||||||
context = BaseContext(request, additional_context=context).context
|
context = BaseContext(request, additional_context=context).context
|
||||||
context.update(
|
context.update(
|
||||||
@ -255,7 +264,7 @@ class BaseEditSpatialLocatedObjectFormView(BaseSpatialLocatedObjectFormView):
|
|||||||
form: BaseForm = self._FORM_CLS(None, instance=obj, user=request.user)
|
form: BaseForm = self._FORM_CLS(None, instance=obj, user=request.user)
|
||||||
geom_form: SimpleGeomForm = self._GEOMETRY_FORM_CLS(None, instance=obj, read_only=False)
|
geom_form: SimpleGeomForm = self._GEOMETRY_FORM_CLS(None, instance=obj, read_only=False)
|
||||||
|
|
||||||
context = self._get_additional_context_data()
|
context = self._get_additional_context()
|
||||||
context = BaseContext(request, additional_context=context).context
|
context = BaseContext(request, additional_context=context).context
|
||||||
context.update(
|
context.update(
|
||||||
{
|
{
|
||||||
@ -280,12 +289,6 @@ class BaseEditSpatialLocatedObjectFormView(BaseSpatialLocatedObjectFormView):
|
|||||||
obj = form.save(request.user, geom_form)
|
obj = form.save(request.user, geom_form)
|
||||||
messages.success(request, _("{} edited").format(obj.identifier))
|
messages.success(request, _("{} edited").format(obj.identifier))
|
||||||
|
|
||||||
# The data form takes the geom form for processing, as well as the performing user
|
|
||||||
# Save the current state of recorded|checked to inform the user in case of a status reset due to editing
|
|
||||||
obj_is_checked = obj.checked is not None
|
|
||||||
if obj_is_checked:
|
|
||||||
messages.info(request, CHECK_STATE_RESET)
|
|
||||||
|
|
||||||
if geom_form.has_geometry_simplified():
|
if geom_form.has_geometry_simplified():
|
||||||
messages.info(
|
messages.info(
|
||||||
request,
|
request,
|
||||||
@ -301,7 +304,8 @@ class BaseEditSpatialLocatedObjectFormView(BaseSpatialLocatedObjectFormView):
|
|||||||
|
|
||||||
return redirect(obj_redirect_url)
|
return redirect(obj_redirect_url)
|
||||||
else:
|
else:
|
||||||
context = self._get_additional_context_data()
|
context = self._get_additional_context()
|
||||||
|
messages.error(request, FORM_INVALID, extra_tags="danger",)
|
||||||
|
|
||||||
context = BaseContext(request, additional_context=context).context
|
context = BaseContext(request, additional_context=context).context
|
||||||
context.update(
|
context.update(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user