Spaces:
Sleeping
Sleeping
Relacionar palabras con tecnica en configuracion (estilo atributos)
Browse files- tecnicas/controllers/__init__.py +4 -1
- tecnicas/controllers/estilo_palabras_controller.py +32 -0
- tecnicas/controllers/palabras_controller.py +25 -0
- tecnicas/migrations/0012_alter_sesionsensorial_codigo_sesion_and_more.py +25 -0
- tecnicas/models/sesion_sensorial.py +1 -1
- tecnicas/test/test_controller_words.py +27 -0
- tecnicas/views/create_session.py +26 -3
tecnicas/controllers/__init__.py
CHANGED
|
@@ -1,4 +1,7 @@
|
|
| 1 |
from .tecnica_controller import TecnicaController
|
| 2 |
from .escala_controller import EscalaController
|
| 3 |
from .productos_controller import ProductosController
|
| 4 |
-
from .ordenes_controller import OrdenesController
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from .tecnica_controller import TecnicaController
|
| 2 |
from .escala_controller import EscalaController
|
| 3 |
from .productos_controller import ProductosController
|
| 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
|
tecnicas/controllers/estilo_palabras_controller.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..models import EsAtributo, Tecnica, Palabra
|
| 2 |
+
from django.db import DatabaseError
|
| 3 |
+
from ..utils import controller_error
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class EstiloPalabrasController():
|
| 7 |
+
def __init__(self, technique: Tecnica = None, words: list[Palabra] = None):
|
| 8 |
+
self.technique = technique
|
| 9 |
+
self.list_words = words
|
| 10 |
+
|
| 11 |
+
def setTechnique(self, technique: Tecnica):
|
| 12 |
+
self.technique = technique
|
| 13 |
+
|
| 14 |
+
def setListWords(self, new_words: list[Palabra]):
|
| 15 |
+
self.list_words = new_words
|
| 16 |
+
|
| 17 |
+
def createAndSaveInstaceStyle(self):
|
| 18 |
+
try:
|
| 19 |
+
self.instanceStyle = EsAtributo.objects.create(
|
| 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:
|
| 27 |
+
return controller_error("no existen palabras para asociar")
|
| 28 |
+
try:
|
| 29 |
+
self.instanceStyle.palabras.add(*self.list_words)
|
| 30 |
+
return self.instanceStyle.palabras
|
| 31 |
+
except DatabaseError as error:
|
| 32 |
+
return controller_error(error)
|
tecnicas/controllers/palabras_controller.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ..models import Palabra
|
| 2 |
+
from django.db import DatabaseError
|
| 3 |
+
from ..utils import controller_error
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class PalabrasController():
|
| 7 |
+
ids_words: list[int]
|
| 8 |
+
words: list[Palabra]
|
| 9 |
+
|
| 10 |
+
def __init__(self, ids: list[int]):
|
| 11 |
+
self.ids_words = ids
|
| 12 |
+
|
| 13 |
+
def setIdsWords(self, new_ids: list[int]):
|
| 14 |
+
self.ids_words = new_ids
|
| 15 |
+
|
| 16 |
+
def setWords(self):
|
| 17 |
+
self.words = []
|
| 18 |
+
try:
|
| 19 |
+
searched_words = Palabra.objects.filter(id__in=self.ids_words)
|
| 20 |
+
if not len(searched_words):
|
| 21 |
+
return controller_error("no se han encontrado registros")
|
| 22 |
+
self.words = searched_words
|
| 23 |
+
return self.words
|
| 24 |
+
except DatabaseError as error:
|
| 25 |
+
return controller_error(error)
|
tecnicas/migrations/0012_alter_sesionsensorial_codigo_sesion_and_more.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Generated by Django 5.2.1 on 2025-09-08 22:21
|
| 2 |
+
|
| 3 |
+
import django.db.models.deletion
|
| 4 |
+
import shortuuid.main
|
| 5 |
+
from django.db import migrations, models
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class Migration(migrations.Migration):
|
| 9 |
+
|
| 10 |
+
dependencies = [
|
| 11 |
+
('tecnicas', '0011_alter_escala_tecnica_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='tecnica',
|
| 23 |
+
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='sesion_tecnica', to='tecnicas.tecnica'),
|
| 24 |
+
),
|
| 25 |
+
]
|
tecnicas/models/sesion_sensorial.py
CHANGED
|
@@ -10,7 +10,7 @@ class SesionSensorial(models.Model):
|
|
| 10 |
fechaCreacion = models.DateTimeField("date published")
|
| 11 |
activo = models.BooleanField(default=False)
|
| 12 |
creadoPor = models.ForeignKey(Presentador, on_delete=models.CASCADE, related_name="presentador_sesion")
|
| 13 |
-
tecnica = models.
|
| 14 |
|
| 15 |
def __str__(self):
|
| 16 |
return self.codigo_sesion
|
|
|
|
| 10 |
fechaCreacion = models.DateTimeField("date published")
|
| 11 |
activo = models.BooleanField(default=False)
|
| 12 |
creadoPor = models.ForeignKey(Presentador, on_delete=models.CASCADE, related_name="presentador_sesion")
|
| 13 |
+
tecnica = models.OneToOneField(Tecnica, on_delete=models.CASCADE, related_name="sesion_tecnica")
|
| 14 |
|
| 15 |
def __str__(self):
|
| 16 |
return self.codigo_sesion
|
tecnicas/test/test_controller_words.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.test import TestCase
|
| 2 |
+
from django.urls import reverse
|
| 3 |
+
from ..controllers import PalabrasController
|
| 4 |
+
from ..models import Palabra
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestsApiWords(TestCase):
|
| 8 |
+
ids: list[int]
|
| 9 |
+
words_saved: list[Palabra]
|
| 10 |
+
|
| 11 |
+
def setUp(self):
|
| 12 |
+
self.named_words = ["rasposo", "afilado", "poroso"]
|
| 13 |
+
words_to_save = [Palabra(nombre_palabra=name)
|
| 14 |
+
for name in self.named_words]
|
| 15 |
+
self.words_saved = Palabra.objects.bulk_create(words_to_save)
|
| 16 |
+
self.ids = [word.id for word in self.words_saved]
|
| 17 |
+
|
| 18 |
+
def test_get_words_by_list_ids(self):
|
| 19 |
+
instance = PalabrasController(ids=self.ids)
|
| 20 |
+
new_words = Palabra.objects.filter(id__in=self.ids)
|
| 21 |
+
names = [word.nombre_palabra for word in new_words]
|
| 22 |
+
self.assertEqual(set(self.named_words), set(names))
|
| 23 |
+
|
| 24 |
+
def test_get_words_by_list_ids_fail(self):
|
| 25 |
+
instance = PalabrasController(ids=[23, 12, 76])
|
| 26 |
+
response = instance.setWords()
|
| 27 |
+
self.assertIn("error", response)
|
tecnicas/views/create_session.py
CHANGED
|
@@ -2,7 +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, EscalaController, ProductosController, OrdenesController
|
| 6 |
|
| 7 |
|
| 8 |
def createSession(req: HttpRequest):
|
|
@@ -79,14 +79,37 @@ def createSession(req: HttpRequest):
|
|
| 79 |
saved_orders = controllerOrdes.saveOrders()
|
| 80 |
if saved_orders["error"]:
|
| 81 |
return general_error(saved_orders["error"])
|
| 82 |
-
|
| 83 |
seded_positions = controllerOrdes.setPositions()
|
| 84 |
if seded_positions["error"]:
|
| 85 |
return general_error(seded_positions["error"])
|
| 86 |
-
|
| 87 |
saved_postions = controllerOrdes.savePostions()
|
| 88 |
if saved_prodcuts["error"]:
|
| 89 |
return general_error(saved_prodcuts["error"])
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
return JsonResponse({"message": "sesion creada", "data": {"session_id": "asd548ad4a"}})
|
| 92 |
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
|
| 6 |
|
| 7 |
|
| 8 |
def createSession(req: HttpRequest):
|
|
|
|
| 79 |
saved_orders = controllerOrdes.saveOrders()
|
| 80 |
if saved_orders["error"]:
|
| 81 |
return general_error(saved_orders["error"])
|
| 82 |
+
|
| 83 |
seded_positions = controllerOrdes.setPositions()
|
| 84 |
if seded_positions["error"]:
|
| 85 |
return general_error(seded_positions["error"])
|
| 86 |
+
|
| 87 |
saved_postions = controllerOrdes.savePostions()
|
| 88 |
if saved_prodcuts["error"]:
|
| 89 |
return general_error(saved_prodcuts["error"])
|
| 90 |
|
| 91 |
+
# /////////////////////////////////////////////////////// #
|
| 92 |
+
#
|
| 93 |
+
# Third step: Create relations technique with Words Style #
|
| 94 |
+
#
|
| 95 |
+
# /////////////////////////////////////////////////////// #
|
| 96 |
+
ids_words = req.session["form_words"]
|
| 97 |
+
words_controller = PalabrasController(ids=ids_words)
|
| 98 |
+
|
| 99 |
+
words_to_use = words_controller.setWords()
|
| 100 |
+
if words_to_use["error"]:
|
| 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["error"]:
|
| 108 |
+
return general_error(instace_style["error"])
|
| 109 |
+
|
| 110 |
+
words_using = style_controller.relatedWords()
|
| 111 |
+
if words_using["error"]:
|
| 112 |
+
return general_error("error")
|
| 113 |
+
|
| 114 |
return JsonResponse({"message": "sesion creada", "data": {"session_id": "asd548ad4a"}})
|
| 115 |
return general_error("ha orcurrido un error inesperado")
|