Spaces:
Sleeping
Sleeping
Se craa funcionalidad para guardar la relacion entre etiquetas y escala
Browse files
tecnicas/admin.py
CHANGED
|
@@ -16,6 +16,9 @@ from .models import Palabra
|
|
| 16 |
|
| 17 |
from .models import Etiqueta
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
# Register your models here.
|
| 20 |
admin.site.register(CategoriaTecnica)
|
| 21 |
admin.site.register(TipoEscala)
|
|
@@ -30,4 +33,7 @@ admin.site.register(Tecnica)
|
|
| 30 |
admin.site.register(SesionSensorial)
|
| 31 |
|
| 32 |
admin.site.register(EsAtributo)
|
| 33 |
-
admin.site.register(Palabra)
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
from .models import Etiqueta
|
| 18 |
|
| 19 |
+
from .models import Escala
|
| 20 |
+
from .models import EtiquetasEscala
|
| 21 |
+
|
| 22 |
# Register your models here.
|
| 23 |
admin.site.register(CategoriaTecnica)
|
| 24 |
admin.site.register(TipoEscala)
|
|
|
|
| 33 |
admin.site.register(SesionSensorial)
|
| 34 |
|
| 35 |
admin.site.register(EsAtributo)
|
| 36 |
+
admin.site.register(Palabra)
|
| 37 |
+
|
| 38 |
+
admin.site.register(Escala)
|
| 39 |
+
admin.site.register(EtiquetasEscala)
|
tecnicas/controllers/escala_controller.py
CHANGED
|
@@ -1,65 +1,98 @@
|
|
| 1 |
-
from ..models import
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
class EscalaController():
|
| 5 |
-
|
| 6 |
scale: Escala
|
|
|
|
| 7 |
|
| 8 |
-
def __init__(self,
|
| 9 |
-
self.scale =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
def
|
| 12 |
-
self.scale = Escala
|
| 13 |
-
id_tipo_escala=
|
| 14 |
-
longitud=size,
|
| 15 |
-
tecnica=technique
|
| 16 |
)
|
| 17 |
|
| 18 |
-
def
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
|
| 23 |
-
start_point = EtiquetasEscala.objects.create(
|
| 24 |
-
id_escala=self.scale.id,
|
| 25 |
-
id_etiqueta=tag,
|
| 26 |
-
posicion=1
|
| 27 |
-
)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
posicion=3
|
| 41 |
-
)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
("
|
| 46 |
-
(
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
id_escala=self.scale.id,
|
| 59 |
-
id_etiqueta=
|
| 60 |
-
posicion=
|
| 61 |
)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..models import Etiqueta, EtiquetasEscala, Escala
|
| 2 |
+
from django.db import DatabaseError
|
| 3 |
|
| 4 |
|
| 5 |
class EscalaController():
|
|
|
|
| 6 |
scale: Escala
|
| 7 |
+
tags: list[tuple[str, EtiquetasEscala]]
|
| 8 |
|
| 9 |
+
def __init__(self, data):
|
| 10 |
+
self.scale = Escala(
|
| 11 |
+
id_tipo_escala=data["scale"],
|
| 12 |
+
longitud=data["size"],
|
| 13 |
+
tecnica=data["technique"]
|
| 14 |
+
)
|
| 15 |
|
| 16 |
+
def setScale(self, newData):
|
| 17 |
+
self.scale = Escala(
|
| 18 |
+
id_tipo_escala=newData["scale"],
|
| 19 |
+
longitud=newData["size"],
|
| 20 |
+
tecnica=newData["technique"]
|
| 21 |
)
|
| 22 |
|
| 23 |
+
def saveScale(self):
|
| 24 |
+
try:
|
| 25 |
+
self.scale.save()
|
| 26 |
+
except Exception:
|
| 27 |
+
return False
|
| 28 |
+
return self.scale
|
| 29 |
|
| 30 |
+
def deleteScale(self):
|
| 31 |
+
self.scale.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
def addAndSaveTags(self, tags: list):
|
| 34 |
+
if self.scale.id_tipo_escala.nombre_escala == "cotinua":
|
| 35 |
+
if not self.realte_tags_type_cotinue(tags):
|
| 36 |
+
return False
|
| 37 |
+
elif self.scale.id_tipo_escala.nombre_escala == "estructurada":
|
| 38 |
+
if not self.realte_tags_type_structure(tags):
|
| 39 |
+
return False
|
| 40 |
+
return self.tags
|
| 41 |
|
| 42 |
+
def deleteRelationshipsWithLabels(self):
|
| 43 |
+
for tuple in self.tags:
|
| 44 |
+
relaTag = tuple[1]
|
| 45 |
+
relaTag.adelete()
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
def realte_tags_type_cotinue(self, tags: list):
|
| 48 |
+
try:
|
| 49 |
+
tag_start = Etiqueta.objects.get(id=tags["punto_inicial"])
|
| 50 |
+
start_point = EtiquetasEscala.objects.create(
|
| 51 |
+
id_escala=self.scale.id,
|
| 52 |
+
id_etiqueta=tag_start,
|
| 53 |
+
posicion=1
|
| 54 |
+
)
|
| 55 |
|
| 56 |
+
self.tags.append(("start", start_point))
|
| 57 |
|
| 58 |
+
tag_medium = Etiqueta.objects.get(id=tags["punto_medio"])
|
| 59 |
+
half_point = EtiquetasEscala.objects.create(
|
| 60 |
+
id_escala=self.scale.id,
|
| 61 |
+
id_etiqueta=tag_medium,
|
| 62 |
+
posicion=2
|
| 63 |
+
)
|
| 64 |
|
| 65 |
+
self.tags.append(("medium", half_point))
|
| 66 |
+
|
| 67 |
+
tag_end = Etiqueta.objects.get(id=tags["punto_final"])
|
| 68 |
+
end_point = EtiquetasEscala.objects.create(
|
| 69 |
id_escala=self.scale.id,
|
| 70 |
+
id_etiqueta=tag_end,
|
| 71 |
+
posicion=3
|
| 72 |
)
|
| 73 |
+
|
| 74 |
+
self.tags.append(("end", end_point))
|
| 75 |
+
return True
|
| 76 |
+
except DatabaseError as error:
|
| 77 |
+
self.deleteRelationshipsWithLabels()
|
| 78 |
+
return False
|
| 79 |
+
|
| 80 |
+
def realte_tags_type_structure(self, tags: dict):
|
| 81 |
+
try:
|
| 82 |
+
index = 1
|
| 83 |
+
self.tags = []
|
| 84 |
+
|
| 85 |
+
for name, id_tag in tags.items():
|
| 86 |
+
tag = Etiqueta.objects.get(id=id_tag)
|
| 87 |
+
related_tag = EtiquetasEscala(
|
| 88 |
+
id_escala=self.scale.id,
|
| 89 |
+
id_etiqueta=tag,
|
| 90 |
+
posicion=index
|
| 91 |
+
)
|
| 92 |
+
self.tags.append((name, related_tag))
|
| 93 |
+
index += 1
|
| 94 |
+
|
| 95 |
+
return True
|
| 96 |
+
except DatabaseError as error:
|
| 97 |
+
self.deleteRelationshipsWithLabels()
|
| 98 |
+
return False
|
tecnicas/controllers/tecnica_controller.py
CHANGED
|
@@ -23,6 +23,16 @@ class TecnicaController():
|
|
| 23 |
def getDataTechnique(self):
|
| 24 |
return self.technique.toDict()
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
@staticmethod
|
| 27 |
def getTypesTechnique():
|
| 28 |
showTecnicas = {}
|
|
|
|
| 23 |
def getDataTechnique(self):
|
| 24 |
return self.technique.toDict()
|
| 25 |
|
| 26 |
+
def saveTechnique(self):
|
| 27 |
+
try:
|
| 28 |
+
self.technique.save()
|
| 29 |
+
except Exception:
|
| 30 |
+
return False
|
| 31 |
+
return self.technique
|
| 32 |
+
|
| 33 |
+
def deleteTechnique(self):
|
| 34 |
+
self.technique.delete()
|
| 35 |
+
|
| 36 |
@staticmethod
|
| 37 |
def getTypesTechnique():
|
| 38 |
showTecnicas = {}
|
tecnicas/models/escala.py
CHANGED
|
@@ -9,4 +9,4 @@ class Escala(models.Model):
|
|
| 9 |
tecnica = models.OneToOneField(Tecnica, on_delete=models.CASCADE, related_name="escala_tecnica")
|
| 10 |
|
| 11 |
def __str__(self):
|
| 12 |
-
return self.
|
|
|
|
| 9 |
tecnica = models.OneToOneField(Tecnica, on_delete=models.CASCADE, related_name="escala_tecnica")
|
| 10 |
|
| 11 |
def __str__(self):
|
| 12 |
+
return self.id_tipo_escala.nombre_escala
|
tecnicas/models/tecnica.py
CHANGED
|
@@ -15,7 +15,7 @@ class Tecnica(models.Model):
|
|
| 15 |
EstiloPalabra, on_delete=models.CASCADE, related_name="estilo_tecnica")
|
| 16 |
|
| 17 |
def __str__(self):
|
| 18 |
-
return self.tipo_tecnica
|
| 19 |
|
| 20 |
def toDict(self):
|
| 21 |
return {
|
|
|
|
| 15 |
EstiloPalabra, on_delete=models.CASCADE, related_name="estilo_tecnica")
|
| 16 |
|
| 17 |
def __str__(self):
|
| 18 |
+
return self.tipo_tecnica.nombre_tecnica
|
| 19 |
|
| 20 |
def toDict(self):
|
| 21 |
return {
|
tecnicas/static/js/create-session.js
CHANGED
|
@@ -3,7 +3,7 @@ const formSubmit = document.querySelector(".ct-cretae-session-form");
|
|
| 3 |
document.addEventListener("DOMContentLoaded", () => {
|
| 4 |
setTimeout(() => {
|
| 5 |
cretaeSession();
|
| 6 |
-
},
|
| 7 |
});
|
| 8 |
|
| 9 |
async function cretaeSession() {
|
|
|
|
| 3 |
document.addEventListener("DOMContentLoaded", () => {
|
| 4 |
setTimeout(() => {
|
| 5 |
cretaeSession();
|
| 6 |
+
}, 2000);
|
| 7 |
});
|
| 8 |
|
| 9 |
async function cretaeSession() {
|
tecnicas/views/create_session.py
CHANGED
|
@@ -2,8 +2,7 @@ from django.http import HttpRequest, JsonResponse
|
|
| 2 |
from django.shortcuts import render, redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from ..utils import general_error
|
| 5 |
-
from ..controllers import TecnicaController
|
| 6 |
-
from ..models import TipoTecnica, EstiloPalabra
|
| 7 |
|
| 8 |
|
| 9 |
def createSession(req: HttpRequest):
|
|
@@ -15,23 +14,37 @@ def createSession(req: HttpRequest):
|
|
| 15 |
req.session.flush()
|
| 16 |
return general_error("no se ha especificado informacion necesaria para la creacion de la sesion")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
data_basic = req.session["form_basic"]
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
print(controllTechnique.getDataTechnique())
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
'tamano_escala': 9,
|
| 36 |
-
'instrucciones': ''
|
| 37 |
-
}
|
|
|
|
| 2 |
from django.shortcuts import render, redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from ..utils import general_error
|
| 5 |
+
from ..controllers import TecnicaController, EscalaController
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def createSession(req: HttpRequest):
|
|
|
|
| 14 |
req.session.flush()
|
| 15 |
return general_error("no se ha especificado informacion necesaria para la creacion de la sesion")
|
| 16 |
|
| 17 |
+
# ////////////////////////////////////////////////////// #
|
| 18 |
+
#
|
| 19 |
+
# First step: Create technique and scale with their tags #
|
| 20 |
+
#
|
| 21 |
+
# ////////////////////////////////////////////////////// #
|
| 22 |
data_basic = req.session["form_basic"]
|
| 23 |
+
controllerTechnique = TecnicaController()
|
| 24 |
+
controllerTechnique.setTechniqueFromBasicData(basic=data_basic)
|
|
|
|
| 25 |
|
| 26 |
+
technique = controllerTechnique.saveTechnique()
|
| 27 |
+
if not technique:
|
| 28 |
+
return general_error("error al guardar la tecnica")
|
| 29 |
+
|
| 30 |
+
data_scale = {
|
| 31 |
+
"scale": data_basic["tipo_escala"],
|
| 32 |
+
"size": data_basic["tamano_escala"],
|
| 33 |
+
"technique": technique
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
controllerScale = EscalaController(data=data_scale)
|
| 37 |
|
| 38 |
+
scale = controllerScale.saveScale()
|
| 39 |
+
if not scale:
|
| 40 |
+
controllerTechnique.deleteTechnique()
|
| 41 |
+
return general_error("error al guardar la escala, datos agregados previeamante borrados")
|
| 42 |
|
| 43 |
+
list_tags = req.session["form_tags"]
|
| 44 |
+
|
| 45 |
+
saved_tags = controllerScale.addAndSaveTags(list_tags)
|
| 46 |
+
if not saved_tags:
|
| 47 |
+
return general_error("error al guardar asociar escalas, datos agregados previeamante borrados")
|
| 48 |
+
|
| 49 |
+
return JsonResponse({"message": "sesion creada", "data": {"session_id": "asd548ad4a"}})
|
| 50 |
+
return general_error("ha orcurrido un error inesperado")
|
|
|
|
|
|
|
|
|