chartManD commited on
Commit
89e83ae
·
1 Parent(s): bc22ead

Manejo de errores en primer formulario de configuracion

Browse files
tecnicas/templates/tecnicas/seleccion-tecnica.html CHANGED
@@ -16,16 +16,22 @@
16
  </div>
17
  </header>
18
  <section class="text-white *:not-last:mb-4">
 
 
 
 
 
 
19
  {% for cate, tecnicas in tipos.items %}
20
  <article>
21
  <button
22
  class="p-4 bg-blue-700 hover:bg-blue-800 active:ring-4 active:outline-none active:ring-blue-300 flex flex-row gap-4 justify-center items-center rounded-lg text-2xl font-medium uppercase tracking-wider w-full z-20 relative"
23
- onclick="showList('{{cate}}')" type="button">{{ cate }}</button>
24
  {% if tecnicas %}
25
  <section
26
  class="modal-list-{{ cate }} flex flex-col text-lg bg-blue-100 p-4 pr-6 pl-8 sm:pl-12 z-10 -translate-y-1 rounded-b-2xl *:not-last:mb-4 transition-all duration-1000 hidden w-full">
27
  {% for tecnica in tecnicas %}
28
- <a href="{% url 'cata_system:panel_configuracion'%}?id_tecnica={{tecnica.id}}"
29
  class="bg-green-700 border-l-10 border-gray-700 rounded-md px-3 py-2 w-full font-bold tracking-wider text-left uppercase">
30
  {{ tecnica.nombre_tecnica }}
31
  </a>
@@ -50,5 +56,10 @@
50
  list.classList.add("hidden")
51
  }
52
  }
 
 
 
 
 
53
  </script>
54
  {% endblock %}
 
16
  </div>
17
  </header>
18
  <section class="text-white *:not-last:mb-4">
19
+ {% if error %}
20
+ <article class="ct-error bg-red-400 rounded-xl text-center font-normal tracking-wider text-xl p-1 pb-2">
21
+ <p>{{ error }}</p>
22
+ </article>
23
+ {% endif %}
24
+
25
  {% for cate, tecnicas in tipos.items %}
26
  <article>
27
  <button
28
  class="p-4 bg-blue-700 hover:bg-blue-800 active:ring-4 active:outline-none active:ring-blue-300 flex flex-row gap-4 justify-center items-center rounded-lg text-2xl font-medium uppercase tracking-wider w-full z-20 relative"
29
+ onclick="showList('{{cate}}'); hiddenError()" type="button">{{ cate }}</button>
30
  {% if tecnicas %}
31
  <section
32
  class="modal-list-{{ cate }} flex flex-col text-lg bg-blue-100 p-4 pr-6 pl-8 sm:pl-12 z-10 -translate-y-1 rounded-b-2xl *:not-last:mb-4 transition-all duration-1000 hidden w-full">
33
  {% for tecnica in tecnicas %}
34
+ <a href="{% url 'cata_system:panel_configuracion'%}?id_tecnica={{tecnica.id}}"
35
  class="bg-green-700 border-l-10 border-gray-700 rounded-md px-3 py-2 w-full font-bold tracking-wider text-left uppercase">
36
  {{ tecnica.nombre_tecnica }}
37
  </a>
 
56
  list.classList.add("hidden")
57
  }
58
  }
59
+
60
+ function hiddenError () {
61
+ const error = document.getElementsByClassName("ct-error")[0]
62
+ error.classList.add("hidden")
63
+ }
64
  </script>
65
  {% endblock %}
tecnicas/views/configuracion_panel.py CHANGED
@@ -1,5 +1,6 @@
1
  from django.shortcuts import render, redirect
2
  from django.http import HttpRequest
 
3
  from ..forms import SesionFirtsForm
4
  from ..models import TipoTecnica
5
 
@@ -11,16 +12,16 @@ def configuracionPanel(req: HttpRequest):
11
  else:
12
  return render(req, "tecnicas/configuracion-panel.html", { "form_sesion": form })
13
  elif req.method == "GET":
14
- if req.GET["id_tecnica"]:
15
- try:
16
- tecnica = TipoTecnica.objects.get(pk=int(req.GET["id_tecnica"]))
17
- except (ValueError, TipoTecnica.DoesNotExist):
18
-
19
- pass
20
- else:
21
- redirect("/seleccion-tecnica")
22
- pass
23
-
24
- form_sesion = SesionFirtsForm()
25
 
26
- return render(req, "tecnicas/configuracion-panel.html", { "form_sesion": form_sesion })
 
 
 
 
 
1
  from django.shortcuts import render, redirect
2
  from django.http import HttpRequest
3
+ from django.urls import reverse
4
  from ..forms import SesionFirtsForm
5
  from ..models import TipoTecnica
6
 
 
12
  else:
13
  return render(req, "tecnicas/configuracion-panel.html", { "form_sesion": form })
14
  elif req.method == "GET":
15
+ try:
16
+ id_tecnica = req.GET["id_tecnica"]
17
+ tecnica = TipoTecnica.objects.get(pk=id_tecnica)
18
+ except KeyError:
19
+ return redirect(reverse("cata_system:seleccion_tecnica") + "?error=tecnica_no_establecida")
20
+ except (ValueError, TipoTecnica.DoesNotExist):
21
+ return redirect(reverse("cata_system:seleccion_tecnica") + "?error=tecnica_no_establecida")
 
 
 
 
22
 
23
+ if tecnica:
24
+ form_sesion = SesionFirtsForm()
25
+ return render(req, "tecnicas/configuracion-panel.html", { "form_sesion": form_sesion })
26
+ else:
27
+ return redirect(reverse("cata_system:seleccion_tecnica") + "?error=la_tecnica_no_existe")
tecnicas/views/seleccion_tecnica.py CHANGED
@@ -1,7 +1,15 @@
1
  from django.shortcuts import render
 
2
 
3
  from ..controllers import TecnicaController
4
 
5
- def selecionTecnica(req):
6
  tipos = TecnicaController.getTypesTechnique()
7
- return render(req, "tecnicas/seleccion-tecnica.html", context={"tipos":tipos})
 
 
 
 
 
 
 
 
1
  from django.shortcuts import render
2
+ from django.http import HttpRequest
3
 
4
  from ..controllers import TecnicaController
5
 
6
+ def selecionTecnica(req:HttpRequest):
7
  tipos = TecnicaController.getTypesTechnique()
8
+ try:
9
+ error : str = req.GET["error"]
10
+ error = error.replace("_", " ")
11
+ error = error.capitalize()
12
+
13
+ return render(req, "tecnicas/seleccion-tecnica.html", context={"tipos":tipos, "error":error})
14
+ except KeyError:
15
+ return render(req, "tecnicas/seleccion-tecnica.html", context={"tipos":tipos})