chartManD commited on
Commit
415f2d8
·
1 Parent(s): 965ace8

Se agrega ingreso a sesion en login-sesion

Browse files
tecnicas/controllers/views_controller/login_tester_controller.py CHANGED
@@ -14,7 +14,7 @@ class LoginTesterController():
14
 
15
  def existCredential(self, user_tester: str, code_session: str):
16
  try:
17
- self.tester = Catador.objects.get(usuarioCatador=user_tester)
18
  self.session = SesionSensorial.objects.get(
19
  codigo_sesion=code_session)
20
 
@@ -23,7 +23,7 @@ class LoginTesterController():
23
  return controller_error("Credenciales inválidas")
24
 
25
  def validateEntry(self):
26
- if not self.tester.nombre or not self.session.codigo_sesion:
27
  return controller_error("Credenciales no definidas")
28
 
29
  if not self.session.activo:
 
14
 
15
  def existCredential(self, user_tester: str, code_session: str):
16
  try:
17
+ self.tester = Catador.objects.get(user__username=user_tester)
18
  self.session = SesionSensorial.objects.get(
19
  codigo_sesion=code_session)
20
 
 
23
  return controller_error("Credenciales inválidas")
24
 
25
  def validateEntry(self):
26
+ if not self.tester.user.first_name or not self.session.codigo_sesion:
27
  return controller_error("Credenciales no definidas")
28
 
29
  if not self.session.activo:
tecnicas/controllers/views_controller/main_tester_form_controller.py CHANGED
@@ -10,7 +10,7 @@ class MainTesterFormController():
10
 
11
  def __init__(self, code_session: str, user_tester: str):
12
  try:
13
- self.tester = Catador.objects.get(usuarioCatador=user_tester)
14
  self.session = SesionSensorial.objects.get(
15
  codigo_sesion=code_session)
16
  except (Catador.DoesNotExist, SesionSensorial.DoesNotExist):
 
10
 
11
  def __init__(self, code_session: str, user_tester: str):
12
  try:
13
+ self.tester = Catador.objects.get(user__username=user_tester)
14
  self.session = SesionSensorial.objects.get(
15
  codigo_sesion=code_session)
16
  except (Catador.DoesNotExist, SesionSensorial.DoesNotExist):
tecnicas/models/participacion.py CHANGED
@@ -12,4 +12,4 @@ class Participacion(models.Model):
12
  finalizado = models.BooleanField(default=True)
13
 
14
  def __str__(self):
15
- return f"{self.catador.usuarioCatador} {'activo' if self.activo else 'no activo'}"
 
12
  finalizado = models.BooleanField(default=True)
13
 
14
  def __str__(self):
15
+ return f"{self.catador.user.username} {'activo' if self.activo else 'no activo'}"
tecnicas/models/sesion_sensorial.py CHANGED
@@ -17,4 +17,9 @@ class SesionSensorial(models.Model):
17
  Tecnica, on_delete=models.CASCADE, related_name="sesion_tecnica")
18
 
19
  def __str__(self):
20
- return self.nombre_sesion if self.nombre_sesion else self.codigo_sesion
 
 
 
 
 
 
17
  Tecnica, on_delete=models.CASCADE, related_name="sesion_tecnica")
18
 
19
  def __str__(self):
20
+ name_str = f"{self.codigo_sesion}"
21
+
22
+ if self.nombre_sesion:
23
+ name_str += f" : {self.nombre_sesion}"
24
+
25
+ return name_str
tecnicas/templates/tecnicas/forms_tester/{main_tester.html → init_session.html} RENAMED
@@ -99,7 +99,8 @@
99
 
100
  <article class="flex flex-wrap gap-10">
101
  {% if has_ended %}
102
- <div class="text-2xl font-semibold flex-1 cts-btn-secondary p-4 flex justify-center items-center rounded-lg select-none">
 
103
  <p class=" text-black">Finalizaste la repetición</p>
104
  </div>
105
  {% else %}
@@ -112,14 +113,15 @@
112
  </figure>
113
  </button>
114
  {% endif %}
115
- <button
116
- class="flex-1 uppercase text-lg tracking-wider cts-btn-general cts-btn-error btn-push flex flex-col justify-center items-center gap-2"
117
- onclick="closeSession()">
118
- Salir se la sesión
119
- <figure class="w-10">
120
- <img src="{% static 'img/exit.svg' %}" alt="bote de basura" class="invert">
121
- </figure>
122
- </button>
 
123
  </article>
124
 
125
  <form action="" method="post" class="hidden ct-action-form">
 
99
 
100
  <article class="flex flex-wrap gap-10">
101
  {% if has_ended %}
102
+ <div
103
+ class="text-2xl font-semibold flex-1 cts-btn-secondary p-4 flex justify-center items-center rounded-lg select-none">
104
  <p class=" text-black">Finalizaste la repetición</p>
105
  </div>
106
  {% else %}
 
113
  </figure>
114
  </button>
115
  {% endif %}
116
+ <a href="{% url 'cata_system:catador_main' %}">
117
+ <button
118
+ class="flex-1 uppercase text-lg tracking-wider cts-btn-general cts-btn-error btn-push flex flex-col justify-center items-center gap-2">
119
+ Salir se la sesión
120
+ <figure class="w-10">
121
+ <img src="{% static 'img/exit.svg' %}" alt="bote de basura" class="invert">
122
+ </figure>
123
+ </button>
124
+ </a>
125
  </article>
126
 
127
  <form action="" method="post" class="hidden ct-action-form">
tecnicas/templates/tecnicas/forms_tester/login_session.html ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends 'tecnicas/layouts/base.html' %}
2
+
3
+ {% block title %}Ingresar a Sesión{% endblock %}
4
+
5
+ {% block content %}
6
+ <article class="cts-container-main">
7
+ <article class="cts-wrap-content text-black max-w-2xl">
8
+ <header class="flex flex-col md:flex-row md:items-center md:justify-between gap-3">
9
+ <h1 class="rounded font-bold text-2xl bg-surface-ligt p-4 flex-1">
10
+ Ingresar a una sesión sensorial
11
+ </h1>
12
+ <a href="{% url 'cata_system:catador_main' %}">
13
+ <button class="cts-btn-general-compress px-4 py-2 cts-btn-secondary btn-push">
14
+ Regresar
15
+ </button>
16
+ </a>
17
+ </header>
18
+
19
+ {% if error %}
20
+ {% include "../components/error-message.html" with message=error %}
21
+ {% endif %}
22
+ {% if message %}
23
+ {% include "../components/error-message.html" with message=message %}
24
+ {% endif %}
25
+
26
+ <form action="" method="post" class="rounded-xl text-black space-y-4">
27
+ {% csrf_token %}
28
+ <section class="bg-surface-sweet rounded p-4">
29
+ <h2 class="font-semibold text-2xl text-center">
30
+ Para Ingresar a la sesion debes ingresar el codigo de sesión
31
+ </h2>
32
+ </section>
33
+ <article class="flex flex-col gap-6 items-center w-full px-6">
34
+ <label for="code_session" class="w-full">
35
+ <input type="text" name="code_session" id="code_session" placeholder="Código de sesión"
36
+ class="placeholder:text-gray-400 placeholder:font-semibold text-xl max-sm:text-base bg-surface-ligt py-3 px-6 rounded-xl w-full border-b-2 border-surface-sweet"
37
+ required>
38
+ </label>
39
+
40
+ <section class="flex flex-row flex-wrap gap-4 w-full justify-center">
41
+ <button type="submit"
42
+ class="cts-btn-general-compress px-4 py-2 cts-btn-primary btn-push uppercase w-full">
43
+ Ingresar a la sesión
44
+ </button>
45
+ </section>
46
+ </article>
47
+ </form>
48
+ </article>
49
+ </article>
50
+ {% endblock %}
tecnicas/templates/tecnicas/forms_tester/main_panel_tester.html CHANGED
@@ -1,6 +1,6 @@
1
  {% extends 'tecnicas/layouts/base.html' %}
2
 
3
- {% block title %}Detalles Sesion{% endblock %}
4
 
5
  {% block content %}
6
  <article class="cts-container-main">
@@ -11,9 +11,11 @@
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>
 
1
  {% extends 'tecnicas/layouts/base.html' %}
2
 
3
+ {% block title %}Panel Principal Tester{% endblock %}
4
 
5
  {% block content %}
6
  <article class="cts-container-main">
 
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
+ <a href="{% url 'cata_system:catador_in_session' %}">
15
+ <button class="cts-btn-general-compress px-4 py-2 cts-btn-primary btn-push">
16
+ + Nueva sesión
17
+ </button>
18
+ </a>
19
  </div>
20
 
21
  <div class="divider my-3"></div>
tecnicas/urls.py CHANGED
@@ -82,9 +82,13 @@ urlpatterns = [
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,
 
82
  views.mainPanelTester,
83
  name="catador_main"),
84
 
85
+ path("testers/log-in-session",
86
+ views.loginSessionTester,
87
+ name="catador_in_session"),
88
+
89
+ path("testers/init-session/<str:code_sesion>",
90
  views.initTesterForm,
91
+ name="catador_init_session"),
92
 
93
  path("testers/en-session/convencional",
94
  views.convencionalScales,
tecnicas/views/__init__.py CHANGED
@@ -25,3 +25,4 @@ from .apis.rating_word import reatingWord
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
 
 
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
28
+ from .tester_forms.login_session import loginSessionTester
tecnicas/views/login_tester.py CHANGED
@@ -3,8 +3,6 @@ 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):
@@ -21,44 +19,3 @@ def loginTester(req: HttpRequest):
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")
29
- elif req.method == "POST":
30
- tester_user = req.POST.get("user_tester")
31
- session_code = req.POST.get("code_session")
32
- if not tester_user or not session_code:
33
- return general_error("Se esperan credenciales")
34
-
35
- login_controller = LoginTesterController()
36
-
37
- existCredentials = login_controller.existCredential(
38
- tester_user, session_code)
39
- if isinstance(existCredentials, dict):
40
- context = {"error": existCredentials["error"]}
41
- return render(req, "tecnicas/cata-login.html", context)
42
-
43
- tester = existCredentials[0]
44
- session = existCredentials[1]
45
-
46
- taster_participation = login_controller.validateEntry()
47
- if isinstance(taster_participation, dict):
48
- context = {"error": taster_participation["error"]}
49
- return render(req, "tecnicas/cata-login.html", context)
50
-
51
- req.session["cata_username"] = tester_user
52
- req.session["id_cata"] = tester.id
53
- req.session["code_session"] = session_code
54
- req.session["id_techniqe"] = session.tecnica.id
55
- req.session["id_participation"] = taster_participation.id
56
-
57
- req.session.set_expiry(15*60)
58
-
59
- response = redirect(reverse("cata_system:catador_main"))
60
- response.set_cookie('id_participacion',
61
- taster_participation.id, max_age=60*60*24)
62
- return response
63
- else:
64
- return render(req, "tecnicas/cata-login.html")
 
3
  from django.urls import reverse
4
  from django.contrib.auth import login
5
  from django.contrib.auth.models import User
 
 
6
 
7
 
8
  def loginTester(req: HttpRequest):
 
19
 
20
  login(req, user, backend='django.contrib.auth.backends.ModelBackend')
21
  return redirect(reverse("cata_system:catador_main"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tecnicas/views/tester_forms/init_tester_form.py CHANGED
@@ -4,16 +4,17 @@ from django.urls import reverse
4
  from ...controllers import SesionController, MainTesterFormController, ParticipacionController
5
 
6
 
7
- def initTesterForm(req: HttpRequest):
8
- session = SesionController.getSessionByCodePanelTester(
9
- req.session["code_session"])
10
 
11
  context = {
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()
@@ -22,12 +23,12 @@ def initTesterForm(req: HttpRequest):
22
  req.session["id_order"] = order.id
23
  is_end = view_controller.isEndedSession(
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
 
30
- return render(req, "tecnicas/forms_tester/main_tester.html", context)
31
  elif req.method == "POST":
32
  if req.POST["action"] == "start_posting":
33
  if "id_order" in req.session:
@@ -35,33 +36,30 @@ def initTesterForm(req: HttpRequest):
35
  id_participation=req.session["id_participation"])
36
  if isinstance(update_participation, dict):
37
  context["error"] = update_participation["error"]
38
- return render(req, "tecnicas/forms_tester/main_tester.html", context)
39
 
40
  return redirect(reverse("cata_system:session_convencional"))
41
 
42
  order = view_controller.assignOrder()
43
  if isinstance(order, dict):
44
  context["error"] = order["error"]
45
- return render(req, "tecnicas/forms_tester/main_tester.html", context)
46
 
47
  update_participation = ParticipacionController.enterSession(
48
  id_participation=req.session["id_participation"])
49
  if isinstance(update_participation, dict):
50
  context["error"] = update_participation["error"]
51
- return render(req, "tecnicas/forms_tester/main_tester.html", context)
52
 
53
  return redirect(reverse("cata_system:session_convencional"))
54
- elif req.POST["action"] == "close_session":
55
- req.session.flush()
56
- return redirect(reverse("cata_system:catador_login"))
57
  elif req.POST["action"] == "exit_session":
58
  response = ParticipacionController.outSession(
59
  req.session["id_participation"])
60
  if isinstance(response, dict):
61
  context["error"] = response["error"]
62
- return render(req, "tecnicas/forms_tester/main_tester.html", context)
63
  else:
64
  context["error"] = "Acción sin especificar"
65
- return render(req, "tecnicas/forms_tester/main_tester.html", context)
66
  else:
67
  return JsonResponse({"error": "metodo no permitido"})
 
4
  from ...controllers import SesionController, MainTesterFormController, ParticipacionController
5
 
6
 
7
+ def initTesterForm(req: HttpRequest, code_sesion: str):
8
+ session = SesionController.getSessionByCodePanelTester(code_sesion)
 
9
 
10
  context = {
11
  "session": session
12
  }
13
 
14
  view_controller = MainTesterFormController(
15
+ code_sesion, req.user.username)
16
+
17
+ template_url = "tecnicas/forms_tester/init_session.html"
18
 
19
  if req.method == "GET":
20
  order = view_controller.checkAssignOrder()
 
23
  req.session["id_order"] = order.id
24
  is_end = view_controller.isEndedSession(
25
  id_participation=req.session["id_participation"], repetition=session.tecnica.repeticion)
26
+
27
  if is_end:
28
  context["message"] = "El catador ha terminado de realizar su evaluación, espere instrucciones del presentador"
29
  context["has_ended"] = True
30
 
31
+ return render(req, template_url, context)
32
  elif req.method == "POST":
33
  if req.POST["action"] == "start_posting":
34
  if "id_order" in req.session:
 
36
  id_participation=req.session["id_participation"])
37
  if isinstance(update_participation, dict):
38
  context["error"] = update_participation["error"]
39
+ return render(req, template_url, context)
40
 
41
  return redirect(reverse("cata_system:session_convencional"))
42
 
43
  order = view_controller.assignOrder()
44
  if isinstance(order, dict):
45
  context["error"] = order["error"]
46
+ return render(req, template_url, context)
47
 
48
  update_participation = ParticipacionController.enterSession(
49
  id_participation=req.session["id_participation"])
50
  if isinstance(update_participation, dict):
51
  context["error"] = update_participation["error"]
52
+ return render(req, template_url, context)
53
 
54
  return redirect(reverse("cata_system:session_convencional"))
 
 
 
55
  elif req.POST["action"] == "exit_session":
56
  response = ParticipacionController.outSession(
57
  req.session["id_participation"])
58
  if isinstance(response, dict):
59
  context["error"] = response["error"]
60
+ return render(req, template_url, context)
61
  else:
62
  context["error"] = "Acción sin especificar"
63
+ return render(req, template_url, context)
64
  else:
65
  return JsonResponse({"error": "metodo no permitido"})
tecnicas/views/tester_forms/login_session.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.http import HttpRequest, JsonResponse
2
+ from django.shortcuts import render, redirect
3
+ from django.urls import reverse
4
+ from tecnicas.utils import general_error
5
+ from tecnicas.controllers import LoginTesterController
6
+
7
+
8
+ def loginSessionTester(req: HttpRequest):
9
+ if req.method == "GET":
10
+ return render(req, "tecnicas/forms_tester/login_session.html")
11
+ elif req.method == "POST":
12
+ tester_user = req.user.username
13
+ session_code = req.POST.get("code_session")
14
+ if not tester_user or not session_code:
15
+ return general_error("Se esperan credenciales")
16
+
17
+ login_controller = LoginTesterController()
18
+
19
+ existCredentials = login_controller.existCredential(
20
+ tester_user, session_code)
21
+ if isinstance(existCredentials, dict):
22
+ context = {"error": existCredentials["error"]}
23
+ return render(req, "tecnicas/forms_tester/login_session.html", context)
24
+
25
+ tester = existCredentials[0]
26
+ session = existCredentials[1]
27
+
28
+ taster_participation = login_controller.validateEntry()
29
+ if isinstance(taster_participation, dict):
30
+ context = {"error": taster_participation["error"]}
31
+ return render(req, "tecnicas/forms_tester/login_session.html", context)
32
+
33
+ params = {
34
+ "code_sesion": session_code
35
+ }
36
+
37
+ return redirect(reverse("cata_system:catador_init_session", kwargs=params))
38
+ else:
39
+ return JsonResponse({"message": "Método no valido"})
40
+
41
+ # req.session["cata_username"] = tester_user
42
+ # req.session["id_cata"] = tester.id
43
+ # req.session["code_session"] = session_code
44
+ # req.session["id_techniqe"] = session.tecnica.id
45
+ # req.session["id_participation"] = taster_participation.id
46
+
47
+ # response.set_cookie('id_participacion', taster_participation.id, max_age=60*60*24)