# Identifier Generator View
* refactors identifier generator view methods into classes * introduces IdentifierGenerator * introduces AbstractIdentifierGeneratorView
This commit is contained in:
32
konova/views/identifier.py
Normal file
32
konova/views/identifier.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""
|
||||
Author: Michel Peltriaux
|
||||
Created on: 14.12.25
|
||||
|
||||
"""
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.http import HttpRequest, JsonResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
||||
from konova.decorators import default_group_required
|
||||
from konova.utils.generators import IdentifierGenerator
|
||||
|
||||
|
||||
class AbstractIdentifierGeneratorView(LoginRequiredMixin, View):
|
||||
_MODEL = None
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
@method_decorator(default_group_required)
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def get(self, request: HttpRequest, *args, **kwargs):
|
||||
generator = IdentifierGenerator(model=self._MODEL)
|
||||
identifier = generator.generate_id()
|
||||
return JsonResponse(
|
||||
data={
|
||||
"gen_data": identifier
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user