# Identifier Generator View Compensation refactoring

* refactors identifier generator view for compensation
This commit is contained in:
mpeltriaux 2025-10-15 16:42:42 +02:00
parent c597e1934b
commit 80e8925a63
2 changed files with 9 additions and 20 deletions

View File

@ -17,14 +17,14 @@ from compensation.views.compensation.action import NewCompensationActionView, Ed
RemoveCompensationActionView RemoveCompensationActionView
from compensation.views.compensation.state import NewCompensationStateView, EditCompensationStateView, \ from compensation.views.compensation.state import NewCompensationStateView, EditCompensationStateView, \
RemoveCompensationStateView RemoveCompensationStateView
from compensation.views.compensation.compensation import new_view, new_id_view, detail_view, edit_view, \ from compensation.views.compensation.compensation import new_view, detail_view, edit_view, \
remove_view, CompensationIndexView remove_view, CompensationIndexView, CompensationIdentifierGeneratorView
from compensation.views.compensation.log import CompensationLogView from compensation.views.compensation.log import CompensationLogView
urlpatterns = [ urlpatterns = [
# Main compensation # Main compensation
path("", CompensationIndexView.as_view(), name="index"), path("", CompensationIndexView.as_view(), name="index"),
path('new/id', new_id_view, name='new-id'), path('new/id', CompensationIdentifierGeneratorView.as_view(), name='new-id'),
path('new/<intervention_id>', new_view, name='new'), path('new/<intervention_id>', new_view, name='new'),
path('new', new_view, name='new'), path('new', new_view, name='new'),
path('<id>', detail_view, name='detail'), path('<id>', detail_view, name='detail'),

View File

@ -28,7 +28,7 @@ from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE, \ from konova.utils.message_templates import COMPENSATION_REMOVED_TEMPLATE, DATA_CHECKED_PREVIOUSLY_TEMPLATE, \
RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET, FORM_INVALID, PARAMS_INVALID, IDENTIFIER_REPLACED, \ RECORDED_BLOCKS_EDIT, CHECK_STATE_RESET, FORM_INVALID, PARAMS_INVALID, IDENTIFIER_REPLACED, \
COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE COMPENSATION_ADDED_TEMPLATE, DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
from konova.views.base import BaseIndexView from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView
class CompensationIndexView(LoginRequiredMixin, BaseIndexView): class CompensationIndexView(LoginRequiredMixin, BaseIndexView):
@ -115,23 +115,12 @@ def new_view(request: HttpRequest, intervention_id: str = None):
return render(request, template, context) return render(request, template, context)
@login_required class CompensationIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGeneratorView):
@default_group_required _MODEL_CLS = Compensation
def new_id_view(request: HttpRequest): _REDIRECT_URL_NAME = "compensation:index"
""" JSON endpoint
Provides fetching of free identifiers for e.g. AJAX calls def _user_has_permission(self, user):
return user.is_default_user()
"""
tmp = Compensation()
identifier = tmp.generate_new_identifier()
while Compensation.objects.filter(identifier=identifier).exists():
identifier = tmp.generate_new_identifier()
return JsonResponse(
data={
"gen_data": identifier
}
)
@login_required @login_required