# Identifier Generator View EcoAccount refactoring
* refactors identifier generator view for ecoaccount * simplifies base identifier generator view even further
This commit is contained in:
parent
80e8925a63
commit
be9f6f1b7e
@ -8,8 +8,8 @@ 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, new_id_view, edit_view, remove_view, \
|
from compensation.views.eco_account.eco_account import new_view, edit_view, remove_view, \
|
||||||
detail_view, EcoAccountIndexView
|
detail_view, EcoAccountIndexView, EcoAccountIdentifierGeneratorView
|
||||||
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 report_view
|
from compensation.views.eco_account.report import report_view
|
||||||
@ -30,7 +30,7 @@ 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/', new_view, name='new'),
|
||||||
path('new/id', new_id_view, name='new-id'),
|
path('new/id', EcoAccountIdentifierGeneratorView.as_view(), name='new-id'),
|
||||||
path('<id>', detail_view, name='detail'),
|
path('<id>', detail_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'),
|
||||||
|
|||||||
@ -119,9 +119,6 @@ class CompensationIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGene
|
|||||||
_MODEL_CLS = Compensation
|
_MODEL_CLS = Compensation
|
||||||
_REDIRECT_URL_NAME = "compensation:index"
|
_REDIRECT_URL_NAME = "compensation:index"
|
||||||
|
|
||||||
def _user_has_permission(self, user):
|
|
||||||
return user.is_default_user()
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@default_group_required
|
@default_group_required
|
||||||
|
|||||||
@ -24,7 +24,7 @@ from konova.settings import ETS_GROUP, DEFAULT_GROUP, ZB_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, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
IDENTIFIER_REPLACED, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||||
from konova.views.base import BaseIndexView
|
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountIndexView(LoginRequiredMixin, BaseIndexView):
|
class EcoAccountIndexView(LoginRequiredMixin, BaseIndexView):
|
||||||
@ -96,23 +96,9 @@ def new_view(request: HttpRequest):
|
|||||||
return render(request, template, context)
|
return render(request, template, context)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class EcoAccountIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGeneratorView):
|
||||||
@default_group_required
|
_MODEL_CLS = EcoAccount
|
||||||
def new_id_view(request: HttpRequest):
|
_REDIRECT_URL_NAME = "compensation:acc:index"
|
||||||
""" JSON endpoint
|
|
||||||
|
|
||||||
Provides fetching of free identifiers for e.g. AJAX calls
|
|
||||||
|
|
||||||
"""
|
|
||||||
tmp = EcoAccount()
|
|
||||||
identifier = tmp.generate_new_identifier()
|
|
||||||
while EcoAccount.objects.filter(identifier=identifier).exists():
|
|
||||||
identifier = tmp.generate_new_identifier()
|
|
||||||
return JsonResponse(
|
|
||||||
data={
|
|
||||||
"gen_data": identifier
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@ -104,9 +104,6 @@ class InterventionIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGene
|
|||||||
_MODEL_CLS = Intervention
|
_MODEL_CLS = Intervention
|
||||||
_REDIRECT_URL_NAME = "intervention:index"
|
_REDIRECT_URL_NAME = "intervention:index"
|
||||||
|
|
||||||
def _user_has_permission(self, user):
|
|
||||||
return user.is_default_user()
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@any_group_check
|
@any_group_check
|
||||||
|
|||||||
@ -75,7 +75,7 @@ class BaseIdentifierGeneratorView(View):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _user_has_permission(self, user):
|
def _user_has_permission(self, user):
|
||||||
""" Has to be implemented in inheriting classes!
|
""" Should be overwritten in inheriting classes!
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
user ():
|
user ():
|
||||||
@ -83,4 +83,4 @@ class BaseIdentifierGeneratorView(View):
|
|||||||
Returns:
|
Returns:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
return user.is_default_user()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user