Spaces:
Sleeping
Sleeping
Creacion de session sensorial escalas
Browse files- tecnicas/admin.py +5 -1
- tecnicas/controllers/__init__.py +1 -0
- tecnicas/controllers/escala_controller.py +28 -56
- tecnicas/controllers/estilo_palabras_controller.py +2 -2
- tecnicas/controllers/ordenes_controller.py +33 -40
- tecnicas/controllers/palabras_controller.py +1 -1
- tecnicas/controllers/productos_controller.py +7 -9
- tecnicas/controllers/sesion_controller.py +41 -0
- tecnicas/controllers/tecnica_controller.py +5 -3
- tecnicas/migrations/0013_alter_sesionsensorial_codigo_sesion_and_more.py +24 -0
- tecnicas/migrations/0014_alter_sesionsensorial_codigo_sesion_and_more.py +25 -0
- tecnicas/models/etiquetas_escala.py +10 -5
- tecnicas/models/orden.py +7 -1
- tecnicas/models/sesion_sensorial.py +11 -7
- tecnicas/models/tecnica.py +1 -1
- tecnicas/static/js/create-session.js +30 -13
- tecnicas/static/js/panel-codes.js +14 -1
- tecnicas/views/configuration_panel_basic.py +11 -2
- tecnicas/views/configuration_panel_tags.py +9 -6
- tecnicas/views/create_session.py +71 -23
tecnicas/admin.py
CHANGED
|
@@ -19,6 +19,8 @@ from .models import Etiqueta
|
|
| 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)
|
|
@@ -36,4 +38,6 @@ admin.site.register(EsAtributo)
|
|
| 36 |
admin.site.register(Palabra)
|
| 37 |
|
| 38 |
admin.site.register(Escala)
|
| 39 |
-
admin.site.register(EtiquetasEscala)
|
|
|
|
|
|
|
|
|
| 19 |
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)
|
| 26 |
admin.site.register(TipoEscala)
|
|
|
|
| 38 |
admin.site.register(Palabra)
|
| 39 |
|
| 40 |
admin.site.register(Escala)
|
| 41 |
+
admin.site.register(EtiquetasEscala)
|
| 42 |
+
|
| 43 |
+
admin.site.register(Producto)
|
tecnicas/controllers/__init__.py
CHANGED
|
@@ -5,3 +5,4 @@ from .ordenes_controller import OrdenesController
|
|
| 5 |
from .palabras_controller import PalabrasController
|
| 6 |
from .estilo_palabras_controller import EstiloPalabrasController
|
| 7 |
from .palabras_controller import PalabrasController
|
|
|
|
|
|
| 5 |
from .palabras_controller import PalabrasController
|
| 6 |
from .estilo_palabras_controller import EstiloPalabrasController
|
| 7 |
from .palabras_controller import PalabrasController
|
| 8 |
+
from .sesion_controller import SesionController
|
tecnicas/controllers/escala_controller.py
CHANGED
|
@@ -1,21 +1,22 @@
|
|
| 1 |
-
from ..models import Etiqueta, EtiquetasEscala, Escala
|
| 2 |
from django.db import DatabaseError
|
|
|
|
| 3 |
|
| 4 |
|
| 5 |
class EscalaController():
|
| 6 |
scale: Escala
|
| 7 |
-
|
| 8 |
|
| 9 |
def __init__(self, data):
|
| 10 |
self.scale = Escala(
|
| 11 |
-
id_tipo_escala=data["
|
| 12 |
longitud=data["size"],
|
| 13 |
tecnica=data["technique"]
|
| 14 |
)
|
| 15 |
|
| 16 |
def setScale(self, newData):
|
| 17 |
self.scale = Escala(
|
| 18 |
-
id_tipo_escala=newData["
|
| 19 |
longitud=newData["size"],
|
| 20 |
tecnica=newData["technique"]
|
| 21 |
)
|
|
@@ -23,76 +24,47 @@ class EscalaController():
|
|
| 23 |
def saveScale(self):
|
| 24 |
try:
|
| 25 |
self.scale.save()
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
def deleteScale(self):
|
| 31 |
self.scale.delete()
|
| 32 |
|
| 33 |
-
def addAndSaveTags(self, tags:
|
|
|
|
| 34 |
if self.scale.id_tipo_escala.nombre_escala == "cotinua":
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
elif self.scale.id_tipo_escala.nombre_escala == "estructurada":
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
def deleteRelationshipsWithLabels(self):
|
| 43 |
-
for
|
| 44 |
-
|
| 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
|
| 81 |
try:
|
| 82 |
index = 1
|
| 83 |
-
self.
|
| 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
|
| 89 |
id_etiqueta=tag,
|
| 90 |
posicion=index
|
| 91 |
)
|
| 92 |
-
self.
|
| 93 |
index += 1
|
| 94 |
|
| 95 |
-
return
|
| 96 |
except DatabaseError as error:
|
| 97 |
self.deleteRelationshipsWithLabels()
|
| 98 |
-
return
|
|
|
|
| 1 |
+
from ..models import Etiqueta, EtiquetasEscala, Escala, TipoEscala
|
| 2 |
from django.db import DatabaseError
|
| 3 |
+
from ..utils import controller_error
|
| 4 |
|
| 5 |
|
| 6 |
class EscalaController():
|
| 7 |
scale: Escala
|
| 8 |
+
tags_relation: dict[str, EtiquetasEscala]
|
| 9 |
|
| 10 |
def __init__(self, data):
|
| 11 |
self.scale = Escala(
|
| 12 |
+
id_tipo_escala=TipoEscala.objects.get(id=data["id_scale"]),
|
| 13 |
longitud=data["size"],
|
| 14 |
tecnica=data["technique"]
|
| 15 |
)
|
| 16 |
|
| 17 |
def setScale(self, newData):
|
| 18 |
self.scale = Escala(
|
| 19 |
+
id_tipo_escala=TipoEscala.objects.get(id=newData["id_scale"]),
|
| 20 |
longitud=newData["size"],
|
| 21 |
tecnica=newData["technique"]
|
| 22 |
)
|
|
|
|
| 24 |
def saveScale(self):
|
| 25 |
try:
|
| 26 |
self.scale.save()
|
| 27 |
+
return self.scale
|
| 28 |
+
except DatabaseError as error:
|
| 29 |
+
return controller_error("error al guardar la escala")
|
| 30 |
|
| 31 |
def deleteScale(self):
|
| 32 |
self.scale.delete()
|
| 33 |
|
| 34 |
+
def addAndSaveTags(self, tags: dict):
|
| 35 |
+
self.tags_relation = {}
|
| 36 |
if self.scale.id_tipo_escala.nombre_escala == "cotinua":
|
| 37 |
+
ok_tags = self.realte_tags_type_cotinue(tags)
|
| 38 |
+
if ok_tags["error"]:
|
| 39 |
+
return ok_tags
|
| 40 |
+
return self.tags_relation
|
| 41 |
+
|
| 42 |
elif self.scale.id_tipo_escala.nombre_escala == "estructurada":
|
| 43 |
+
ok_tags = self.realte_tags_type_structure(tags)
|
| 44 |
+
if ok_tags["error"]:
|
| 45 |
+
return ok_tags
|
| 46 |
+
return self.tags_relation
|
| 47 |
|
| 48 |
def deleteRelationshipsWithLabels(self):
|
| 49 |
+
for name, tag in self.tags_relation.items():
|
| 50 |
+
tag.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
def realteTags(self, tags: dict):
|
| 53 |
try:
|
| 54 |
index = 1
|
| 55 |
+
self.tags_relation = {}
|
| 56 |
|
| 57 |
for name, id_tag in tags.items():
|
| 58 |
tag = Etiqueta.objects.get(id=id_tag)
|
| 59 |
+
related_tag = EtiquetasEscala.objects.create(
|
| 60 |
+
id_escala=self.scale,
|
| 61 |
id_etiqueta=tag,
|
| 62 |
posicion=index
|
| 63 |
)
|
| 64 |
+
self.tags_relation[name] = related_tag
|
| 65 |
index += 1
|
| 66 |
|
| 67 |
+
return self.tags_relation
|
| 68 |
except DatabaseError as error:
|
| 69 |
self.deleteRelationshipsWithLabels()
|
| 70 |
+
return controller_error("error guardar relacion etiqueta escala")
|
tecnicas/controllers/estilo_palabras_controller.py
CHANGED
|
@@ -20,7 +20,7 @@ class EstiloPalabrasController():
|
|
| 20 |
id_tecnica=self.technique)
|
| 21 |
return self.instanceStyle
|
| 22 |
except DatabaseError as error:
|
| 23 |
-
return controller_error(error)
|
| 24 |
|
| 25 |
def relatedWords(self):
|
| 26 |
if not self.list_words:
|
|
@@ -29,4 +29,4 @@ class EstiloPalabrasController():
|
|
| 29 |
self.instanceStyle.palabras.add(*self.list_words)
|
| 30 |
return self.instanceStyle.palabras
|
| 31 |
except DatabaseError as error:
|
| 32 |
-
return controller_error(error)
|
|
|
|
| 20 |
id_tecnica=self.technique)
|
| 21 |
return self.instanceStyle
|
| 22 |
except DatabaseError as error:
|
| 23 |
+
return controller_error("error al registrar el estilo con tecnica")
|
| 24 |
|
| 25 |
def relatedWords(self):
|
| 26 |
if not self.list_words:
|
|
|
|
| 29 |
self.instanceStyle.palabras.add(*self.list_words)
|
| 30 |
return self.instanceStyle.palabras
|
| 31 |
except DatabaseError as error:
|
| 32 |
+
return controller_error("error al relacionar palabras con el estilo tecnica")
|
tecnicas/controllers/ordenes_controller.py
CHANGED
|
@@ -6,78 +6,71 @@ from django.db import DatabaseError
|
|
| 6 |
class OrdenesController():
|
| 7 |
products: list[Producto]
|
| 8 |
technique: Tecnica
|
| 9 |
-
raw_list_orders: list[
|
| 10 |
orders: list[Orden]
|
| 11 |
-
orders_save: list[Orden]
|
| 12 |
positions: list[Posicion]
|
| 13 |
-
savePostions: list[Posicion]
|
| 14 |
|
| 15 |
-
def __init__(self, raw_orders: list[
|
| 16 |
self.products = list_products
|
| 17 |
self.technique = technique
|
| 18 |
self.raw_list_orders = raw_orders
|
| 19 |
|
| 20 |
-
def
|
| 21 |
-
self.
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
self.orders.append(Orden(id_tecnica=self.technique))
|
| 25 |
|
| 26 |
def saveOrders(self):
|
| 27 |
if not self.orders:
|
| 28 |
return controller_error("no se han establecido las ordenes para guardar")
|
| 29 |
try:
|
| 30 |
-
|
| 31 |
-
|
|
|
|
| 32 |
except DatabaseError as error:
|
| 33 |
-
return controller_error(error)
|
| 34 |
|
| 35 |
def setPositions(self):
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
if len(self.orders_save) != len(self.raw_list_orders):
|
| 42 |
return controller_error("el numero de ordenes guardados no coinciden con los recibidos")
|
| 43 |
|
| 44 |
self.positions = []
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
codes_raw_orders = [next(iter(position.values()))
|
| 48 |
-
for position in raw_order]
|
| 49 |
-
|
| 50 |
-
if not set(codes_raw_orders) == set(codes_expect):
|
| 51 |
-
self.positions = []
|
| 52 |
return controller_error("las ordenes mandadas no contienen los productos esperados")
|
| 53 |
|
| 54 |
-
for
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
locate_code_id = [
|
| 59 |
-
code_id for code_id in codes_ids if code in code_id]
|
| 60 |
|
| 61 |
-
if
|
| 62 |
-
return controller_error("no
|
| 63 |
-
else:
|
| 64 |
-
locate_code_id = locate_code_id[0]
|
| 65 |
|
|
|
|
| 66 |
new_position = Posicion(
|
| 67 |
-
id_producto=
|
| 68 |
-
id_orden=self.
|
| 69 |
-
posicion=
|
| 70 |
)
|
| 71 |
-
|
| 72 |
self.positions.append(new_position)
|
| 73 |
-
|
| 74 |
return self.positions
|
| 75 |
|
| 76 |
-
def
|
| 77 |
if not self.positions:
|
| 78 |
return controller_error("no se han establecido posiciones para guargar")
|
| 79 |
try:
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
except DatabaseError as error:
|
| 83 |
-
return controller_error(error)
|
|
|
|
| 6 |
class OrdenesController():
|
| 7 |
products: list[Producto]
|
| 8 |
technique: Tecnica
|
| 9 |
+
raw_list_orders: list[dict]
|
| 10 |
orders: list[Orden]
|
|
|
|
| 11 |
positions: list[Posicion]
|
|
|
|
| 12 |
|
| 13 |
+
def __init__(self, raw_orders: list[dict], list_products: list[Producto], technique: Tecnica):
|
| 14 |
self.products = list_products
|
| 15 |
self.technique = technique
|
| 16 |
self.raw_list_orders = raw_orders
|
| 17 |
|
| 18 |
+
def serRawOrders(self, new_raw_orders: list[dict]):
|
| 19 |
+
self.raw_list_orders = new_raw_orders
|
| 20 |
|
| 21 |
+
def setOrdersToSave(self):
|
| 22 |
+
self.orders = []
|
| 23 |
+
for raw in self.raw_list_orders:
|
| 24 |
self.orders.append(Orden(id_tecnica=self.technique))
|
| 25 |
|
| 26 |
def saveOrders(self):
|
| 27 |
if not self.orders:
|
| 28 |
return controller_error("no se han establecido las ordenes para guardar")
|
| 29 |
try:
|
| 30 |
+
for order in self.orders:
|
| 31 |
+
order.save()
|
| 32 |
+
return self.orders
|
| 33 |
except DatabaseError as error:
|
| 34 |
+
return controller_error("error al guardar las ordenes")
|
| 35 |
|
| 36 |
def setPositions(self):
|
| 37 |
+
codes_ids_products = {}
|
| 38 |
+
for product in self.products:
|
| 39 |
+
codes_ids_products[product.codigoProducto] = product.id
|
| 40 |
+
codes_expect = list(codes_ids_products.keys())
|
| 41 |
|
| 42 |
+
if len(self.orders) != len(self.raw_list_orders):
|
|
|
|
|
|
|
| 43 |
return controller_error("el numero de ordenes guardados no coinciden con los recibidos")
|
| 44 |
|
| 45 |
self.positions = []
|
| 46 |
+
for index, order in enumerate(self.raw_list_orders):
|
| 47 |
+
received_codes_order = list(order.keys())
|
| 48 |
|
| 49 |
+
if set(received_codes_order) != set(codes_expect):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return controller_error("las ordenes mandadas no contienen los productos esperados")
|
| 51 |
|
| 52 |
+
for name, position_index in order.items():
|
| 53 |
+
list_product_use = [product for product in self.products
|
| 54 |
+
if product.codigoProducto == name]
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
if len(list_product_use) != 1:
|
| 57 |
+
return controller_error("no pueden existir dos productos que ocupen la misma posicion de un orden")
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
product_use = list_product_use[0]
|
| 60 |
new_position = Posicion(
|
| 61 |
+
id_producto=product_use,
|
| 62 |
+
id_orden=self.orders[index],
|
| 63 |
+
posicion=position_index
|
| 64 |
)
|
|
|
|
| 65 |
self.positions.append(new_position)
|
|
|
|
| 66 |
return self.positions
|
| 67 |
|
| 68 |
+
def savePositions(self):
|
| 69 |
if not self.positions:
|
| 70 |
return controller_error("no se han establecido posiciones para guargar")
|
| 71 |
try:
|
| 72 |
+
for position in self.positions:
|
| 73 |
+
position.save()
|
| 74 |
+
return self.positions
|
| 75 |
except DatabaseError as error:
|
| 76 |
+
return controller_error("error al guardar las posiciones")
|
tecnicas/controllers/palabras_controller.py
CHANGED
|
@@ -22,4 +22,4 @@ class PalabrasController():
|
|
| 22 |
self.words = searched_words
|
| 23 |
return self.words
|
| 24 |
except DatabaseError as error:
|
| 25 |
-
return controller_error(error)
|
|
|
|
| 22 |
self.words = searched_words
|
| 23 |
return self.words
|
| 24 |
except DatabaseError as error:
|
| 25 |
+
return controller_error("error al guardar buscar palabras")
|
tecnicas/controllers/productos_controller.py
CHANGED
|
@@ -9,14 +9,11 @@ class ProductosController():
|
|
| 9 |
technique: Tecnica
|
| 10 |
|
| 11 |
def __init__(self, codes: list[str], technique: Tecnica):
|
| 12 |
-
|
| 13 |
-
self.list_codes.append(code)
|
| 14 |
-
|
| 15 |
self.technique = technique
|
| 16 |
|
| 17 |
-
def setListCodes(self,
|
| 18 |
-
|
| 19 |
-
self.list_codes.append(code)
|
| 20 |
|
| 21 |
def setTechnique(self, technique: Tecnica):
|
| 22 |
self.technique = technique
|
|
@@ -35,7 +32,8 @@ class ProductosController():
|
|
| 35 |
return controller_error("no se han establecido los productos para guardar")
|
| 36 |
|
| 37 |
try:
|
| 38 |
-
|
| 39 |
-
|
|
|
|
| 40 |
except DatabaseError as error:
|
| 41 |
-
return controller_error(error)
|
|
|
|
| 9 |
technique: Tecnica
|
| 10 |
|
| 11 |
def __init__(self, codes: list[str], technique: Tecnica):
|
| 12 |
+
self.list_codes = codes
|
|
|
|
|
|
|
| 13 |
self.technique = technique
|
| 14 |
|
| 15 |
+
def setListCodes(self, new_codes: list[str]):
|
| 16 |
+
self.list_codes = new_codes
|
|
|
|
| 17 |
|
| 18 |
def setTechnique(self, technique: Tecnica):
|
| 19 |
self.technique = technique
|
|
|
|
| 32 |
return controller_error("no se han establecido los productos para guardar")
|
| 33 |
|
| 34 |
try:
|
| 35 |
+
for product in self.list_product:
|
| 36 |
+
product.save()
|
| 37 |
+
return self.list_product
|
| 38 |
except DatabaseError as error:
|
| 39 |
+
return controller_error("error al guardar los productos")
|
tecnicas/controllers/sesion_controller.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import DatabaseError
|
| 2 |
+
from ..models import Tecnica, Presentador, SesionSensorial
|
| 3 |
+
from ..utils import controller_error
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class SesionController():
|
| 7 |
+
def __init__(self, name_session: str, technique: Tecnica, creator: Presentador):
|
| 8 |
+
self.name_session = name_session or None
|
| 9 |
+
self.technique = technique or None
|
| 10 |
+
self.presenter = creator or None
|
| 11 |
+
|
| 12 |
+
def setData(self, name_session: str, technique: Tecnica, creator: Presentador):
|
| 13 |
+
self.name_session = name_session
|
| 14 |
+
self.technique = technique
|
| 15 |
+
self.presenter = creator
|
| 16 |
+
|
| 17 |
+
def setSession(self):
|
| 18 |
+
if not self.presenter:
|
| 19 |
+
return controller_error("se requiere presentador para crear sesion")
|
| 20 |
+
elif not self.technique:
|
| 21 |
+
return controller_error("se requiere tecnica para crear sesion")
|
| 22 |
+
|
| 23 |
+
self.sensorial_session = SesionSensorial(
|
| 24 |
+
tecnica=self.technique,
|
| 25 |
+
creadoPor=self.presenter,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if self.name_session != "":
|
| 29 |
+
self.sensorial_session.nombre_sesion = self.name_session
|
| 30 |
+
|
| 31 |
+
return self.sensorial_session
|
| 32 |
+
|
| 33 |
+
def saveSession(self):
|
| 34 |
+
if not self.sensorial_session:
|
| 35 |
+
return controller_error("no se ha definido la sesion a guardar")
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
self.sensorial_session.save()
|
| 39 |
+
return self.sensorial_session
|
| 40 |
+
except DatabaseError as error:
|
| 41 |
+
return controller_error("Error al crear la session sensorial")
|
tecnicas/controllers/tecnica_controller.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
from ..models import TipoTecnica, CategoriaTecnica, Tecnica, EstiloPalabra
|
|
|
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
class TecnicaController():
|
|
@@ -26,9 +28,9 @@ class TecnicaController():
|
|
| 26 |
def saveTechnique(self):
|
| 27 |
try:
|
| 28 |
self.technique.save()
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
def deleteTechnique(self):
|
| 34 |
self.technique.delete()
|
|
|
|
| 1 |
from ..models import TipoTecnica, CategoriaTecnica, Tecnica, EstiloPalabra
|
| 2 |
+
from django.db import DatabaseError
|
| 3 |
+
from ..utils import controller_error
|
| 4 |
|
| 5 |
|
| 6 |
class TecnicaController():
|
|
|
|
| 28 |
def saveTechnique(self):
|
| 29 |
try:
|
| 30 |
self.technique.save()
|
| 31 |
+
return self.technique
|
| 32 |
+
except DatabaseError:
|
| 33 |
+
return controller_error("No se ha podido guardar la tecnica")
|
| 34 |
|
| 35 |
def deleteTechnique(self):
|
| 36 |
self.technique.delete()
|
tecnicas/migrations/0013_alter_sesionsensorial_codigo_sesion_and_more.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Generated by Django 5.2.1 on 2025-09-09 21:05
|
| 2 |
+
|
| 3 |
+
import shortuuid.main
|
| 4 |
+
from django.db import migrations, models
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class Migration(migrations.Migration):
|
| 8 |
+
|
| 9 |
+
dependencies = [
|
| 10 |
+
('tecnicas', '0012_alter_sesionsensorial_codigo_sesion_and_more'),
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
operations = [
|
| 14 |
+
migrations.AlterField(
|
| 15 |
+
model_name='sesionsensorial',
|
| 16 |
+
name='codigo_sesion',
|
| 17 |
+
field=models.CharField(default=shortuuid.main.ShortUUID.uuid, editable=False, max_length=22, primary_key=True, serialize=False),
|
| 18 |
+
),
|
| 19 |
+
migrations.AlterField(
|
| 20 |
+
model_name='sesionsensorial',
|
| 21 |
+
name='fechaCreacion',
|
| 22 |
+
field=models.DateTimeField(auto_created=True),
|
| 23 |
+
),
|
| 24 |
+
]
|
tecnicas/migrations/0014_alter_sesionsensorial_codigo_sesion_and_more.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Generated by Django 5.2.1 on 2025-09-10 00:04
|
| 2 |
+
|
| 3 |
+
import django.utils.timezone
|
| 4 |
+
import shortuuid.main
|
| 5 |
+
from django.db import migrations, models
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class Migration(migrations.Migration):
|
| 9 |
+
|
| 10 |
+
dependencies = [
|
| 11 |
+
('tecnicas', '0013_alter_sesionsensorial_codigo_sesion_and_more'),
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
operations = [
|
| 15 |
+
migrations.AlterField(
|
| 16 |
+
model_name='sesionsensorial',
|
| 17 |
+
name='codigo_sesion',
|
| 18 |
+
field=models.CharField(default=shortuuid.main.ShortUUID.uuid, editable=False, max_length=22, primary_key=True, serialize=False),
|
| 19 |
+
),
|
| 20 |
+
migrations.AlterField(
|
| 21 |
+
model_name='sesionsensorial',
|
| 22 |
+
name='fechaCreacion',
|
| 23 |
+
field=models.DateTimeField(default=django.utils.timezone.now),
|
| 24 |
+
),
|
| 25 |
+
]
|
tecnicas/models/etiquetas_escala.py
CHANGED
|
@@ -1,11 +1,16 @@
|
|
| 1 |
from django.db import models
|
| 2 |
-
|
| 3 |
from .escala import Escala
|
| 4 |
from .etiqueta import Etiqueta
|
| 5 |
|
|
|
|
| 6 |
class EtiquetasEscala(models.Model):
|
| 7 |
-
id_escala = models.ForeignKey(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
posicion = models.IntegerField()
|
|
|
|
| 1 |
from django.db import models
|
|
|
|
| 2 |
from .escala import Escala
|
| 3 |
from .etiqueta import Etiqueta
|
| 4 |
|
| 5 |
+
|
| 6 |
class EtiquetasEscala(models.Model):
|
| 7 |
+
id_escala = models.ForeignKey(
|
| 8 |
+
Escala, on_delete=models.CASCADE, related_name="escalas_etiqutas_escala")
|
| 9 |
+
|
| 10 |
+
id_etiqueta = models.ForeignKey(
|
| 11 |
+
Etiqueta, on_delete=models.CASCADE, related_name="etiqueta_etiquetas_escala")
|
| 12 |
+
|
| 13 |
+
posicion = models.IntegerField()
|
| 14 |
|
| 15 |
+
def __str__(self):
|
| 16 |
+
return f"Escala {self.id_escala.id}, {self.id_etiqueta.valor_etiqueta}, posicion {self.posicion}"
|
|
|
tecnicas/models/orden.py
CHANGED
|
@@ -8,7 +8,13 @@ class Orden(models.Model):
|
|
| 8 |
id_tecnica = models.ForeignKey(Tecnica, on_delete=models.CASCADE, related_name="orden_tecnica")
|
| 9 |
id_catador = models.ForeignKey(Catador, on_delete=models.CASCADE, related_name="orden_catador", null=True)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
class Posicion(models.Model):
|
| 12 |
id_producto = models.ForeignKey(Producto, on_delete=models.CASCADE, related_name="posicion_producto")
|
| 13 |
id_orden = models.ForeignKey(Orden, on_delete=models.CASCADE, related_name="posicion_orden")
|
| 14 |
-
posicion = models.IntegerField()
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
id_tecnica = models.ForeignKey(Tecnica, on_delete=models.CASCADE, related_name="orden_tecnica")
|
| 9 |
id_catador = models.ForeignKey(Catador, on_delete=models.CASCADE, related_name="orden_catador", null=True)
|
| 10 |
|
| 11 |
+
def __str__(self):
|
| 12 |
+
return f"Orden ID: {self.id}"
|
| 13 |
+
|
| 14 |
class Posicion(models.Model):
|
| 15 |
id_producto = models.ForeignKey(Producto, on_delete=models.CASCADE, related_name="posicion_producto")
|
| 16 |
id_orden = models.ForeignKey(Orden, on_delete=models.CASCADE, related_name="posicion_orden")
|
| 17 |
+
posicion = models.IntegerField()
|
| 18 |
+
|
| 19 |
+
def __str__(self):
|
| 20 |
+
return f"Posicion ID: {self.id}"
|
tecnicas/models/sesion_sensorial.py
CHANGED
|
@@ -1,16 +1,20 @@
|
|
| 1 |
-
import shortuuid
|
| 2 |
from django.db import models
|
| 3 |
-
|
| 4 |
from .presentador import Presentador
|
| 5 |
from .tecnica import Tecnica
|
|
|
|
|
|
|
| 6 |
|
| 7 |
class SesionSensorial(models.Model):
|
| 8 |
-
codigo_sesion =
|
|
|
|
| 9 |
nombre_sesion = models.CharField(max_length=255, null=True)
|
| 10 |
-
fechaCreacion = models.DateTimeField(
|
| 11 |
activo = models.BooleanField(default=False)
|
| 12 |
-
creadoPor = models.ForeignKey(
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def __str__(self):
|
| 16 |
-
return self.codigo_sesion
|
|
|
|
|
|
|
| 1 |
from django.db import models
|
| 2 |
+
from django.utils import timezone
|
| 3 |
from .presentador import Presentador
|
| 4 |
from .tecnica import Tecnica
|
| 5 |
+
import shortuuid
|
| 6 |
+
|
| 7 |
|
| 8 |
class SesionSensorial(models.Model):
|
| 9 |
+
codigo_sesion = models.CharField(
|
| 10 |
+
primary_key=True, default=shortuuid.uuid, editable=False, max_length=22)
|
| 11 |
nombre_sesion = models.CharField(max_length=255, null=True)
|
| 12 |
+
fechaCreacion = models.DateTimeField(default=timezone.now)
|
| 13 |
activo = models.BooleanField(default=False)
|
| 14 |
+
creadoPor = models.ForeignKey(
|
| 15 |
+
Presentador, on_delete=models.CASCADE, related_name="presentador_sesion")
|
| 16 |
+
tecnica = models.OneToOneField(
|
| 17 |
+
Tecnica, on_delete=models.CASCADE, related_name="sesion_tecnica")
|
| 18 |
|
| 19 |
def __str__(self):
|
| 20 |
+
return self.codigo_sesion
|
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.nombre_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 f"{self.id} : {self.tipo_tecnica.nombre_tecnica} : {self.id_estilo.nombre_estilo}"
|
| 19 |
|
| 20 |
def toDict(self):
|
| 21 |
return {
|
tecnicas/static/js/create-session.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
const formSubmit = document.querySelector(".ct-cretae-session-form");
|
| 2 |
|
| 3 |
document.addEventListener("DOMContentLoaded", () => {
|
| 4 |
-
|
| 5 |
-
cretaeSession();
|
| 6 |
-
}, 2000);
|
| 7 |
});
|
| 8 |
|
| 9 |
async function cretaeSession() {
|
|
@@ -27,18 +25,34 @@ async function cretaeSession() {
|
|
| 27 |
}
|
| 28 |
|
| 29 |
const data = jsonResponse["data"];
|
| 30 |
-
renderElementsResponse({
|
|
|
|
|
|
|
|
|
|
| 31 |
} catch (error) {
|
| 32 |
renderElementsResponse({ error: jsonResponse.error });
|
| 33 |
}
|
| 34 |
}
|
| 35 |
|
| 36 |
-
function renderElementsResponse({
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
const container = document.querySelector(".ct-message-create");
|
| 38 |
const loadElement = document.querySelector(".ct-load-create");
|
| 39 |
|
| 40 |
-
const
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
const idSession = document.createElement("p");
|
| 43 |
idSession.classList.add("text-lg", "text-white", "text-center", "font-bold");
|
| 44 |
const pHelp = document.createElement("p");
|
|
@@ -47,12 +61,12 @@ function renderElementsResponse({ sessionId = "No id", error = false }) {
|
|
| 47 |
// Mostrar el error que ha ocurrido //
|
| 48 |
// ******************************** //
|
| 49 |
if (error) {
|
| 50 |
-
|
| 51 |
idSession.textContent = `Error: ${error}`;
|
| 52 |
} else {
|
| 53 |
-
|
| 54 |
-
|
| 55 |
idSession.innerHTML = `El ID de la seesion es:<br><strong class="border-b border-white">${sessionId}</strong>`;
|
|
|
|
| 56 |
|
| 57 |
pHelp.classList.add("text-lg", "text-white", "text-center");
|
| 58 |
pHelp.textContent =
|
|
@@ -84,7 +98,7 @@ function renderElementsResponse({ sessionId = "No id", error = false }) {
|
|
| 84 |
];
|
| 85 |
|
| 86 |
const aIndex = document.createElement("a");
|
| 87 |
-
aIndex.href = "
|
| 88 |
aIndex.textContent = "Volver al inicio";
|
| 89 |
|
| 90 |
aIndex.classList.add(
|
|
@@ -96,7 +110,7 @@ function renderElementsResponse({ sessionId = "No id", error = false }) {
|
|
| 96 |
);
|
| 97 |
|
| 98 |
const aMonitor = document.createElement("a");
|
| 99 |
-
aMonitor.href = "
|
| 100 |
aMonitor.textContent = "Monitorear la sesion";
|
| 101 |
|
| 102 |
aMonitor.classList.add(
|
|
@@ -117,7 +131,10 @@ function renderElementsResponse({ sessionId = "No id", error = false }) {
|
|
| 117 |
|
| 118 |
container.innerHTML = "";
|
| 119 |
|
| 120 |
-
container.appendChild(
|
|
|
|
|
|
|
|
|
|
| 121 |
container.appendChild(idSession);
|
| 122 |
container.appendChild(pHelp);
|
| 123 |
container.appendChild(divBtns);
|
|
|
|
| 1 |
const formSubmit = document.querySelector(".ct-cretae-session-form");
|
| 2 |
|
| 3 |
document.addEventListener("DOMContentLoaded", () => {
|
| 4 |
+
cretaeSession();
|
|
|
|
|
|
|
| 5 |
});
|
| 6 |
|
| 7 |
async function cretaeSession() {
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
const data = jsonResponse["data"];
|
| 28 |
+
renderElementsResponse({
|
| 29 |
+
sessionId: data["codigo_sesion"],
|
| 30 |
+
nameSession: data["nombre_sesion"],
|
| 31 |
+
});
|
| 32 |
} catch (error) {
|
| 33 |
renderElementsResponse({ error: jsonResponse.error });
|
| 34 |
}
|
| 35 |
}
|
| 36 |
|
| 37 |
+
function renderElementsResponse({
|
| 38 |
+
sessionId = "No id",
|
| 39 |
+
error = false,
|
| 40 |
+
nameSession = "",
|
| 41 |
+
}) {
|
| 42 |
const container = document.querySelector(".ct-message-create");
|
| 43 |
const loadElement = document.querySelector(".ct-load-create");
|
| 44 |
|
| 45 |
+
const message = document.createElement("p");
|
| 46 |
+
message.classList.add("text-2xl", "text-white", "text-center", "font-bold");
|
| 47 |
+
|
| 48 |
+
const nameSessionP = document.createElement("p");
|
| 49 |
+
nameSessionP.classList.add(
|
| 50 |
+
"text-lg",
|
| 51 |
+
"text-white",
|
| 52 |
+
"text-center",
|
| 53 |
+
"font-bold"
|
| 54 |
+
);
|
| 55 |
+
|
| 56 |
const idSession = document.createElement("p");
|
| 57 |
idSession.classList.add("text-lg", "text-white", "text-center", "font-bold");
|
| 58 |
const pHelp = document.createElement("p");
|
|
|
|
| 61 |
// Mostrar el error que ha ocurrido //
|
| 62 |
// ******************************** //
|
| 63 |
if (error) {
|
| 64 |
+
message.textContent = "No se ha podido completar la creacion de la sesion";
|
| 65 |
idSession.textContent = `Error: ${error}`;
|
| 66 |
} else {
|
| 67 |
+
message.textContent = "La session se ha creado";
|
|
|
|
| 68 |
idSession.innerHTML = `El ID de la seesion es:<br><strong class="border-b border-white">${sessionId}</strong>`;
|
| 69 |
+
nameSessionP.textContent = `Nombre de sesion: ${nameSession}`;
|
| 70 |
|
| 71 |
pHelp.classList.add("text-lg", "text-white", "text-center");
|
| 72 |
pHelp.textContent =
|
|
|
|
| 98 |
];
|
| 99 |
|
| 100 |
const aIndex = document.createElement("a");
|
| 101 |
+
aIndex.href = "/cata";
|
| 102 |
aIndex.textContent = "Volver al inicio";
|
| 103 |
|
| 104 |
aIndex.classList.add(
|
|
|
|
| 110 |
);
|
| 111 |
|
| 112 |
const aMonitor = document.createElement("a");
|
| 113 |
+
aMonitor.href = "/cata";
|
| 114 |
aMonitor.textContent = "Monitorear la sesion";
|
| 115 |
|
| 116 |
aMonitor.classList.add(
|
|
|
|
| 131 |
|
| 132 |
container.innerHTML = "";
|
| 133 |
|
| 134 |
+
container.appendChild(message);
|
| 135 |
+
if (nameSession != "") {
|
| 136 |
+
container.appendChild(nameSessionP);
|
| 137 |
+
}
|
| 138 |
container.appendChild(idSession);
|
| 139 |
container.appendChild(pHelp);
|
| 140 |
container.appendChild(divBtns);
|
tecnicas/static/js/panel-codes.js
CHANGED
|
@@ -9,10 +9,20 @@ let sortData;
|
|
| 9 |
initIU();
|
| 10 |
|
| 11 |
function submitData(e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
const codesInput = document.createElement("input");
|
| 13 |
codesInput.type = "hidden";
|
| 14 |
codesInput.name = "sort_codes";
|
| 15 |
-
codesInput.value = JSON.stringify(
|
| 16 |
this.appendChild(codesInput);
|
| 17 |
}
|
| 18 |
|
|
@@ -110,6 +120,9 @@ function shuffle(arr) {
|
|
| 110 |
return arrSuffle;
|
| 111 |
}
|
| 112 |
|
|
|
|
|
|
|
|
|
|
| 113 |
function addIUPermutations() {
|
| 114 |
const container = document.getElementsByClassName("ct-orden-list")[0];
|
| 115 |
const itemsChild = [];
|
|
|
|
| 9 |
initIU();
|
| 10 |
|
| 11 |
function submitData(e) {
|
| 12 |
+
const submitData = [];
|
| 13 |
+
|
| 14 |
+
sortData.forEach((order) => {
|
| 15 |
+
const simplePosition = {};
|
| 16 |
+
order.forEach((dataPosition) => {
|
| 17 |
+
simplePosition[dataPosition["code"]] = dataPosition["position"];
|
| 18 |
+
});
|
| 19 |
+
submitData.push(simplePosition);
|
| 20 |
+
});
|
| 21 |
+
|
| 22 |
const codesInput = document.createElement("input");
|
| 23 |
codesInput.type = "hidden";
|
| 24 |
codesInput.name = "sort_codes";
|
| 25 |
+
codesInput.value = JSON.stringify(submitData);
|
| 26 |
this.appendChild(codesInput);
|
| 27 |
}
|
| 28 |
|
|
|
|
| 120 |
return arrSuffle;
|
| 121 |
}
|
| 122 |
|
| 123 |
+
/**
|
| 124 |
+
* Render the UI with permutations
|
| 125 |
+
*/
|
| 126 |
function addIUPermutations() {
|
| 127 |
const container = document.getElementsByClassName("ct-orden-list")[0];
|
| 128 |
const itemsChild = [];
|
tecnicas/views/configuration_panel_basic.py
CHANGED
|
@@ -6,8 +6,17 @@ from ..models import TipoTecnica
|
|
| 6 |
|
| 7 |
|
| 8 |
def configurationPanelBasic(req: HttpRequest):
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
if req.method == "POST":
|
| 12 |
try:
|
| 13 |
form = SesionBasicForm(req.POST)
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def configurationPanelBasic(req: HttpRequest):
|
| 9 |
+
keys_forms = [
|
| 10 |
+
"form_basic",
|
| 11 |
+
"form_tags",
|
| 12 |
+
"form_codes",
|
| 13 |
+
"form_words"
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
for key in keys_forms:
|
| 17 |
+
if key in req.session:
|
| 18 |
+
del req.session[key]
|
| 19 |
+
|
| 20 |
if req.method == "POST":
|
| 21 |
try:
|
| 22 |
form = SesionBasicForm(req.POST)
|
tecnicas/views/configuration_panel_tags.py
CHANGED
|
@@ -4,31 +4,34 @@ from django.urls import reverse
|
|
| 4 |
from ..forms import SesionTagsForm, EtiquetaForm
|
| 5 |
from ..models import TipoEscala
|
| 6 |
|
|
|
|
| 7 |
def configurationPanelTags(req: HttpRequest):
|
| 8 |
basic_data = req.session.get("form_basic", {})
|
| 9 |
|
| 10 |
if not basic_data:
|
| 11 |
return redirect(reverse('cata_system:panel_configuracion_basic'))
|
| 12 |
-
|
| 13 |
type_scale = TipoEscala.objects.get(pk=basic_data["tipo_escala"])
|
| 14 |
tamano_escala = basic_data["tamano_escala"]
|
| 15 |
form_new_etiqueta = EtiquetaForm()
|
| 16 |
|
| 17 |
if req.method == "GET":
|
| 18 |
-
form_etiqutas = SesionTagsForm(
|
|
|
|
| 19 |
|
| 20 |
context_tags = {
|
| 21 |
-
"form_tags":form_etiqutas,
|
| 22 |
"form_new_tag": form_new_etiqueta
|
| 23 |
}
|
| 24 |
|
| 25 |
return render(req, "tecnicas/create_sesion/configuracion-panel-tags.html", context_tags)
|
| 26 |
elif req.method == "POST":
|
| 27 |
values = {}
|
| 28 |
-
form = SesionTagsForm(req.POST, longitud=tamano_escala,
|
|
|
|
| 29 |
|
| 30 |
context_tags = {
|
| 31 |
-
"form_tags":form,
|
| 32 |
"form_new_tag": form_new_etiqueta
|
| 33 |
}
|
| 34 |
|
|
@@ -40,4 +43,4 @@ def configurationPanelTags(req: HttpRequest):
|
|
| 40 |
return redirect(reverse("cata_system:panel_configuracion_codes"))
|
| 41 |
else:
|
| 42 |
context_tags["error"] = "ha ocurrido un error"
|
| 43 |
-
return render(req, "tecnicas/create_sesion/configuracion-panel-tags.html", context_tags)
|
|
|
|
| 4 |
from ..forms import SesionTagsForm, EtiquetaForm
|
| 5 |
from ..models import TipoEscala
|
| 6 |
|
| 7 |
+
|
| 8 |
def configurationPanelTags(req: HttpRequest):
|
| 9 |
basic_data = req.session.get("form_basic", {})
|
| 10 |
|
| 11 |
if not basic_data:
|
| 12 |
return redirect(reverse('cata_system:panel_configuracion_basic'))
|
| 13 |
+
|
| 14 |
type_scale = TipoEscala.objects.get(pk=basic_data["tipo_escala"])
|
| 15 |
tamano_escala = basic_data["tamano_escala"]
|
| 16 |
form_new_etiqueta = EtiquetaForm()
|
| 17 |
|
| 18 |
if req.method == "GET":
|
| 19 |
+
form_etiqutas = SesionTagsForm(
|
| 20 |
+
longitud=tamano_escala, tipo_escala=type_scale.nombre_escala)
|
| 21 |
|
| 22 |
context_tags = {
|
| 23 |
+
"form_tags": form_etiqutas,
|
| 24 |
"form_new_tag": form_new_etiqueta
|
| 25 |
}
|
| 26 |
|
| 27 |
return render(req, "tecnicas/create_sesion/configuracion-panel-tags.html", context_tags)
|
| 28 |
elif req.method == "POST":
|
| 29 |
values = {}
|
| 30 |
+
form = SesionTagsForm(req.POST, longitud=tamano_escala,
|
| 31 |
+
tipo_escala=type_scale.nombre_escala)
|
| 32 |
|
| 33 |
context_tags = {
|
| 34 |
+
"form_tags": form,
|
| 35 |
"form_new_tag": form_new_etiqueta
|
| 36 |
}
|
| 37 |
|
|
|
|
| 43 |
return redirect(reverse("cata_system:panel_configuracion_codes"))
|
| 44 |
else:
|
| 45 |
context_tags["error"] = "ha ocurrido un error"
|
| 46 |
+
return render(req, "tecnicas/create_sesion/configuracion-panel-tags.html", context_tags)
|
tecnicas/views/create_session.py
CHANGED
|
@@ -2,7 +2,8 @@ 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, EscalaController, ProductosController, OrdenesController, EstiloPalabrasController, PalabrasController
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def createSession(req: HttpRequest):
|
|
@@ -10,7 +11,7 @@ def createSession(req: HttpRequest):
|
|
| 10 |
return render(req, 'tecnicas/create_sesion/creando_sesion.html')
|
| 11 |
if req.method == "POST":
|
| 12 |
if req.POST.get('action') == 'create_session':
|
| 13 |
-
if not req.session.get("form_basic") or not req.session.get("form_tags") or not req.session.get("form_codes") or not req.session
|
| 14 |
req.session.flush()
|
| 15 |
return general_error("no se ha especificado informacion necesaria para la creacion de la sesion")
|
| 16 |
|
|
@@ -28,7 +29,7 @@ def createSession(req: HttpRequest):
|
|
| 28 |
return general_error("error al guardar la tecnica")
|
| 29 |
|
| 30 |
data_scale = {
|
| 31 |
-
"
|
| 32 |
"size": data_basic["tamano_escala"],
|
| 33 |
"technique": technique
|
| 34 |
}
|
|
@@ -36,15 +37,14 @@ def createSession(req: HttpRequest):
|
|
| 36 |
controllerScale = EscalaController(data=data_scale)
|
| 37 |
|
| 38 |
scale = controllerScale.saveScale()
|
| 39 |
-
if
|
| 40 |
controllerTechnique.deleteTechnique()
|
| 41 |
-
return general_error("error
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
return general_error("error al guardar asociar escalas, datos agregados previeamante borrados")
|
| 48 |
|
| 49 |
# ////////////////////////////////////////////////////////// #
|
| 50 |
#
|
|
@@ -53,8 +53,10 @@ def createSession(req: HttpRequest):
|
|
| 53 |
# ////////////////////////////////////////////////////////// #
|
| 54 |
data_codes = req.session["form_codes"]
|
| 55 |
|
|
|
|
|
|
|
| 56 |
codes = []
|
| 57 |
-
for product in
|
| 58 |
code = next(iter(product.values()))
|
| 59 |
codes.append(code)
|
| 60 |
|
|
@@ -65,8 +67,9 @@ def createSession(req: HttpRequest):
|
|
| 65 |
|
| 66 |
controllerProducts.setProductsNoSave()
|
| 67 |
saved_prodcuts = controllerProducts.saveProducts()
|
| 68 |
-
if saved_prodcuts
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
raw_sort_codes = data_codes["sort_codes"]
|
| 72 |
controllerOrdes = OrdenesController(
|
|
@@ -75,17 +78,20 @@ def createSession(req: HttpRequest):
|
|
| 75 |
technique=technique
|
| 76 |
)
|
| 77 |
|
| 78 |
-
controllerOrdes.
|
| 79 |
saved_orders = controllerOrdes.saveOrders()
|
| 80 |
-
if saved_orders
|
|
|
|
| 81 |
return general_error(saved_orders["error"])
|
| 82 |
|
| 83 |
seded_positions = controllerOrdes.setPositions()
|
| 84 |
-
if seded_positions
|
|
|
|
| 85 |
return general_error(seded_positions["error"])
|
| 86 |
|
| 87 |
-
saved_postions = controllerOrdes.
|
| 88 |
-
if
|
|
|
|
| 89 |
return general_error(saved_prodcuts["error"])
|
| 90 |
|
| 91 |
# /////////////////////////////////////////////////////// #
|
|
@@ -97,19 +103,61 @@ def createSession(req: HttpRequest):
|
|
| 97 |
words_controller = PalabrasController(ids=ids_words)
|
| 98 |
|
| 99 |
words_to_use = words_controller.setWords()
|
| 100 |
-
if words_to_use
|
|
|
|
| 101 |
return general_error(words_to_use["error"])
|
| 102 |
|
| 103 |
style_controller = EstiloPalabrasController(
|
| 104 |
technique=technique, words=words_to_use)
|
| 105 |
|
| 106 |
instace_style = style_controller.createAndSaveInstaceStyle()
|
| 107 |
-
if instace_style
|
|
|
|
| 108 |
return general_error(instace_style["error"])
|
| 109 |
|
| 110 |
words_using = style_controller.relatedWords()
|
| 111 |
-
if words_using
|
|
|
|
| 112 |
return general_error("error")
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
return general_error("ha orcurrido un error inesperado")
|
|
|
|
| 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, ProductosController, OrdenesController, EstiloPalabrasController, PalabrasController, SesionController
|
| 6 |
+
from ..models import Presentador
|
| 7 |
|
| 8 |
|
| 9 |
def createSession(req: HttpRequest):
|
|
|
|
| 11 |
return render(req, 'tecnicas/create_sesion/creando_sesion.html')
|
| 12 |
if req.method == "POST":
|
| 13 |
if req.POST.get('action') == 'create_session':
|
| 14 |
+
if not req.session.get("form_basic") or not req.session.get("form_tags") or not req.session.get("form_codes") or not req.session.get("form_words"):
|
| 15 |
req.session.flush()
|
| 16 |
return general_error("no se ha especificado informacion necesaria para la creacion de la sesion")
|
| 17 |
|
|
|
|
| 29 |
return general_error("error al guardar la tecnica")
|
| 30 |
|
| 31 |
data_scale = {
|
| 32 |
+
"id_scale": data_basic["tipo_escala"],
|
| 33 |
"size": data_basic["tamano_escala"],
|
| 34 |
"technique": technique
|
| 35 |
}
|
|
|
|
| 37 |
controllerScale = EscalaController(data=data_scale)
|
| 38 |
|
| 39 |
scale = controllerScale.saveScale()
|
| 40 |
+
if isinstance(scale, dict):
|
| 41 |
controllerTechnique.deleteTechnique()
|
| 42 |
+
return general_error(scale["error"])
|
| 43 |
|
| 44 |
+
dict_tags = req.session["form_tags"]
|
| 45 |
+
saved_related_tags = controllerScale.realteTags(dict_tags)
|
| 46 |
+
if "error" in saved_related_tags:
|
| 47 |
+
return general_error(saved_related_tags["error"])
|
|
|
|
| 48 |
|
| 49 |
# ////////////////////////////////////////////////////////// #
|
| 50 |
#
|
|
|
|
| 53 |
# ////////////////////////////////////////////////////////// #
|
| 54 |
data_codes = req.session["form_codes"]
|
| 55 |
|
| 56 |
+
list_codes_dict = data_codes["product_codes"]
|
| 57 |
+
|
| 58 |
codes = []
|
| 59 |
+
for product in list_codes_dict:
|
| 60 |
code = next(iter(product.values()))
|
| 61 |
codes.append(code)
|
| 62 |
|
|
|
|
| 67 |
|
| 68 |
controllerProducts.setProductsNoSave()
|
| 69 |
saved_prodcuts = controllerProducts.saveProducts()
|
| 70 |
+
if isinstance(saved_prodcuts, dict):
|
| 71 |
+
controllerTechnique.deleteTechnique()
|
| 72 |
+
return general_error(saved_prodcuts["error"])
|
| 73 |
|
| 74 |
raw_sort_codes = data_codes["sort_codes"]
|
| 75 |
controllerOrdes = OrdenesController(
|
|
|
|
| 78 |
technique=technique
|
| 79 |
)
|
| 80 |
|
| 81 |
+
controllerOrdes.setOrdersToSave()
|
| 82 |
saved_orders = controllerOrdes.saveOrders()
|
| 83 |
+
if isinstance(saved_orders, dict):
|
| 84 |
+
controllerTechnique.deleteTechnique()
|
| 85 |
return general_error(saved_orders["error"])
|
| 86 |
|
| 87 |
seded_positions = controllerOrdes.setPositions()
|
| 88 |
+
if isinstance(seded_positions, dict):
|
| 89 |
+
controllerTechnique.deleteTechnique()
|
| 90 |
return general_error(seded_positions["error"])
|
| 91 |
|
| 92 |
+
saved_postions = controllerOrdes.savePositions()
|
| 93 |
+
if isinstance(saved_postions, dict):
|
| 94 |
+
controllerTechnique.deleteTechnique()
|
| 95 |
return general_error(saved_prodcuts["error"])
|
| 96 |
|
| 97 |
# /////////////////////////////////////////////////////// #
|
|
|
|
| 103 |
words_controller = PalabrasController(ids=ids_words)
|
| 104 |
|
| 105 |
words_to_use = words_controller.setWords()
|
| 106 |
+
if isinstance(words_to_use, dict):
|
| 107 |
+
controllerTechnique.deleteTechnique()
|
| 108 |
return general_error(words_to_use["error"])
|
| 109 |
|
| 110 |
style_controller = EstiloPalabrasController(
|
| 111 |
technique=technique, words=words_to_use)
|
| 112 |
|
| 113 |
instace_style = style_controller.createAndSaveInstaceStyle()
|
| 114 |
+
if isinstance(instace_style, dict):
|
| 115 |
+
controllerTechnique.deleteTechnique()
|
| 116 |
return general_error(instace_style["error"])
|
| 117 |
|
| 118 |
words_using = style_controller.relatedWords()
|
| 119 |
+
if isinstance(words_using, dict):
|
| 120 |
+
controllerTechnique.deleteTechnique()
|
| 121 |
return general_error("error")
|
| 122 |
+
|
| 123 |
+
# //////////////////////////////////////////////////////// #
|
| 124 |
+
#
|
| 125 |
+
# Fourth step: Create session and relat with the technique #
|
| 126 |
+
#
|
| 127 |
+
# //////////////////////////////////////////////////////// #
|
| 128 |
+
session_controller = SesionController(
|
| 129 |
+
name_session=data_basic["nombre_sesion"] if data_basic["nombre_sesion"] != "" else None,
|
| 130 |
+
technique=technique,
|
| 131 |
+
creator=Presentador.objects.get(nombre_usuario="aguBido")
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
setting_session = session_controller.setSession()
|
| 135 |
+
if isinstance(setting_session, dict):
|
| 136 |
+
controllerTechnique.deleteTechnique()
|
| 137 |
+
return general_error(setting_session["error"])
|
| 138 |
+
|
| 139 |
+
saved_session = session_controller.saveSession()
|
| 140 |
+
if isinstance(saved_session, dict):
|
| 141 |
+
return general_error(saved_session["error"])
|
| 142 |
+
|
| 143 |
+
context = {
|
| 144 |
+
"message": "sesion creada",
|
| 145 |
+
"data": {
|
| 146 |
+
"codigo_sesion": saved_session.codigo_sesion,
|
| 147 |
+
"nombre_sesion": saved_session.nombre_sesion
|
| 148 |
+
}
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
keys_forms = [
|
| 152 |
+
"form_basic",
|
| 153 |
+
"form_tags",
|
| 154 |
+
"form_codes",
|
| 155 |
+
"form_words"
|
| 156 |
+
]
|
| 157 |
+
|
| 158 |
+
for key in keys_forms:
|
| 159 |
+
if key in req.session:
|
| 160 |
+
del req.session[key]
|
| 161 |
+
|
| 162 |
+
return JsonResponse(context)
|
| 163 |
return general_error("ha orcurrido un error inesperado")
|