Spaces:
Sleeping
Sleeping
Se establce switch para ingreso a sesion segun la tecnica usada en CatadorPanel
Browse files
tecnicas/controllers/views_controller/login_tester_controller.py
CHANGED
|
@@ -1,12 +1,17 @@
|
|
| 1 |
-
from
|
| 2 |
-
from
|
|
|
|
| 3 |
from django.db import transaction
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
class LoginTesterController():
|
| 7 |
tester: Catador
|
| 8 |
session: SesionSensorial
|
| 9 |
taster_participation: Participacion
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def __init__(self):
|
| 12 |
self.tester = Catador()
|
|
@@ -22,42 +27,73 @@ class LoginTesterController():
|
|
| 22 |
except (Catador.DoesNotExist, SesionSensorial.DoesNotExist):
|
| 23 |
return controller_error("Credenciales inválidas")
|
| 24 |
|
| 25 |
-
def
|
| 26 |
-
|
| 27 |
-
return controller_error("Credenciales no definidas")
|
| 28 |
-
|
| 29 |
if not self.session.activo:
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
if self.session.tecnica.repeticion > 1:
|
| 33 |
try:
|
| 34 |
self.taster_participation = Participacion.objects.get(
|
| 35 |
tecnica=self.session.tecnica, catador=self.tester)
|
| 36 |
-
|
|
|
|
| 37 |
except Participacion.DoesNotExist:
|
| 38 |
-
|
|
|
|
| 39 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
try:
|
| 41 |
self.taster_participation = Participacion.objects.get(
|
| 42 |
tecnica=self.session.tecnica, catador=self.tester)
|
| 43 |
-
|
|
|
|
| 44 |
except Participacion.DoesNotExist:
|
| 45 |
with transaction.atomic():
|
| 46 |
code_session = self.session.codigo_sesion
|
| 47 |
self.session = SesionSensorial.objects.select_for_update().get(
|
| 48 |
codigo_sesion=code_session)
|
| 49 |
|
| 50 |
-
max_testers = self.session.tecnica.limite_catadores
|
| 51 |
-
current_num_testers = Participacion.objects.filter(
|
| 52 |
-
tecnica=self.session.tecnica).count()
|
| 53 |
-
|
| 54 |
-
if current_num_testers >= max_testers:
|
| 55 |
-
return controller_error("La sesión ha alcanzado el número máximo de catadores")
|
| 56 |
-
|
| 57 |
self.taster_participation = Participacion.objects.create(
|
| 58 |
tecnica=self.session.tecnica,
|
| 59 |
catador=self.tester,
|
| 60 |
finalizado=False
|
| 61 |
)
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest, JsonResponse
|
| 2 |
+
from django.shortcuts import render, redirect
|
| 3 |
+
from django.urls import reverse
|
| 4 |
from django.db import transaction
|
| 5 |
+
from tecnicas.models import Catador, SesionSensorial, Participacion
|
| 6 |
+
from tecnicas.utils import controller_error
|
| 7 |
|
| 8 |
|
| 9 |
class LoginTesterController():
|
| 10 |
tester: Catador
|
| 11 |
session: SesionSensorial
|
| 12 |
taster_participation: Participacion
|
| 13 |
+
current_direcction = "tecnicas/forms_tester/login_session.html"
|
| 14 |
+
destinity_direcction = "cata_system:catador_init_session"
|
| 15 |
|
| 16 |
def __init__(self):
|
| 17 |
self.tester = Catador()
|
|
|
|
| 27 |
except (Catador.DoesNotExist, SesionSensorial.DoesNotExist):
|
| 28 |
return controller_error("Credenciales inválidas")
|
| 29 |
|
| 30 |
+
def validateEntryEscalas(self, request=HttpRequest):
|
| 31 |
+
context = {}
|
|
|
|
|
|
|
| 32 |
if not self.session.activo:
|
| 33 |
+
context["error"] = "La sesión no está activa actualmente"
|
| 34 |
+
return render(request, self.current_direcction, context)
|
| 35 |
|
| 36 |
if self.session.tecnica.repeticion > 1:
|
| 37 |
try:
|
| 38 |
self.taster_participation = Participacion.objects.get(
|
| 39 |
tecnica=self.session.tecnica, catador=self.tester)
|
| 40 |
+
context["error"] = "Usted ya esta dentro de la sesión"
|
| 41 |
+
return render(request, self.current_direcction, context)
|
| 42 |
except Participacion.DoesNotExist:
|
| 43 |
+
context["error"] = "No tienes permitido entrar a esta sesión"
|
| 44 |
+
return render(request, self.current_direcction, context)
|
| 45 |
else:
|
| 46 |
+
with transaction.atomic():
|
| 47 |
+
code_session = self.session.codigo_sesion
|
| 48 |
+
self.session = SesionSensorial.objects.select_for_update().get(
|
| 49 |
+
codigo_sesion=code_session)
|
| 50 |
+
|
| 51 |
+
max_testers = self.session.tecnica.limite_catadores
|
| 52 |
+
current_num_testers = Participacion.objects.filter(
|
| 53 |
+
tecnica=self.session.tecnica).count()
|
| 54 |
+
|
| 55 |
+
if current_num_testers >= max_testers:
|
| 56 |
+
context["error"] = "La sesión ha alcanzado el número máximo de catadores"
|
| 57 |
+
return render(request, self.current_direcction, context)
|
| 58 |
+
|
| 59 |
+
self.taster_participation = Participacion.objects.create(
|
| 60 |
+
tecnica=self.session.tecnica,
|
| 61 |
+
catador=self.tester,
|
| 62 |
+
finalizado=False
|
| 63 |
+
)
|
| 64 |
+
params = {
|
| 65 |
+
"code_sesion": self.session.codigo_sesion
|
| 66 |
+
}
|
| 67 |
+
return redirect(reverse(self.destinity_direcction, kwargs=params))
|
| 68 |
+
|
| 69 |
+
def validateEntryRATA(self, request: HttpRequest):
|
| 70 |
+
context = {}
|
| 71 |
+
if not self.session.activo:
|
| 72 |
+
context["error"] = "La sesión no está activa actualmente"
|
| 73 |
+
return render(request, self.current_direcction, context)
|
| 74 |
+
|
| 75 |
+
if self.session.tecnica.repeticion <= 1:
|
| 76 |
try:
|
| 77 |
self.taster_participation = Participacion.objects.get(
|
| 78 |
tecnica=self.session.tecnica, catador=self.tester)
|
| 79 |
+
context["error"] = "Usted ya esta dentro de la sesión"
|
| 80 |
+
return render(request, self.current_direcction, context)
|
| 81 |
except Participacion.DoesNotExist:
|
| 82 |
with transaction.atomic():
|
| 83 |
code_session = self.session.codigo_sesion
|
| 84 |
self.session = SesionSensorial.objects.select_for_update().get(
|
| 85 |
codigo_sesion=code_session)
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
self.taster_participation = Participacion.objects.create(
|
| 88 |
tecnica=self.session.tecnica,
|
| 89 |
catador=self.tester,
|
| 90 |
finalizado=False
|
| 91 |
)
|
| 92 |
|
| 93 |
+
params = {
|
| 94 |
+
"code_sesion": self.session.codigo_sesion
|
| 95 |
+
}
|
| 96 |
+
return redirect(reverse(self.destinity_direcction, kwargs=params))
|
| 97 |
+
else:
|
| 98 |
+
context["error"] = "Imposible acceder a esta sesión"
|
| 99 |
+
return render(request, self.current_direcction, context)
|
tecnicas/views/tester_forms/login_session.py
CHANGED
|
@@ -25,15 +25,19 @@ def loginSessionTester(req: HttpRequest):
|
|
| 25 |
tester = existCredentials[0]
|
| 26 |
session = existCredentials[1]
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
else:
|
| 39 |
return JsonResponse({"message": "Método no valido"})
|
|
|
|
| 25 |
tester = existCredentials[0]
|
| 26 |
session = existCredentials[1]
|
| 27 |
|
| 28 |
+
type_technique = session.tecnica.tipo_tecnica.nombre_tecnica
|
| 29 |
+
|
| 30 |
+
if type_technique == "escalas":
|
| 31 |
+
response = login_controller.validateEntryEscalas()
|
| 32 |
+
elif type_technique == "rata":
|
| 33 |
+
response = login_controller.validateEntryRATA()
|
| 34 |
+
else:
|
| 35 |
+
context = {
|
| 36 |
+
"error": "La técnica usada en esta sesión o ha sido implementada para ingresar a ella"
|
| 37 |
+
}
|
| 38 |
+
response = render(
|
| 39 |
+
req, "tecnicas/forms_tester/login_session.html", context)
|
| 40 |
+
|
| 41 |
+
return response
|
| 42 |
else:
|
| 43 |
return JsonResponse({"message": "Método no valido"})
|