chartManD commited on
Commit
f35536d
·
1 Parent(s): fb8b627

Configuracion basica para sesion con RATA

Browse files
tecnicas/controllers/views_controller/create_session/panel_basic_controller.py CHANGED
@@ -5,14 +5,25 @@ from django.urls import reverse
5
 
6
 
7
  class PanelBasicController():
 
 
 
 
 
8
  def __init__(self):
9
  pass
10
 
11
  @staticmethod
12
  def controllGetEscalas(request: HttpRequest):
13
  form_sesion = SesionBasicForm()
 
 
 
 
 
 
14
  response = render(
15
- request, "tecnicas/create_sesion/configuracion-panel-basic.html", {"form_sesion": form_sesion})
16
  return response
17
 
18
  @staticmethod
@@ -40,3 +51,55 @@ class PanelBasicController():
40
  "cata_system:seleccion_tecnica") + "?error=error en datos de configuracion")
41
 
42
  return response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
 
7
  class PanelBasicController():
8
+ conf_initial_rata = {
9
+ "numero_catadores": 0,
10
+ "numero_repeticiones": 1
11
+ }
12
+
13
  def __init__(self):
14
  pass
15
 
16
  @staticmethod
17
  def controllGetEscalas(request: HttpRequest):
18
  form_sesion = SesionBasicForm()
19
+
20
+ view_context = {
21
+ "form_sesion": form_sesion,
22
+ "use_technique": "escalas"
23
+ }
24
+
25
  response = render(
26
+ request, "tecnicas/create_sesion/configuracion-panel-basic.html", view_context)
27
  return response
28
 
29
  @staticmethod
 
51
  "cata_system:seleccion_tecnica") + "?error=error en datos de configuracion")
52
 
53
  return response
54
+
55
+ @staticmethod
56
+ def controllGetRATA(request: HttpRequest):
57
+ form_sesion = SesionBasicForm(
58
+ initial_conf=PanelBasicController.conf_initial_rata)
59
+
60
+ view_context = {
61
+ "form_sesion": form_sesion,
62
+ "use_technique": "rata"
63
+ }
64
+
65
+ response = render(
66
+ request, "tecnicas/create_sesion/configuracion-panel-basic.html", view_context)
67
+ return response
68
+
69
+ @staticmethod
70
+ def controllPostRATA(request: HttpRequest, name_tecnica: str):
71
+ try:
72
+ form = SesionBasicForm(
73
+ request.POST, initial_conf=PanelBasicController.conf_initial_rata)
74
+
75
+ if form.is_valid():
76
+ values = {}
77
+ for name, value in form.cleaned_data.items():
78
+ if name == "estilo_palabras" or name == "tipo_escala":
79
+ values[name] = value.id
80
+ else:
81
+ values[name] = value
82
+
83
+ for key, expected in PanelBasicController.conf_initial_rata.items():
84
+ actual = values.get(key)
85
+
86
+ if actual is None or str(actual) != str(expected):
87
+ form.add_error(
88
+ key, f"Valor inválido para '{key}': se esperaba {expected}, se recibió {actual}")
89
+
90
+ if form.errors:
91
+ response = render(request, "tecnicas/create_sesion/configuracion-panel-basic.html", {
92
+ "form_sesion": form, "error": "No puedes modificar el número de catadores o repeticiones"})
93
+ else:
94
+ values["name_tecnica"] = name_tecnica
95
+ request.session['form_basic'] = values
96
+ response = redirect(
97
+ reverse("cata_system:panel_configuracion_tags"))
98
+ else:
99
+ response = render(request, "tecnicas/create_sesion/configuracion-panel-basic.html", {
100
+ "form_sesion": form, "error": "Información no valida"})
101
+ except KeyError:
102
+ response = redirect(reverse(
103
+ "cata_system:seleccion_tecnica") + "?error=error en datos de configuracion")
104
+
105
+ return response
tecnicas/forms/sesion_basic_form.py CHANGED
@@ -34,9 +34,12 @@ class SesionBasicForm(forms.Form):
34
  "placeholder": "Este campo es opcional"
35
  }), required=False)
36
 
37
- def __init__(self, *args, **kwargs):
38
  super().__init__(*args, **kwargs)
39
 
 
 
 
40
  self.fields['estilo_palabras'] = forms.ModelChoiceField(queryset=EstiloPalabra.objects.all(), widget=forms.RadioSelect(attrs={
41
  "class": "uppercase text-lg tracking-wider font-medium p-2 px-4 active:px-5 transition-all rounded-xl bg-blue-500 text-white",
42
  }), required=True, initial=EstiloPalabra.objects.first())
@@ -49,6 +52,12 @@ class SesionBasicForm(forms.Form):
49
  "class": "cts-size-input",
50
  }), required=True)
51
 
 
 
 
 
 
 
52
  def clean(self):
53
  data_clean = super().clean()
54
  escala = data_clean.get("tipo_escala")
 
34
  "placeholder": "Este campo es opcional"
35
  }), required=False)
36
 
37
+ def __init__(self, *args, initial_conf: dict = None, **kwargs):
38
  super().__init__(*args, **kwargs)
39
 
40
+ if initial_conf is None:
41
+ initial_conf = {}
42
+
43
  self.fields['estilo_palabras'] = forms.ModelChoiceField(queryset=EstiloPalabra.objects.all(), widget=forms.RadioSelect(attrs={
44
  "class": "uppercase text-lg tracking-wider font-medium p-2 px-4 active:px-5 transition-all rounded-xl bg-blue-500 text-white",
45
  }), required=True, initial=EstiloPalabra.objects.first())
 
52
  "class": "cts-size-input",
53
  }), required=True)
54
 
55
+ if "numero_catadores" in initial_conf:
56
+ self.fields["numero_catadores"].initial = initial_conf["numero_catadores"]
57
+
58
+ if "numero_repeticiones" in initial_conf:
59
+ self.fields["numero_repeticiones"].initial = initial_conf["numero_repeticiones"]
60
+
61
  def clean(self):
62
  data_clean = super().clean()
63
  escala = data_clean.get("tipo_escala")
tecnicas/templates/tecnicas/create_sesion/configuracion-panel-basic.html CHANGED
@@ -26,20 +26,45 @@
26
  {{ form_sesion.nombre_sesion }}
27
  </label>
28
  </section>
29
- <section
30
- class="flex flex-row flex-wrap justify-center gap-4 [&>label]:text-lg [&>label]:flex [&>label]:flex-col [&>label]:items-center [&>label]:px-2 [&>label]:font-medium [&>label]:tracking-wide [&>label]:[&>p]:tracking-normal [&>label]:[&>p]:text-base [&>label]:[&>p]:font-bold">
31
- <label for="{{ form_sesion.numero_productos.id_for_label }}">
32
- <p>Número de Productos:</p>
 
 
33
  {{ form_sesion.numero_productos }}
34
  </label>
35
- <label for="{{ form_sesion.numero_catadores.id_for_label }}">
36
- <p>Número de Catadores:</p>
 
 
 
 
37
  {{ form_sesion.numero_catadores }}
38
  </label>
39
- <label for="{{ form_sesion.numero_repeticiones.id_for_label }}">
40
- <p>Número de Repeticiones:</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  {{ form_sesion.numero_repeticiones }}
42
  </label>
 
43
  </section>
44
  <section class="flex justify-center items-center mt-2">
45
  <label for="{{form_sesion.instrucciones.id_for_label}}"
@@ -95,15 +120,18 @@
95
  </label>
96
  <div class="flex justify-around max-sm:flex-col gap-8 cts-options-size-scale">
97
  <label class="flex flex-col items-center cursor-pointer">
98
- <input type="radio" name="option_size_scale" value="5" class="radio radio-lg checked:bg-pink-500" />
 
99
  <span class="mt-2 text-xl text-gray-700 font-medium">5</span>
100
  </label>
101
  <label class="flex flex-col items-center cursor-pointer">
102
- <input type="radio" name="option_size_scale" value="7" class="radio radio-lg checked:bg-pink-500" />
 
103
  <span class="mt-2 text-xl text-gray-700 font-medium">7</span>
104
  </label>
105
  <label class="flex flex-col items-center cursor-pointer">
106
- <input type="radio" name="option_size_scale" value="9" class="radio radio-lg checked:bg-pink-500" />
 
107
  <span class="mt-2 text-xl text-gray-700 font-medium">9</span>
108
  </label>
109
  </div>
 
26
  {{ form_sesion.nombre_sesion }}
27
  </label>
28
  </section>
29
+ <section class="flex flex-row flex-wrap justify-center gap-4">
30
+ <label for="{{ form_sesion.numero_productos.id_for_label }}"
31
+ class="text-lg flex flex-col items-center px-2 font-medium tracking-wide">
32
+ <p class="tracking-normal text-base font-bold">
33
+ Número de Productos:
34
+ </p>
35
  {{ form_sesion.numero_productos }}
36
  </label>
37
+ {% if use_technique == 'escalas' %}
38
+ <label for="{{ form_sesion.numero_catadores.id_for_label }}"
39
+ class="text-lg flex flex-col items-center px-2 font-medium tracking-wide">
40
+ <p class="tracking-normal text-base font-bold">
41
+ Número de Catadores:
42
+ </p>
43
  {{ form_sesion.numero_catadores }}
44
  </label>
45
+ <label for="{{ form_sesion.numero_repeticiones.id_for_label }}"
46
+ class="text-lg flex flex-col items-center px-2 font-medium tracking-wide">
47
+ <p class="tracking-normal text-base font-bold">
48
+ Número de Repeticiones:
49
+ </p>
50
+ {{ form_sesion.numero_repeticiones }}
51
+ </label>
52
+ {% else %}
53
+ <label for="{{ form_sesion.numero_catadores.id_for_label }}"
54
+ class="text-lg flex flex-col items-center px-2 font-medium tracking-wide hidden">
55
+ <p class="tracking-normal text-base font-bold">
56
+ Número de Catadores:
57
+ </p>
58
+ {{ form_sesion.numero_catadores }}
59
+ </label>
60
+ <label for="{{ form_sesion.numero_repeticiones.id_for_label }}"
61
+ class="text-lg flex flex-col items-center px-2 font-medium tracking-wide hidden">
62
+ <p class="tracking-normal text-base font-bold">
63
+ Número de Repeticiones:
64
+ </p>
65
  {{ form_sesion.numero_repeticiones }}
66
  </label>
67
+ {% endif %}
68
  </section>
69
  <section class="flex justify-center items-center mt-2">
70
  <label for="{{form_sesion.instrucciones.id_for_label}}"
 
120
  </label>
121
  <div class="flex justify-around max-sm:flex-col gap-8 cts-options-size-scale">
122
  <label class="flex flex-col items-center cursor-pointer">
123
+ <input type="radio" name="option_size_scale" value="5"
124
+ class="radio radio-lg checked:bg-pink-500" />
125
  <span class="mt-2 text-xl text-gray-700 font-medium">5</span>
126
  </label>
127
  <label class="flex flex-col items-center cursor-pointer">
128
+ <input type="radio" name="option_size_scale" value="7"
129
+ class="radio radio-lg checked:bg-pink-500" />
130
  <span class="mt-2 text-xl text-gray-700 font-medium">7</span>
131
  </label>
132
  <label class="flex flex-col items-center cursor-pointer">
133
+ <input type="radio" name="option_size_scale" value="9"
134
+ class="radio radio-lg checked:bg-pink-500" />
135
  <span class="mt-2 text-xl text-gray-700 font-medium">9</span>
136
  </label>
137
  </div>
tecnicas/views/sessions_config/configuration_panel_basic.py CHANGED
@@ -7,12 +7,14 @@ from tecnicas.utils import deleteDataSession
7
 
8
  def configurationPanelBasic(req: HttpRequest):
9
  deleteDataSession(req)
10
-
11
  if req.method == "GET":
12
  name_tecnica = req.GET["name_tecnica"]
13
 
14
  if name_tecnica == "escalas":
15
  response = PanelBasicController.controllGetEscalas(request=req)
 
 
16
  else:
17
  response = redirect(
18
  reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida o sin implementar")
@@ -24,6 +26,9 @@ def configurationPanelBasic(req: HttpRequest):
24
  if name_tecnica == "escalas":
25
  response = PanelBasicController.controllPostEscalas(
26
  request=req, name_tecnica=name_tecnica)
 
 
 
27
  else:
28
  response = redirect(
29
  reverse("cata_system:seleccion_tecnica") + "?error=¡Oh, vaya! Cambio de técnica repentino, vuelve a elegir otra vez")
 
7
 
8
  def configurationPanelBasic(req: HttpRequest):
9
  deleteDataSession(req)
10
+
11
  if req.method == "GET":
12
  name_tecnica = req.GET["name_tecnica"]
13
 
14
  if name_tecnica == "escalas":
15
  response = PanelBasicController.controllGetEscalas(request=req)
16
+ elif name_tecnica == "rata":
17
+ response = PanelBasicController.controllGetRATA(request=req)
18
  else:
19
  response = redirect(
20
  reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida o sin implementar")
 
26
  if name_tecnica == "escalas":
27
  response = PanelBasicController.controllPostEscalas(
28
  request=req, name_tecnica=name_tecnica)
29
+ elif name_tecnica == "rata":
30
+ response = PanelBasicController.controllPostRATA(
31
+ request=req, name_tecnica=name_tecnica)
32
  else:
33
  response = redirect(
34
  reverse("cata_system:seleccion_tecnica") + "?error=¡Oh, vaya! Cambio de técnica repentino, vuelve a elegir otra vez")
tecnicas/views/sessions_config/configuration_panel_tags.py CHANGED
@@ -10,11 +10,11 @@ def configurationPanelTags(req: HttpRequest):
10
  deleteDataSession(req)
11
  return redirect(reverse('cata_system:panel_configuracion_basic') +
12
  "?error=datos requeridos no encontrados")
13
-
14
  basic_data = req.session.get("form_basic")
15
 
16
  if req.method == "GET":
17
- if basic_data["name_tecnica"] == "escalas":
18
  response = PanelTagsController.controllGetEscalas(
19
  request=req, data=basic_data)
20
  else:
@@ -23,7 +23,7 @@ def configurationPanelTags(req: HttpRequest):
23
 
24
  return response
25
  elif req.method == "POST":
26
- if basic_data["name_tecnica"] == "escalas":
27
  response = PanelTagsController.controllPostEscalas(
28
  request=req, data=basic_data)
29
  else:
 
10
  deleteDataSession(req)
11
  return redirect(reverse('cata_system:panel_configuracion_basic') +
12
  "?error=datos requeridos no encontrados")
13
+
14
  basic_data = req.session.get("form_basic")
15
 
16
  if req.method == "GET":
17
+ if basic_data["name_tecnica"] == "escalas" or basic_data["name_tecnica"] == "rata":
18
  response = PanelTagsController.controllGetEscalas(
19
  request=req, data=basic_data)
20
  else:
 
23
 
24
  return response
25
  elif req.method == "POST":
26
+ if basic_data["name_tecnica"] == "escalas" or basic_data["name_tecnica"] == "rata":
27
  response = PanelTagsController.controllPostEscalas(
28
  request=req, data=basic_data)
29
  else: