Spaces:
Sleeping
Sleeping
Comprobraciones para que el Catador inice la session
Browse files- tecnicas/controllers/main_tester_form_controller.py +47 -2
- tecnicas/controllers/sesion_controller.py +8 -0
- tecnicas/templates/tecnicas/forms_tester/convencional.html +24 -0
- tecnicas/templates/tecnicas/forms_tester/main_tester.html +17 -0
- tecnicas/urls.py +4 -0
- tecnicas/views/__init__.py +1 -0
- tecnicas/views/login_tester.py +1 -0
- tecnicas/views/tester_forms/convencional_scales.py +17 -0
- tecnicas/views/tester_forms/main_tester_form.py +28 -13
tecnicas/controllers/main_tester_form_controller.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from ..models import Catador, SesionSensorial, Orden
|
| 2 |
from ..utils import controller_error, shuffleArray
|
| 3 |
from django.db import transaction
|
| 4 |
|
|
@@ -35,7 +35,7 @@ class MainTesterFormController():
|
|
| 35 |
def checkAssignOrder(self):
|
| 36 |
if not self.tester or not self.session:
|
| 37 |
return controller_error("Atributos no establecidos")
|
| 38 |
-
|
| 39 |
try:
|
| 40 |
res_order = Orden.objects.get(
|
| 41 |
id_tecnica=self.session.tecnica, id_catador=self.tester)
|
|
@@ -43,3 +43,48 @@ class MainTesterFormController():
|
|
| 43 |
return self.order
|
| 44 |
except Orden.DoesNotExist:
|
| 45 |
return controller_error("Catador sin orden")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..models import Catador, SesionSensorial, Orden, Participacion, Producto, EsAtributo, Calificacion, Vocabulario, EsVocabulario
|
| 2 |
from ..utils import controller_error, shuffleArray
|
| 3 |
from django.db import transaction
|
| 4 |
|
|
|
|
| 35 |
def checkAssignOrder(self):
|
| 36 |
if not self.tester or not self.session:
|
| 37 |
return controller_error("Atributos no establecidos")
|
| 38 |
+
|
| 39 |
try:
|
| 40 |
res_order = Orden.objects.get(
|
| 41 |
id_tecnica=self.session.tecnica, id_catador=self.tester)
|
|
|
|
| 43 |
return self.order
|
| 44 |
except Orden.DoesNotExist:
|
| 45 |
return controller_error("Catador sin orden")
|
| 46 |
+
|
| 47 |
+
def endedToFalseAndActiveTester(self, id_participation: int):
|
| 48 |
+
try:
|
| 49 |
+
self.participation = Participacion.objects.get(id=id_participation)
|
| 50 |
+
self.participation.finalizado = False
|
| 51 |
+
self.participation.activo = True
|
| 52 |
+
self.participation.save()
|
| 53 |
+
return self.participation
|
| 54 |
+
except Participacion.DoesNotExist:
|
| 55 |
+
return controller_error("No se ha encontrado la participación")
|
| 56 |
+
|
| 57 |
+
def isEndedSession(self, id_participation: int):
|
| 58 |
+
if not self.order or not id_participation:
|
| 59 |
+
return controller_error("Se requieren datos para comprobar la finalización")
|
| 60 |
+
|
| 61 |
+
try:
|
| 62 |
+
self.participation = Participacion.objects.get(id=id_participation)
|
| 63 |
+
|
| 64 |
+
if self.participation.finalizado:
|
| 65 |
+
num_products = Producto.objects.filter(
|
| 66 |
+
id_tecnica=self.session.tecnica).count()
|
| 67 |
+
|
| 68 |
+
style_words = self.session.tecnica.id_estilo
|
| 69 |
+
|
| 70 |
+
num_words: int
|
| 71 |
+
|
| 72 |
+
if style_words.nombre_estilo == "atributos":
|
| 73 |
+
e_atribues = EsAtributo.objects.get(
|
| 74 |
+
id_tecnica=self.session.tecnica)
|
| 75 |
+
num_words = e_atribues.palabras.count()
|
| 76 |
+
elif style_words.nombre_estilo == "vocabulario":
|
| 77 |
+
e_vocabulary = EsVocabulario.objects.get(
|
| 78 |
+
id_tecnica=self.session.tecnica)
|
| 79 |
+
num_words = e_vocabulary.id_vocabulario.palabras.count()
|
| 80 |
+
|
| 81 |
+
num_ratings_now = Calificacion.objects.filter(
|
| 82 |
+
id_tecnica=self.session.tecnica, id_catador=self.tester).count()
|
| 83 |
+
|
| 84 |
+
num_ratings_max_by_tester = num_products * num_words
|
| 85 |
+
|
| 86 |
+
return not num_ratings_now <= num_ratings_max_by_tester
|
| 87 |
+
else:
|
| 88 |
+
return self.participation.finalizado
|
| 89 |
+
except Participacion.DoesNotExist:
|
| 90 |
+
return controller_error("No se ha encontrado la participación")
|
tecnicas/controllers/sesion_controller.py
CHANGED
|
@@ -91,6 +91,14 @@ class SesionController():
|
|
| 91 |
return session
|
| 92 |
except SesionSensorial.DoesNotExist:
|
| 93 |
return controller_error("La sesión ya no existe")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
@staticmethod
|
| 96 |
def getNumberSessionsByCreator(user_name: str):
|
|
|
|
| 91 |
return session
|
| 92 |
except SesionSensorial.DoesNotExist:
|
| 93 |
return controller_error("La sesión ya no existe")
|
| 94 |
+
|
| 95 |
+
@staticmethod
|
| 96 |
+
def getSessionByCode(code: str):
|
| 97 |
+
try:
|
| 98 |
+
session = SesionSensorial.objects.get(codigo_sesion=code)
|
| 99 |
+
return session
|
| 100 |
+
except SesionSensorial.DoesNotExist:
|
| 101 |
+
return controller_error("La sesión ya no existe")
|
| 102 |
|
| 103 |
@staticmethod
|
| 104 |
def getNumberSessionsByCreator(user_name: str):
|
tecnicas/templates/tecnicas/forms_tester/convencional.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends 'tecnicas/layouts/base.html' %}
|
| 2 |
+
|
| 3 |
+
{% block title %}Convencional{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<article class="w-full flex flex-col justify-center items-center bg-gray-600 mt-10 mb-10">
|
| 7 |
+
<article class="flex flex-col gap-8 bg-gray-400 p-10 rounded">
|
| 8 |
+
<header class="text-center flex-row w-full flex justify-around items-center flex-wrap gap-10">
|
| 9 |
+
<h1 class="text-white rounded font-bold text-2xl bg-gray-600 p-4 flex-1">
|
| 10 |
+
Sesión usando técnica Convencional
|
| 11 |
+
</h1>
|
| 12 |
+
</header>
|
| 13 |
+
|
| 14 |
+
<article>
|
| 15 |
+
<p class="text-lg font-medium text-center bg-gray-200 p-4 rounded">
|
| 16 |
+
{{ session.tecnica.instrucciones }}
|
| 17 |
+
</p>
|
| 18 |
+
</article>
|
| 19 |
+
</article>
|
| 20 |
+
</article>
|
| 21 |
+
{% endblock %}
|
| 22 |
+
|
| 23 |
+
{% block extra_js %}
|
| 24 |
+
{% endblock %}
|
tecnicas/templates/tecnicas/forms_tester/main_tester.html
CHANGED
|
@@ -28,6 +28,16 @@
|
|
| 28 |
</article>
|
| 29 |
{% endif %}
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
<hr>
|
| 32 |
|
| 33 |
<article
|
|
@@ -88,6 +98,12 @@
|
|
| 88 |
<hr>
|
| 89 |
|
| 90 |
<article class="flex flex-wrap gap-10">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
<button
|
| 92 |
class="ct-btn-start-repition flex-1 uppercase text-lg tracking-wider p-4 border-b-2 active:border-b-0 active:border-t-2 active:border-green-500 border-green-800 transition-all rounded-xl bg-green-600 text-white font-bold disabled:bg-amber-600 flex flex-col justify-center items-center gap-2"
|
| 93 |
onclick="startTest()">
|
|
@@ -96,6 +112,7 @@
|
|
| 96 |
<img src="{% static 'img/check.svg' %}" alt="flechas girando" class="invert">
|
| 97 |
</figure>
|
| 98 |
</button>
|
|
|
|
| 99 |
<button
|
| 100 |
class="flex-1 uppercase text-lg tracking-wider p-4 border-b-2 active:border-b-0 active:border-t-2 active:border-red-500 border-red-800 transition-all rounded-xl bg-red-600 text-white font-bold disabled:bg-amber-600 flex flex-col justify-center items-center gap-2">
|
| 101 |
Salir se la sesión
|
|
|
|
| 28 |
</article>
|
| 29 |
{% endif %}
|
| 30 |
|
| 31 |
+
{% if message %}
|
| 32 |
+
<hr>
|
| 33 |
+
|
| 34 |
+
<article class="bg-blue-600 p-4 text-white rounded-xl ct-notification-error">
|
| 35 |
+
<p class="block font-sans text-white text-xl antialiased font-bold uppercase tracking-wider text-center">
|
| 36 |
+
{{ message }}
|
| 37 |
+
</p>
|
| 38 |
+
</article>
|
| 39 |
+
{% endif %}
|
| 40 |
+
|
| 41 |
<hr>
|
| 42 |
|
| 43 |
<article
|
|
|
|
| 98 |
<hr>
|
| 99 |
|
| 100 |
<article class="flex flex-wrap gap-10">
|
| 101 |
+
{% if has_ended %}
|
| 102 |
+
<button
|
| 103 |
+
class="ct-btn-start-repition flex-1 uppercase text-lg tracking-wider p-4 border-b-2 active:border-b-0 active:border-t-2 active:border-green-500 border-green-800 transition-all rounded-xl bg-green-600 text-white font-bold disabled:bg-amber-600 flex flex-col justify-center items-center gap-2" disabled>
|
| 104 |
+
Finalizaste la sesión
|
| 105 |
+
</button>
|
| 106 |
+
{% else %}
|
| 107 |
<button
|
| 108 |
class="ct-btn-start-repition flex-1 uppercase text-lg tracking-wider p-4 border-b-2 active:border-b-0 active:border-t-2 active:border-green-500 border-green-800 transition-all rounded-xl bg-green-600 text-white font-bold disabled:bg-amber-600 flex flex-col justify-center items-center gap-2"
|
| 109 |
onclick="startTest()">
|
|
|
|
| 112 |
<img src="{% static 'img/check.svg' %}" alt="flechas girando" class="invert">
|
| 113 |
</figure>
|
| 114 |
</button>
|
| 115 |
+
{% endif %}
|
| 116 |
<button
|
| 117 |
class="flex-1 uppercase text-lg tracking-wider p-4 border-b-2 active:border-b-0 active:border-t-2 active:border-red-500 border-red-800 transition-all rounded-xl bg-red-600 text-white font-bold disabled:bg-amber-600 flex flex-col justify-center items-center gap-2">
|
| 118 |
Salir se la sesión
|
tecnicas/urls.py
CHANGED
|
@@ -72,6 +72,10 @@ urlpatterns = [
|
|
| 72 |
views.mainTesterForm,
|
| 73 |
name="catador_main"),
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
# APIs
|
| 76 |
path("nueva-etiqueta",
|
| 77 |
views.newTag,
|
|
|
|
| 72 |
views.mainTesterForm,
|
| 73 |
name="catador_main"),
|
| 74 |
|
| 75 |
+
path("testers/en-session/convencional",
|
| 76 |
+
views.convencionalScales,
|
| 77 |
+
name="session_convencional"),
|
| 78 |
+
|
| 79 |
# APIs
|
| 80 |
path("nueva-etiqueta",
|
| 81 |
views.newTag,
|
tecnicas/views/__init__.py
CHANGED
|
@@ -20,3 +20,4 @@ from .apis.api_tag import newTag
|
|
| 20 |
from .apis.api_words import words
|
| 21 |
|
| 22 |
from .tester_forms.main_tester_form import mainTesterForm
|
|
|
|
|
|
| 20 |
from .apis.api_words import words
|
| 21 |
|
| 22 |
from .tester_forms.main_tester_form import mainTesterForm
|
| 23 |
+
from .tester_forms.convencional_scales import convencionalScales
|
tecnicas/views/login_tester.py
CHANGED
|
@@ -29,6 +29,7 @@ def testerLogin(req: HttpRequest):
|
|
| 29 |
|
| 30 |
req.session["cata_username"] = tester_user
|
| 31 |
req.session["code_session"] = session_code
|
|
|
|
| 32 |
|
| 33 |
req.session.set_expiry(20*60)
|
| 34 |
return redirect(reverse("cata_system:catador_main"))
|
|
|
|
| 29 |
|
| 30 |
req.session["cata_username"] = tester_user
|
| 31 |
req.session["code_session"] = session_code
|
| 32 |
+
req.session["id_participation"] = taster_participation.id
|
| 33 |
|
| 34 |
req.session.set_expiry(20*60)
|
| 35 |
return redirect(reverse("cata_system:catador_main"))
|
tecnicas/views/tester_forms/convencional_scales.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest, JsonResponse
|
| 2 |
+
from django.shortcuts import redirect, render
|
| 3 |
+
from django.urls import reverse
|
| 4 |
+
from ...controllers import SesionController
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def convencionalScales(req: HttpRequest):
|
| 8 |
+
if not "id_order" in req.session:
|
| 9 |
+
return redirect(reverse("cata_system:panel_configuracion_words"))
|
| 10 |
+
|
| 11 |
+
session = SesionController.getSessionByCode(req.session["code_session"])
|
| 12 |
+
|
| 13 |
+
context = {
|
| 14 |
+
"session": session
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
return render(req, "tecnicas/forms_tester/convencional.html", context)
|
tecnicas/views/tester_forms/main_tester_form.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from django.http import HttpRequest, JsonResponse
|
| 2 |
-
from django.shortcuts import render
|
|
|
|
| 3 |
from ...controllers import SesionController, MainTesterFormController
|
| 4 |
-
from ...models import Orden
|
| 5 |
|
| 6 |
|
| 7 |
def mainTesterForm(req: HttpRequest):
|
|
@@ -12,28 +12,43 @@ def mainTesterForm(req: HttpRequest):
|
|
| 12 |
"session": session
|
| 13 |
}
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
if req.method == "GET":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
| 17 |
elif req.method == "POST":
|
| 18 |
if req.POST["action"] == "start_posting":
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
| 27 |
|
| 28 |
order = view_controller.assignOrder()
|
| 29 |
if isinstance(order, dict):
|
| 30 |
context["error"] = order["error"]
|
| 31 |
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
| 35 |
elif req.POST["action"] == "close_session":
|
| 36 |
-
|
|
|
|
| 37 |
else:
|
| 38 |
context["error"] = "Acción sin especificar"
|
| 39 |
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
|
|
|
| 1 |
from django.http import HttpRequest, JsonResponse
|
| 2 |
+
from django.shortcuts import render, redirect
|
| 3 |
+
from django.urls import reverse
|
| 4 |
from ...controllers import SesionController, MainTesterFormController
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def mainTesterForm(req: HttpRequest):
|
|
|
|
| 12 |
"session": session
|
| 13 |
}
|
| 14 |
|
| 15 |
+
view_controller = MainTesterFormController(
|
| 16 |
+
req.session["code_session"], req.session["cata_username"])
|
| 17 |
+
|
| 18 |
if req.method == "GET":
|
| 19 |
+
order = view_controller.checkAssignOrder()
|
| 20 |
+
|
| 21 |
+
if not isinstance(order, dict):
|
| 22 |
+
req.session["id_order"] = order.id
|
| 23 |
+
if view_controller.isEndedSession(req.session["id_participation"]):
|
| 24 |
+
context["message"] = "El catador ha terminado de realizar su evaluación, espere instrucciones del presentador"
|
| 25 |
+
context["has_ended"] = True
|
| 26 |
+
|
| 27 |
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
| 28 |
elif req.method == "POST":
|
| 29 |
if req.POST["action"] == "start_posting":
|
| 30 |
+
if "id_order" in req.session:
|
| 31 |
+
update_participation = view_controller.endedToFalseAndActiveTester(req.session["id_participation"])
|
| 32 |
+
if isinstance(update_participation, dict):
|
| 33 |
+
context["error"] = update_participation["error"]
|
| 34 |
+
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
| 35 |
+
|
| 36 |
+
return redirect(reverse("cata_system:session_convencional"))
|
|
|
|
| 37 |
|
| 38 |
order = view_controller.assignOrder()
|
| 39 |
if isinstance(order, dict):
|
| 40 |
context["error"] = order["error"]
|
| 41 |
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
| 42 |
+
|
| 43 |
+
update_participation = view_controller.endedToFalseAndActiveTester(req.session["id_participation"])
|
| 44 |
+
if isinstance(update_participation, dict):
|
| 45 |
+
context["error"] = update_participation["error"]
|
| 46 |
+
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|
| 47 |
|
| 48 |
+
return redirect(reverse("cata_system:session_convencional"))
|
|
|
|
| 49 |
elif req.POST["action"] == "close_session":
|
| 50 |
+
req.session.flush()
|
| 51 |
+
return redirect(reverse("cata_system:catador_login"))
|
| 52 |
else:
|
| 53 |
context["error"] = "Acción sin especificar"
|
| 54 |
return render(req, "tecnicas/forms_tester/main_tester.html", context)
|