Spaces:
Sleeping
Sleeping
Creado Middlaware para comprobar session de Catador
Browse files- cata_system/settings.py +1 -0
- tecnicas/admin.py +2 -0
- tecnicas/middlewares/__init__.py +1 -0
- tecnicas/middlewares/login_tester_middleware.py +19 -0
- tecnicas/static/js/details-session.js +1 -1
- tecnicas/templates/tecnicas/cata-login.html +1 -1
- tecnicas/templates/tecnicas/forms_tester/main_tester.html +15 -0
- tecnicas/templates/tecnicas/manage_sesions/detalles-sesion.html +16 -0
- tecnicas/urls.py +9 -4
- tecnicas/views/__init__.py +2 -0
- tecnicas/views/login_tester.py +3 -1
- tecnicas/views/sessions_management/session_details.py +3 -3
- tecnicas/views/tester_forms/main_tester_form.py +9 -0
cata_system/settings.py
CHANGED
|
@@ -70,6 +70,7 @@ MIDDLEWARE = [
|
|
| 70 |
|
| 71 |
'django_browser_reload.middleware.BrowserReloadMiddleware',
|
| 72 |
|
|
|
|
| 73 |
]
|
| 74 |
|
| 75 |
ROOT_URLCONF = 'cata_system.urls'
|
|
|
|
| 70 |
|
| 71 |
'django_browser_reload.middleware.BrowserReloadMiddleware',
|
| 72 |
|
| 73 |
+
'tecnicas.middlewares.LoginTesterMiddleware'
|
| 74 |
]
|
| 75 |
|
| 76 |
ROOT_URLCONF = 'cata_system.urls'
|
tecnicas/admin.py
CHANGED
|
@@ -20,6 +20,7 @@ from .models import Escala
|
|
| 20 |
from .models import EtiquetasEscala
|
| 21 |
|
| 22 |
from .models import Producto
|
|
|
|
| 23 |
|
| 24 |
# Register your models here.
|
| 25 |
admin.site.register(CategoriaTecnica)
|
|
@@ -41,3 +42,4 @@ admin.site.register(Escala)
|
|
| 41 |
admin.site.register(EtiquetasEscala)
|
| 42 |
|
| 43 |
admin.site.register(Producto)
|
|
|
|
|
|
| 20 |
from .models import EtiquetasEscala
|
| 21 |
|
| 22 |
from .models import Producto
|
| 23 |
+
from .models import Participacion
|
| 24 |
|
| 25 |
# Register your models here.
|
| 26 |
admin.site.register(CategoriaTecnica)
|
|
|
|
| 42 |
admin.site.register(EtiquetasEscala)
|
| 43 |
|
| 44 |
admin.site.register(Producto)
|
| 45 |
+
admin.site.register(Participacion)
|
tecnicas/middlewares/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .login_tester_middleware import LoginTesterMiddleware
|
tecnicas/middlewares/login_tester_middleware.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest
|
| 2 |
+
from django.shortcuts import redirect
|
| 3 |
+
from django.urls import reverse
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class LoginTesterMiddleware():
|
| 7 |
+
def __init__(self, get_response):
|
| 8 |
+
self.get_response = get_response
|
| 9 |
+
|
| 10 |
+
def __call__(self, req: HttpRequest):
|
| 11 |
+
urls_protected = ["/cata/catador-main"]
|
| 12 |
+
|
| 13 |
+
if req.path in urls_protected:
|
| 14 |
+
if not "cata_username" in req.session:
|
| 15 |
+
return redirect(reverse("cata_system:catador_login"))
|
| 16 |
+
|
| 17 |
+
response = self.get_response(req)
|
| 18 |
+
|
| 19 |
+
return response
|
tecnicas/static/js/details-session.js
CHANGED
|
@@ -16,7 +16,7 @@ function startRepetition() {
|
|
| 16 |
const inputUser = document.createElement("input");
|
| 17 |
inputUser.type = "hidden";
|
| 18 |
inputUser.name = "username";
|
| 19 |
-
inputUser.value = "
|
| 20 |
|
| 21 |
actionForm.appendChild(inputAction);
|
| 22 |
actionForm.appendChild(inputUser);
|
|
|
|
| 16 |
const inputUser = document.createElement("input");
|
| 17 |
inputUser.type = "hidden";
|
| 18 |
inputUser.name = "username";
|
| 19 |
+
inputUser.value = "aguBido";
|
| 20 |
|
| 21 |
actionForm.appendChild(inputAction);
|
| 22 |
actionForm.appendChild(inputUser);
|
tecnicas/templates/tecnicas/cata-login.html
CHANGED
|
@@ -47,6 +47,6 @@
|
|
| 47 |
const error = document.querySelector(".ct-notification-error")
|
| 48 |
setTimeout(() => {
|
| 49 |
error.classList.add("hidden")
|
| 50 |
-
},
|
| 51 |
</script>
|
| 52 |
{% endblock %}
|
|
|
|
| 47 |
const error = document.querySelector(".ct-notification-error")
|
| 48 |
setTimeout(() => {
|
| 49 |
error.classList.add("hidden")
|
| 50 |
+
}, 4000)
|
| 51 |
</script>
|
| 52 |
{% endblock %}
|
tecnicas/templates/tecnicas/forms_tester/main_tester.html
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends 'tecnicas/layouts/base.html' %}
|
| 2 |
+
|
| 3 |
+
{% block title %}Detalles Sesion{% endblock %}
|
| 4 |
+
|
| 5 |
+
{% block content %}
|
| 6 |
+
<article class="w-full flex flex-col justify-center items-center bg-gray-600 mt-10 mb-10">
|
| 7 |
+
<article class="flex flex-col gap-8 bg-gray-400 p-10 rounded-2xl">
|
| 8 |
+
<header class="text-center flex-row w-full flex justify-around items-center flex-wrap gap-10">
|
| 9 |
+
<h1 class="text-white rounded-xl font-bold text-2xl bg-gray-600 p-4 flex-1">
|
| 10 |
+
Detalles de la sesión
|
| 11 |
+
</h1>
|
| 12 |
+
</header>
|
| 13 |
+
</article>
|
| 14 |
+
</article>
|
| 15 |
+
{% endblock %}
|
tecnicas/templates/tecnicas/manage_sesions/detalles-sesion.html
CHANGED
|
@@ -26,6 +26,14 @@
|
|
| 26 |
</article>
|
| 27 |
{% endif %}
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
<p class="font-bold text-2xl border-b-2">
|
| 30 |
Información general
|
| 31 |
</p>
|
|
@@ -149,6 +157,14 @@
|
|
| 149 |
<img src="{% static 'img/giro.svg' %}" alt="flechas girando" class="invert">
|
| 150 |
</figure>
|
| 151 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
{% endif %}
|
| 153 |
|
| 154 |
<button
|
|
|
|
| 26 |
</article>
|
| 27 |
{% endif %}
|
| 28 |
|
| 29 |
+
{% if message %}
|
| 30 |
+
<article class="bg-green-600 p-4 text-white rounded-xl ct-notification-error">
|
| 31 |
+
<p class="block font-sans text-white text-xl antialiased font-bold uppercase tracking-wider text-center">
|
| 32 |
+
{{ error }}
|
| 33 |
+
</p>
|
| 34 |
+
</article>
|
| 35 |
+
{% endif %}
|
| 36 |
+
|
| 37 |
<p class="font-bold text-2xl border-b-2">
|
| 38 |
Información general
|
| 39 |
</p>
|
|
|
|
| 157 |
<img src="{% static 'img/giro.svg' %}" alt="flechas girando" class="invert">
|
| 158 |
</figure>
|
| 159 |
</button>
|
| 160 |
+
{% else %}
|
| 161 |
+
<button
|
| 162 |
+
class="ct-btn-start-repition flex-1 uppercase text-lg tracking-wider p-4 border-b-2 active:border-b-0 active:border-t-2 active:border-orange-500 border-orange-800 transition-all rounded-xl bg-orange-600 text-white font-bold disabled:bg-amber-600 flex flex-col justify-center items-center gap-2">
|
| 163 |
+
Monitorear repetición
|
| 164 |
+
<figure class="w-10">
|
| 165 |
+
<img src="{% static 'img/giro.svg' %}" alt="flechas girando" class="invert">
|
| 166 |
+
</figure>
|
| 167 |
+
</button>
|
| 168 |
{% endif %}
|
| 169 |
|
| 170 |
<button
|
tecnicas/urls.py
CHANGED
|
@@ -12,10 +12,6 @@ urlpatterns = [
|
|
| 12 |
views.autentication,
|
| 13 |
name="autenticacion"),
|
| 14 |
|
| 15 |
-
path("catador-login",
|
| 16 |
-
views.testerLogin,
|
| 17 |
-
name="catador_login"),
|
| 18 |
-
|
| 19 |
|
| 20 |
# Gestion de catadores
|
| 21 |
path("panel-catadores",
|
|
@@ -67,6 +63,15 @@ urlpatterns = [
|
|
| 67 |
name="detalles_sesion"),
|
| 68 |
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# APIs
|
| 71 |
path("nueva-etiqueta",
|
| 72 |
views.newTag,
|
|
|
|
| 12 |
views.autentication,
|
| 13 |
name="autenticacion"),
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Gestion de catadores
|
| 17 |
path("panel-catadores",
|
|
|
|
| 63 |
name="detalles_sesion"),
|
| 64 |
|
| 65 |
|
| 66 |
+
# Vistas para catadores
|
| 67 |
+
path("catador-login",
|
| 68 |
+
views.testerLogin,
|
| 69 |
+
name="catador_login"),
|
| 70 |
+
|
| 71 |
+
path("catador-main",
|
| 72 |
+
views.mainTesterForm,
|
| 73 |
+
name="catador_main"),
|
| 74 |
+
|
| 75 |
# APIs
|
| 76 |
path("nueva-etiqueta",
|
| 77 |
views.newTag,
|
tecnicas/views/__init__.py
CHANGED
|
@@ -18,3 +18,5 @@ from .tester_management.tester_search import testerSearch
|
|
| 18 |
|
| 19 |
from .apis.api_tag import newTag
|
| 20 |
from .apis.api_words import words
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
from .apis.api_tag import newTag
|
| 20 |
from .apis.api_words import words
|
| 21 |
+
|
| 22 |
+
from .tester_forms.main_tester_form import mainTesterForm
|
tecnicas/views/login_tester.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
-
from django.shortcuts import render
|
|
|
|
| 3 |
from ..utils import general_error
|
| 4 |
from ..controllers import LoginTesterController
|
| 5 |
|
|
@@ -30,5 +31,6 @@ def testerLogin(req: HttpRequest):
|
|
| 30 |
req.session["code_session"] = session_code
|
| 31 |
|
| 32 |
req.session.set_expiry(20*60)
|
|
|
|
| 33 |
else:
|
| 34 |
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 ..utils import general_error
|
| 5 |
from ..controllers import LoginTesterController
|
| 6 |
|
|
|
|
| 31 |
req.session["code_session"] = session_code
|
| 32 |
|
| 33 |
req.session.set_expiry(20*60)
|
| 34 |
+
return redirect(reverse("cata_system:catador_main"))
|
| 35 |
else:
|
| 36 |
return render(req, "tecnicas/cata-login.html")
|
tecnicas/views/sessions_management/session_details.py
CHANGED
|
@@ -12,12 +12,12 @@ def sessionDetails(req: HttpRequest, session_code: str):
|
|
| 12 |
elif req.method == "POST":
|
| 13 |
if req.POST["action"] == "start_session":
|
| 14 |
response = DetallesSesionController.startRepetition(
|
| 15 |
-
session_code, req.POST
|
| 16 |
if isinstance(response, dict):
|
| 17 |
context["error"] = response["error"]
|
| 18 |
return render(req, "tecnicas/manage_sesions/detalles-sesion.html", context)
|
| 19 |
-
|
| 20 |
-
return
|
| 21 |
elif req.POST.get("action") == "delete_session":
|
| 22 |
pass
|
| 23 |
elif req.POST.get("action") == "monitor_session":
|
|
|
|
| 12 |
elif req.method == "POST":
|
| 13 |
if req.POST["action"] == "start_session":
|
| 14 |
response = DetallesSesionController.startRepetition(
|
| 15 |
+
session_code=session_code, username=req.POST["username"])
|
| 16 |
if isinstance(response, dict):
|
| 17 |
context["error"] = response["error"]
|
| 18 |
return render(req, "tecnicas/manage_sesions/detalles-sesion.html", context)
|
| 19 |
+
context["message"] = "La sesión ha iniciado"
|
| 20 |
+
return render(req, "tecnicas/manage_sesions/detalles-sesion.html", context)
|
| 21 |
elif req.POST.get("action") == "delete_session":
|
| 22 |
pass
|
| 23 |
elif req.POST.get("action") == "monitor_session":
|
tecnicas/views/tester_forms/main_tester_form.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest, JsonResponse
|
| 2 |
+
from django.shortcuts import render
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def mainTesterForm(req: HttpRequest):
|
| 6 |
+
if req.method == "POST":
|
| 7 |
+
return render(req, "tecnica/forms_tester/main_tester.html")
|
| 8 |
+
else:
|
| 9 |
+
return JsonResponse({"error": "metodo no permitido"})
|