chartManD commited on
Commit
965ace8
·
1 Parent(s): 32ee7e4

Se establece el panel principal de Catadores

Browse files
tecnicas/controllers/views_controller/main_panel_tester_controller.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.core.paginator import Paginator, PageNotAnInteger
2
+ from django.db.models import OuterRef, Subquery, BooleanField
3
+ from tecnicas.models import Catador, SesionSensorial, Participacion
4
+ from tecnicas.utils import controller_error
5
+
6
+
7
+ class MainPanelTesterController():
8
+ def __init__(self):
9
+ pass
10
+
11
+ @staticmethod
12
+ def getSessionByTester(page: int, tester: Catador):
13
+ elements_by_page = 6
14
+
15
+ base_qs = SesionSensorial.objects.filter(
16
+ tecnica__tecnica_participacion__catador=tester
17
+ )
18
+
19
+ participacion_finalizado_subq = Subquery(
20
+ Participacion.objects.filter(
21
+ tecnica=OuterRef('tecnica_id'),
22
+ catador=tester
23
+ ).values('finalizado')[:1],
24
+ output_field=BooleanField()
25
+ )
26
+
27
+ participacion_activo_subq = Subquery(
28
+ Participacion.objects.filter(
29
+ tecnica=OuterRef('tecnica_id'),
30
+ catador=tester
31
+ ).values('activo')[:1],
32
+ output_field=BooleanField()
33
+ )
34
+
35
+ queryset = (
36
+ base_qs
37
+ .select_related(
38
+ 'tecnica',
39
+ 'tecnica__tipo_tecnica',
40
+ 'tecnica__id_estilo',
41
+ )
42
+ .annotate(
43
+ participacion_finalizado=participacion_finalizado_subq,
44
+ participacion_activo=participacion_activo_subq,
45
+ )
46
+ .order_by('activo', '-fechaCreacion')
47
+ .distinct()
48
+ )
49
+
50
+ paginator = Paginator(queryset, elements_by_page)
51
+ try:
52
+ testers_in_page = paginator.page(page)
53
+ except PageNotAnInteger:
54
+ return controller_error("índice inválido")
55
+
56
+ if not testers_in_page.object_list:
57
+ return controller_error("Sin registros de Catadores")
58
+
59
+ is_last_page = not testers_in_page.number < paginator.num_pages
60
+
61
+ return (testers_in_page, is_last_page)
tecnicas/templates/tecnicas/auth.html CHANGED
@@ -26,7 +26,7 @@
26
  </label>
27
 
28
  <label for="password">
29
- <input type="text" name="password" id="password" placeholder="Ingrese Contraseña"
30
  class="placeholder:text-gray-400 placeholder:font-semibold text-xl max-sm:text-base bg-surface-ligt py-3 px-6 rounded-xl lg:w-sm border-b-2 border-surface-sweet"
31
  required>
32
  </label>
 
26
  </label>
27
 
28
  <label for="password">
29
+ <input type="password" name="password" id="password" placeholder="Ingrese Contraseña"
30
  class="placeholder:text-gray-400 placeholder:font-semibold text-xl max-sm:text-base bg-surface-ligt py-3 px-6 rounded-xl lg:w-sm border-b-2 border-surface-sweet"
31
  required>
32
  </label>
tecnicas/templates/tecnicas/cata-login.html CHANGED
@@ -13,23 +13,15 @@
13
  </header>
14
 
15
  {% if error %}
16
- <article class="bg-ct-error p-4 text-white rounded-xl ct-notification-error">
17
- <p
18
- class="block font-sans text-white text-xl antialiased font-bold uppercase tracking-wider text-center">
19
- {{ error }}
20
- </p>
21
- </article>
22
  {% endif %}
23
 
24
  <article class="flex flex-col gap-6 items-center w-full mt-5">
25
- <label for="id">
26
- <input type="text" name="code_session" id="id" placeholder="Codigo de sesion"
27
- class="placeholder:text-gray-400 placeholder:font-semibold text-xl max-sm:text-base bg-surface-ligt py-3 px-6 rounded-xl lg:w-sm border-b-2 border-surface-sweet"
28
- required>
29
- </label>
30
-
31
- <label for="id">
32
- <input type="text" name="user_tester" id="id" placeholder="Nombre de usuario"
33
  class="placeholder:text-gray-400 placeholder:font-semibold text-xl max-sm:text-base bg-surface-ligt py-3 px-6 rounded-xl lg:w-sm border-b-2 border-surface-sweet"
34
  required>
35
  </label>
@@ -44,15 +36,4 @@
44
  </form>
45
  </article>
46
  </article>
47
- {% endblock %}
48
-
49
- {% block extra_js %}
50
- <script>
51
- const error = document.querySelector(".ct-notification-error")
52
- if (error) {
53
- setTimeout(() => {
54
- error.classList.add("hidden")
55
- }, 4000)
56
- }
57
- </script>
58
  {% endblock %}
 
13
  </header>
14
 
15
  {% if error %}
16
+ {% include "./components/error-message.html" with message=error %}
17
+ {% endif %}
18
+ {% if message %}
19
+ {% include "./components/error-message.html" with message=message %}
 
 
20
  {% endif %}
21
 
22
  <article class="flex flex-col gap-6 items-center w-full mt-5">
23
+ <label for="tester">
24
+ <input type="text" name="user_tester" id="tester" placeholder="Nombre de usuario"
 
 
 
 
 
 
25
  class="placeholder:text-gray-400 placeholder:font-semibold text-xl max-sm:text-base bg-surface-ligt py-3 px-6 rounded-xl lg:w-sm border-b-2 border-surface-sweet"
26
  required>
27
  </label>
 
36
  </form>
37
  </article>
38
  </article>
 
 
 
 
 
 
 
 
 
 
 
39
  {% endblock %}
tecnicas/templates/tecnicas/forms_tester/main_panel_tester.html ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'tecnicas/layouts/base.html' %}
2
+
3
+ {% block title %}Detalles Sesion{% endblock %}
4
+
5
+ {% block content %}
6
+ <article class="cts-container-main">
7
+ <article class="cts-wrap-content text-black">
8
+ <div class="container mx-auto max-w-2xl p-4 space-y-6">
9
+ <div class="card bg-surface-card shadow-lg">
10
+ <div class="card-body">
11
+ <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
12
+ <h2 class="card-title text-2xl font-semibold">Información del Usuario</h2>
13
+
14
+ <button class="cts-btn-general-compress px-4 py-2 cts-btn-primary btn-push">
15
+ + Nueva sesión
16
+ </button>
17
+ </div>
18
+
19
+ <div class="divider my-3"></div>
20
+
21
+ <div class="flex flex-wrap gap-4 text-base">
22
+ <div class="bg-surface-sweet rounded-xl p-4 grow border-l-2 border-b-2 border-pink-400">
23
+ <p class="font-semibold">Nombre completo:</p>
24
+ <p>{{ name }}</p>
25
+ </div>
26
+ <div class="bg-surface-sweet rounded-xl p-4 grow border-l-2 border-b-2 border-pink-400">
27
+ <p class="font-semibold">Nombre de usuario:</p>
28
+ <p>@{{ username }}</p>
29
+ </div>
30
+ <div class="bg-surface-sweet rounded-xl p-4 grow border-l-2 border-b-2 border-pink-400">
31
+ <p class="font-semibold">Email:</p>
32
+ <p>{{ email }}</p>
33
+ </div>
34
+ <div class="bg-surface-sweet rounded-xl p-4 grow border-l-2 border-b-2 border-pink-400">
35
+ <p class="font-semibold">Teléfono:</p>
36
+ <p>{{ phone }}</p>
37
+ </div>
38
+ <div class="bg-surface-sweet rounded-xl p-4 grow border-l-2 border-b-2 border-pink-400">
39
+ <p class="font-semibold">Genero:</p>
40
+ <p>{{ genere }}</p>
41
+ </div>
42
+ <div class="bg-surface-sweet rounded-xl p-4 grow border-l-2 border-b-2 border-pink-400">
43
+ <p class="font-semibold">Nacimiento:</p>
44
+ <p>{{ birthday }}</p>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+
50
+ <div class="space-y-4">
51
+ <h3 class="text-xl font-semibold">Sesiones en las que ha participado</h3>
52
+
53
+ <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
54
+ {% for sesion in sesiones %}
55
+ <div class="card bg-base-100 border border-base-300 shadow-md hover:shadow-lg transition">
56
+ <div class="card-body">
57
+ <h4 class="card-title text-lg font-bold">
58
+ {% if sesion.nombre %}
59
+ {{ sesion.nombre }}
60
+ {% else %}
61
+ <span class="italic text-gray-500">Sin nombre</span>
62
+ {% endif %}
63
+ </h4>
64
+
65
+ <div class="text-sm space-y-1">
66
+ <p><span class="font-semibold">Código:</span> {{ sesion.codigo }}</p>
67
+ <p><span class="font-semibold">Técnica:</span> {{ sesion.tecnica }}</p>
68
+ <p><span class="font-semibold">Fecha:</span> {{ sesion.fecha_creacion }}</p>
69
+ <p>
70
+ <span class="font-semibold">Finazliado:</span>
71
+ {% if sesion.finalizado %}
72
+ <span class="badge badge-success">Se ha concluido</span>
73
+ {% else %}
74
+ <span class="badge badge-warning">Sin concluir</span>
75
+ {% endif %}
76
+ </p>
77
+ {% if sesion.activo %}
78
+ <p>
79
+ <span class="font-semibold">Estatus:</span>
80
+ <span class="badge badge-success">En proceso</span>
81
+ </p>
82
+ {% endif %}
83
+ </div>
84
+ </div>
85
+ </div>
86
+ {% empty %}
87
+ <div class="col-span-full text-center text-gray-500">
88
+ No hay sesiones registradas.
89
+ </div>
90
+ {% endfor %}
91
+ </div>
92
+
93
+ {% if sesiones.has_other_pages %}
94
+ <div class="flex justify-center mt-6">
95
+ <div class="join">
96
+ {% if sesiones.has_previous %}
97
+ <a href="/" class="join-item btn btn-sm">«</a>
98
+ {% else %}
99
+ <button class="join-item btn btn-sm btn-disabled">«</button>
100
+ {% endif %}
101
+
102
+ {% for num in sesiones.paginator.page_range %}
103
+ {% if sesiones.number == num %}
104
+ <button class="join-item btn btn-sm btn-active">{{ num }}</button>
105
+ {% else %}
106
+ <a href="/" class="join-item btn btn-sm">{{ num }}</a>
107
+ {% endif %}
108
+ {% endfor %}
109
+
110
+ {% if sesiones.has_next %}
111
+ <a href="/" class="join-item btn btn-sm">»</a>
112
+ {% else %}
113
+ <button class="join-item btn btn-sm btn-disabled">»</button>
114
+ {% endif %}
115
+ </div>
116
+ </div>
117
+ {% endif %}
118
+ </div>
119
+ </div>
120
+ </article>
121
+ </article>
122
+ {% endblock %}
tecnicas/urls.py CHANGED
@@ -11,7 +11,7 @@ urlpatterns = [
11
  name="autenticacion"),
12
 
13
  path("catador-login",
14
- views.testerLogin,
15
  name="catador_login"),
16
 
17
 
@@ -79,9 +79,13 @@ urlpatterns = [
79
 
80
  # Vistas para catadores
81
  path("testers/catador-main",
82
- views.mainTesterForm,
83
  name="catador_main"),
84
 
 
 
 
 
85
  path("testers/en-session/convencional",
86
  views.convencionalScales,
87
  name="session_convencional"),
 
11
  name="autenticacion"),
12
 
13
  path("catador-login",
14
+ views.loginTester,
15
  name="catador_login"),
16
 
17
 
 
79
 
80
  # Vistas para catadores
81
  path("testers/catador-main",
82
+ views.mainPanelTester,
83
  name="catador_main"),
84
 
85
+ path("testers/catador-init",
86
+ views.initTesterForm,
87
+ name="catador_init"),
88
+
89
  path("testers/en-session/convencional",
90
  views.convencionalScales,
91
  name="session_convencional"),
tecnicas/views/__init__.py CHANGED
@@ -1,5 +1,5 @@
1
  from .autentication import autentication
2
- from .login_tester import testerLogin
3
  from .main_panel import mainPanel
4
 
5
  from .sessions_management.sessions_panel import sesionsPanel
@@ -22,5 +22,6 @@ from .apis.api_tag import newTag
22
  from .apis.api_words import words
23
  from .apis.rating_word import reatingWord
24
 
25
- from .tester_forms.main_tester_form import mainTesterForm
26
  from .tester_forms.convencional_scales import convencionalScales
 
 
1
  from .autentication import autentication
2
+ from .login_tester import loginTester
3
  from .main_panel import mainPanel
4
 
5
  from .sessions_management.sessions_panel import sesionsPanel
 
22
  from .apis.api_words import words
23
  from .apis.rating_word import reatingWord
24
 
25
+ from .tester_forms.init_tester_form import initTesterForm
26
  from .tester_forms.convencional_scales import convencionalScales
27
+ from .tester_forms.panel_main_tester import mainPanelTester
tecnicas/views/login_tester.py CHANGED
@@ -1,10 +1,28 @@
1
  from django.http import HttpRequest
2
  from django.shortcuts import render, redirect
3
  from django.urls import reverse
 
 
4
  from ..utils import general_error
5
  from ..controllers import LoginTesterController
6
 
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def testerLogin(req: HttpRequest):
9
  if req.method == "GET":
10
  return render(req, "tecnicas/cata-login.html")
 
1
  from django.http import HttpRequest
2
  from django.shortcuts import render, redirect
3
  from django.urls import reverse
4
+ from django.contrib.auth import login
5
+ from django.contrib.auth.models import User
6
  from ..utils import general_error
7
  from ..controllers import LoginTesterController
8
 
9
 
10
+ def loginTester(req: HttpRequest):
11
+ if req.method == "GET":
12
+ return render(req, "tecnicas/cata-login.html")
13
+ elif req.method == "POST":
14
+ view_context = {}
15
+ username = req.POST.get("user_tester")
16
+
17
+ user = User.objects.filter(username=username).first()
18
+ if not user:
19
+ view_context["error"] = "Catador no encontrado"
20
+ return render(req, "tecnicas/cata-login.html", view_context)
21
+
22
+ login(req, user, backend='django.contrib.auth.backends.ModelBackend')
23
+ return redirect(reverse("cata_system:catador_main"))
24
+
25
+
26
  def testerLogin(req: HttpRequest):
27
  if req.method == "GET":
28
  return render(req, "tecnicas/cata-login.html")
tecnicas/views/tester_forms/{main_tester_form.py → init_tester_form.py} RENAMED
@@ -4,7 +4,7 @@ from django.urls import reverse
4
  from ...controllers import SesionController, MainTesterFormController, ParticipacionController
5
 
6
 
7
- def mainTesterForm(req: HttpRequest):
8
  session = SesionController.getSessionByCodePanelTester(
9
  req.session["code_session"])
10
 
@@ -24,7 +24,6 @@ def mainTesterForm(req: HttpRequest):
24
  id_participation=req.session["id_participation"], repetition=session.tecnica.repeticion)
25
 
26
  if is_end:
27
- print("Estoy dentro y termine [0_0]")
28
  context["message"] = "El catador ha terminado de realizar su evaluación, espere instrucciones del presentador"
29
  context["has_ended"] = True
30
 
 
4
  from ...controllers import SesionController, MainTesterFormController, ParticipacionController
5
 
6
 
7
+ def initTesterForm(req: HttpRequest):
8
  session = SesionController.getSessionByCodePanelTester(
9
  req.session["code_session"])
10
 
 
24
  id_participation=req.session["id_participation"], repetition=session.tecnica.repeticion)
25
 
26
  if is_end:
 
27
  context["message"] = "El catador ha terminado de realizar su evaluación, espere instrucciones del presentador"
28
  context["has_ended"] = True
29
 
tecnicas/views/tester_forms/panel_main_tester.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.http import HttpRequest, JsonResponse
2
+ from django.shortcuts import render
3
+
4
+
5
+ def mainPanelTester(req: HttpRequest):
6
+ if req.method == "GET":
7
+ view_context = {
8
+ "name": f"{req.user.first_name} {req.user.last_name}",
9
+ "username": req.user.username,
10
+ "email": req.user.email,
11
+ "phone": req.user.user_catador.telefono,
12
+ "genere": req.user.user_catador.genero,
13
+ "birthday": req.user.user_catador.nacimiento
14
+ }
15
+ return render(req, "tecnicas/forms_tester/main_panel_tester.html", view_context)
16
+ else:
17
+ return JsonResponse({"message": "Método no permitido"})