# NewId Generator Ema refactoring
* introduces BaseNewIdentifierGeneratorView class * refactors new identifier generator view for ema
This commit is contained in:
@@ -24,8 +24,8 @@ from konova.forms.modals import RemoveModalForm
|
||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
from konova.sub_settings.context_settings import TAB_TITLE_IDENTIFIER
|
||||
from konova.utils.message_templates import RECORDED_BLOCKS_EDIT, IDENTIFIER_REPLACED, FORM_INVALID, \
|
||||
DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE
|
||||
from konova.views.base import BaseIndexView
|
||||
DO_NOT_FORGET_TO_SHARE, GEOMETRY_SIMPLIFIED, GEOMETRIES_IGNORED_TEMPLATE, MISSING_GROUP_PERMISSION
|
||||
from konova.views.base import BaseIndexView, BaseIdentifierGeneratorView
|
||||
|
||||
|
||||
class EmaIndexView(LoginRequiredMixin, BaseIndexView):
|
||||
@@ -96,23 +96,15 @@ def new_view(request: HttpRequest):
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
def new_id_view(request: HttpRequest):
|
||||
""" JSON endpoint
|
||||
class EmaIdentifierGeneratorView(LoginRequiredMixin, BaseIdentifierGeneratorView):
|
||||
_MODEL_CLS = Ema
|
||||
|
||||
Provides fetching of free identifiers for e.g. AJAX calls
|
||||
|
||||
"""
|
||||
tmp = Ema()
|
||||
identifier = tmp.generate_new_identifier()
|
||||
while Ema.objects.filter(identifier=identifier).exists():
|
||||
identifier = tmp.generate_new_identifier()
|
||||
return JsonResponse(
|
||||
data={
|
||||
"gen_data": identifier
|
||||
}
|
||||
)
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
is_ets = request.user.is_ets_user()
|
||||
if not is_ets:
|
||||
messages.info(request, MISSING_GROUP_PERMISSION)
|
||||
return redirect(reverse("ema:index"))
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user