Spaces:
Sleeping
Sleeping
Cambios ligeros de nombre
Browse files- tecnicas/controllers/views_controller/session_management/details/details_napping_controller.py +39 -1
- tecnicas/controllers/views_controller/sessions_tester/login_session_tester_controller.py +49 -33
- tecnicas/templates/tecnicas/components/table-napping-no-mode.html +41 -0
- tecnicas/templates/tecnicas/forms_tester/test_napping.html +1 -1
- tecnicas/templates/tecnicas/manage_sesions/details-session-napping.html +6 -1
- tecnicas/views/tester_forms/login_session.py +4 -1
tecnicas/controllers/views_controller/session_management/details/details_napping_controller.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
from django.shortcuts import redirect
|
| 3 |
from django.urls import reverse
|
|
|
|
| 4 |
from .details_controller import DetallesController
|
| 5 |
-
from tecnicas.models import SesionSensorial, Presentador, Modalidad, TecnicaModalidad
|
|
|
|
| 6 |
from collections import defaultdict
|
| 7 |
|
| 8 |
|
|
@@ -31,6 +33,8 @@ class DetallesNappingController(DetallesController):
|
|
| 31 |
self.context["modes"] = modes.exclude(
|
| 32 |
id__in=use_modes)
|
| 33 |
|
|
|
|
|
|
|
| 34 |
return self.context
|
| 35 |
|
| 36 |
def defineStatus(self):
|
|
@@ -81,3 +85,37 @@ class DetallesNappingController(DetallesController):
|
|
| 81 |
}
|
| 82 |
return redirect(
|
| 83 |
reverse(self.url_next, kwargs=parameters))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
from django.shortcuts import redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
+
from django.db.models import F
|
| 5 |
from .details_controller import DetallesController
|
| 6 |
+
from tecnicas.models import SesionSensorial, Presentador, Modalidad, TecnicaModalidad, Catador, Participacion, DatoPunto, Calificacion
|
| 7 |
+
from tecnicas.utils import defaultdict_to_dict
|
| 8 |
from collections import defaultdict
|
| 9 |
|
| 10 |
|
|
|
|
| 33 |
self.context["modes"] = modes.exclude(
|
| 34 |
id__in=use_modes)
|
| 35 |
|
| 36 |
+
self.setDataTableNoMode()
|
| 37 |
+
|
| 38 |
return self.context
|
| 39 |
|
| 40 |
def defineStatus(self):
|
|
|
|
| 85 |
}
|
| 86 |
return redirect(
|
| 87 |
reverse(self.url_next, kwargs=parameters))
|
| 88 |
+
|
| 89 |
+
def setDataTableNoMode(self):
|
| 90 |
+
participations = Participacion.objects.filter(
|
| 91 |
+
tecnica=self.session.tecnica).select_related("catador")
|
| 92 |
+
testers = [participation.catador for participation in participations]
|
| 93 |
+
self.context["testers"] = testers
|
| 94 |
+
|
| 95 |
+
ratings = Calificacion.objects.filter(id_tecnica=self.session.tecnica)
|
| 96 |
+
|
| 97 |
+
coordinates = (
|
| 98 |
+
DatoPunto.objects.filter(calificacion__in=ratings)
|
| 99 |
+
.values(
|
| 100 |
+
producto=F("calificacion__id_producto__codigoProducto"),
|
| 101 |
+
catador=F("calificacion__id_catador__user__username"),
|
| 102 |
+
px=F("x"),
|
| 103 |
+
py=F("y"),
|
| 104 |
+
))
|
| 105 |
+
|
| 106 |
+
if not coordinates.exists():
|
| 107 |
+
self.context["there_data"] = False
|
| 108 |
+
return []
|
| 109 |
+
|
| 110 |
+
coordinates_by_product = defaultdict(dict)
|
| 111 |
+
|
| 112 |
+
for coordinate in coordinates:
|
| 113 |
+
coordinates_by_product[coordinate["producto"]][coordinate["catador"]] = {
|
| 114 |
+
"px": coordinate["px"],
|
| 115 |
+
"py": coordinate["py"],
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
self.context["coordinates_no_mode"] = defaultdict_to_dict(
|
| 119 |
+
coordinates_by_product)
|
| 120 |
+
|
| 121 |
+
self.context["there_data"] = True
|
tecnicas/controllers/views_controller/sessions_tester/login_session_tester_controller.py
CHANGED
|
@@ -106,41 +106,57 @@ class LoginSessionTesterController():
|
|
| 106 |
return render(request, self.current_direcction, context)
|
| 107 |
|
| 108 |
if self.session.tecnica.repeticion == 1:
|
| 109 |
-
|
| 110 |
-
self.taster_participation = Participacion.objects.get(
|
| 111 |
-
tecnica=self.session.tecnica, catador=self.tester)
|
| 112 |
-
context["error"] = "Usted ya esta dentro de la sesión"
|
| 113 |
-
return render(request, self.current_direcction, context)
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
raise ValueError(
|
| 128 |
-
"La sesión ha alcanzado el número máximo de catadores")
|
| 129 |
-
|
| 130 |
-
self.taster_participation = Participacion.objects.create(
|
| 131 |
-
tecnica=self.session.tecnica,
|
| 132 |
-
catador=self.tester,
|
| 133 |
-
finalizado=False
|
| 134 |
-
)
|
| 135 |
-
params = {
|
| 136 |
-
"code_sesion": self.session.codigo_sesion
|
| 137 |
-
}
|
| 138 |
-
return redirect(reverse(self.destinity_direcction, kwargs=params))
|
| 139 |
-
|
| 140 |
-
except ValueError as e:
|
| 141 |
-
context["error"] = str(e)
|
| 142 |
-
return render(request, self.current_direcction, context)
|
| 143 |
|
| 144 |
else:
|
| 145 |
context["error"] = "Ya no es posible ingresar a la sesión"
|
| 146 |
return render(request, self.current_direcction, context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
return render(request, self.current_direcction, context)
|
| 107 |
|
| 108 |
if self.session.tecnica.repeticion == 1:
|
| 109 |
+
return self.entrySessionLimitTesters(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
else:
|
| 112 |
+
context["error"] = "Ya no es posible ingresar a la sesión"
|
| 113 |
+
return render(request, self.current_direcction, context)
|
| 114 |
+
|
| 115 |
+
def validateEntryNapping(self, request: HttpRequest):
|
| 116 |
+
context = {}
|
| 117 |
+
if not self.session.activo:
|
| 118 |
+
context["error"] = "La sesión no está activa actualmente"
|
| 119 |
+
return render(request, self.current_direcction, context)
|
| 120 |
+
|
| 121 |
+
if self.session.tecnica.repeticion == 0:
|
| 122 |
+
return self.entrySessionLimitTesters(request)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
else:
|
| 125 |
context["error"] = "Ya no es posible ingresar a la sesión"
|
| 126 |
return render(request, self.current_direcction, context)
|
| 127 |
+
|
| 128 |
+
def entrySessionLimitTesters(self, request: HttpRequest):
|
| 129 |
+
try:
|
| 130 |
+
self.taster_participation = Participacion.objects.get(
|
| 131 |
+
tecnica=self.session.tecnica, catador=self.tester)
|
| 132 |
+
context["error"] = "Usted ya esta dentro de la sesión"
|
| 133 |
+
return render(request, self.current_direcction, context)
|
| 134 |
+
|
| 135 |
+
except Participacion.DoesNotExist:
|
| 136 |
+
try:
|
| 137 |
+
with transaction.atomic():
|
| 138 |
+
code_session = self.session.codigo_sesion
|
| 139 |
+
self.session = SesionSensorial.objects.select_for_update().get(
|
| 140 |
+
codigo_sesion=code_session)
|
| 141 |
+
|
| 142 |
+
max_testers = self.session.tecnica.limite_catadores
|
| 143 |
+
current_num_testers = Participacion.objects.filter(
|
| 144 |
+
tecnica=self.session.tecnica).count()
|
| 145 |
+
|
| 146 |
+
if current_num_testers >= max_testers:
|
| 147 |
+
raise ValueError(
|
| 148 |
+
"La sesión ha alcanzado el número máximo de catadores")
|
| 149 |
+
|
| 150 |
+
self.taster_participation = Participacion.objects.create(
|
| 151 |
+
tecnica=self.session.tecnica,
|
| 152 |
+
catador=self.tester,
|
| 153 |
+
finalizado=False
|
| 154 |
+
)
|
| 155 |
+
params = {
|
| 156 |
+
"code_sesion": self.session.codigo_sesion
|
| 157 |
+
}
|
| 158 |
+
return redirect(reverse(self.destinity_direcction, kwargs=params))
|
| 159 |
+
|
| 160 |
+
except ValueError as e:
|
| 161 |
+
context["error"] = str(e)
|
| 162 |
+
return render(request, self.current_direcction, context)
|
tecnicas/templates/tecnicas/components/table-napping-no-mode.html
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% load custom_filters %}
|
| 2 |
+
<article class="space-y-4 text-black">
|
| 3 |
+
<h2 class="font-bold text-xl text-center">
|
| 4 |
+
Datos de Napping sin modalidad
|
| 5 |
+
</h2>
|
| 6 |
+
|
| 7 |
+
<div class="overflow-x-auto rounded-lg border border-surface-general">
|
| 8 |
+
<table id="generic-donwload-table" class="min-w-max w-full text-sm text-center border-collapse">
|
| 9 |
+
<thead class="bg-surface-sweet font-semibold">
|
| 10 |
+
<tr>
|
| 11 |
+
<th class="py-2 px-3 border border-surface-general">Producto</th>
|
| 12 |
+
{% for tester in testers %}
|
| 13 |
+
<th class="py-2 px-3 border border-surface-general uppercase">
|
| 14 |
+
X{{ forloop.counter }}
|
| 15 |
+
</th>
|
| 16 |
+
<th class="py-2 px-3 border border-surface-general uppercase">
|
| 17 |
+
Y{{ forloop.counter }}
|
| 18 |
+
</th>
|
| 19 |
+
{% endfor %}
|
| 20 |
+
</tr>
|
| 21 |
+
</thead>
|
| 22 |
+
<tbody class="bg-surface-ligt divide-y divide-gray-200">
|
| 23 |
+
{% for product, coordinates_tester in coordinates_no_mode.items %}
|
| 24 |
+
<tr>
|
| 25 |
+
<td class="py-2 px-3 border border-surface-general">{{ product }}</td>
|
| 26 |
+
{% for tester in testers %}
|
| 27 |
+
{% with points=coordinates_tester|get_item:tester.user.username %}
|
| 28 |
+
<td class="py-2 px-3 border border-surface-general">
|
| 29 |
+
{{ points.px }}
|
| 30 |
+
</td>
|
| 31 |
+
<td class="py-2 px-3 border border-surface-general">
|
| 32 |
+
{{ points.py }}
|
| 33 |
+
</td>
|
| 34 |
+
{% endwith %}
|
| 35 |
+
{% endfor %}
|
| 36 |
+
</tr>
|
| 37 |
+
{% endfor %}
|
| 38 |
+
</tbody>
|
| 39 |
+
</table>
|
| 40 |
+
</div>
|
| 41 |
+
</article>
|
tecnicas/templates/tecnicas/forms_tester/test_napping.html
CHANGED
|
@@ -42,7 +42,7 @@
|
|
| 42 |
|
| 43 |
<section class="flex items-center justify-center flex-wrap gap-4 bg-surface-ligt p-2 rounded-lg">
|
| 44 |
<p class="text-xl font-bold text-center capitalize">
|
| 45 |
-
Modalidad: {{ mode }}
|
| 46 |
</p>
|
| 47 |
</section>
|
| 48 |
</article>
|
|
|
|
| 42 |
|
| 43 |
<section class="flex items-center justify-center flex-wrap gap-4 bg-surface-ligt p-2 rounded-lg">
|
| 44 |
<p class="text-xl font-bold text-center capitalize">
|
| 45 |
+
Modalidad: {% if mode != "sin modalidad" %}{{ mode }} {% else %} Nappging {% endif %}
|
| 46 |
</p>
|
| 47 |
</section>
|
| 48 |
</article>
|
tecnicas/templates/tecnicas/manage_sesions/details-session-napping.html
CHANGED
|
@@ -119,7 +119,7 @@
|
|
| 119 |
<button
|
| 120 |
class="cts-btn-general capitalize cts-btn-primary btn-push flex flex-col justify-center items-center gap-2"
|
| 121 |
data-mode="{{ mode.nombre }}" onclick="startSession('{{ mode.nombre }}')">
|
| 122 |
-
Napping {{ mode.nombre }}
|
| 123 |
<figure class="w-10">
|
| 124 |
<img src="{% static 'img/giro.svg' %}" alt="flechas girando" class="invert">
|
| 125 |
</figure>
|
|
@@ -177,7 +177,12 @@
|
|
| 177 |
Datos obtenidos
|
| 178 |
</p>
|
| 179 |
|
|
|
|
|
|
|
|
|
|
| 180 |
{% include "../components/error-message.html" with message='Sin datos por mostrar aún' %}
|
|
|
|
|
|
|
| 181 |
|
| 182 |
<form action="" method="post" class="form-action-session hidden">
|
| 183 |
<input type="hidden" name="action" class="action-option">
|
|
|
|
| 119 |
<button
|
| 120 |
class="cts-btn-general capitalize cts-btn-primary btn-push flex flex-col justify-center items-center gap-2"
|
| 121 |
data-mode="{{ mode.nombre }}" onclick="startSession('{{ mode.nombre }}')">
|
| 122 |
+
Napping {% if mode.nombre != "sin modalidad" %} {{ mode.nombre }} {% endif %}
|
| 123 |
<figure class="w-10">
|
| 124 |
<img src="{% static 'img/giro.svg' %}" alt="flechas girando" class="invert">
|
| 125 |
</figure>
|
|
|
|
| 177 |
Datos obtenidos
|
| 178 |
</p>
|
| 179 |
|
| 180 |
+
{% if there_data %}
|
| 181 |
+
{% include "../components/table-napping-no-mode.html" with testers=testers coordinates_no_mode=coordinates_no_mode %}
|
| 182 |
+
{% else %}
|
| 183 |
{% include "../components/error-message.html" with message='Sin datos por mostrar aún' %}
|
| 184 |
+
{% endif %}
|
| 185 |
+
|
| 186 |
|
| 187 |
<form action="" method="post" class="form-action-session hidden">
|
| 188 |
<input type="hidden" name="action" class="action-option">
|
tecnicas/views/tester_forms/login_session.py
CHANGED
|
@@ -27,12 +27,15 @@ def loginSessionTester(req: HttpRequest):
|
|
| 27 |
|
| 28 |
type_technique = session.tecnica.tipo_tecnica.nombre_tecnica
|
| 29 |
|
| 30 |
-
if type_technique in ["escalas", "perfil flash", "sort"
|
| 31 |
response = login_controller.validateEntryLimitTesters(request=req)
|
| 32 |
|
| 33 |
elif type_technique in ["rata", "cata"]:
|
| 34 |
response = login_controller.validateEntryRataCata(request=req)
|
| 35 |
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
| 37 |
context = {
|
| 38 |
"error": "La técnica usada en esta sesión es invalida o no ha sido implementada para ingresar a ella"
|
|
|
|
| 27 |
|
| 28 |
type_technique = session.tecnica.tipo_tecnica.nombre_tecnica
|
| 29 |
|
| 30 |
+
if type_technique in ["escalas", "perfil flash", "sort"]:
|
| 31 |
response = login_controller.validateEntryLimitTesters(request=req)
|
| 32 |
|
| 33 |
elif type_technique in ["rata", "cata"]:
|
| 34 |
response = login_controller.validateEntryRataCata(request=req)
|
| 35 |
|
| 36 |
+
elif type_technique == "napping":
|
| 37 |
+
response = login_controller.validateEntryNapping(request=req)
|
| 38 |
+
|
| 39 |
else:
|
| 40 |
context = {
|
| 41 |
"error": "La técnica usada en esta sesión es invalida o no ha sido implementada para ingresar a ella"
|