Spaces:
Sleeping
Sleeping
Switch para creacion de session con tecnica escalas
Browse files- tecnicas/constants.py +6 -0
- tecnicas/controllers/__init__.py +2 -0
- tecnicas/controllers/models_controller/escala_controller.py +2 -2
- tecnicas/controllers/models_controller/ordenes_controller.py +7 -7
- tecnicas/controllers/models_controller/palabras_controller.py +1 -1
- tecnicas/controllers/models_controller/sesion_controller.py +5 -5
- tecnicas/controllers/models_controller/tecnica_controller.py +1 -1
- tecnicas/controllers/views_controller/create_session/panel_basic_controller.py +2 -2
- tecnicas/controllers/views_controller/create_session/panel_codes_controller.py +2 -2
- tecnicas/controllers/views_controller/create_session/panel_create_controller.py +157 -0
- tecnicas/controllers/views_controller/create_session/panel_tags_controller.py +2 -2
- tecnicas/controllers/views_controller/create_session/panel_words_controller.py +49 -0
- tecnicas/utils/__init__.py +2 -1
- tecnicas/utils/delete_data_session.py +10 -0
- tecnicas/views/sessions_config/configuration_panel_basic.py +6 -15
- tecnicas/views/sessions_config/configuration_panel_codes.py +7 -5
- tecnicas/views/sessions_config/configuration_panel_tags.py +13 -5
- tecnicas/views/sessions_config/configuration_panel_words.py +24 -35
- tecnicas/views/sessions_config/create_session.py +28 -164
tecnicas/constants.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FORMS_TO_CREATE_SESSION = [
|
| 2 |
+
"form_basic",
|
| 3 |
+
"form_tags",
|
| 4 |
+
"form_codes",
|
| 5 |
+
"form_words"
|
| 6 |
+
]
|
tecnicas/controllers/__init__.py
CHANGED
|
@@ -23,3 +23,5 @@ from .views_controller.list_sessions_tester_controller import ListSessionsTester
|
|
| 23 |
from .views_controller.create_session.panel_basic_controller import PanelBasicController
|
| 24 |
from .views_controller.create_session.panel_tags_controller import PanelTagsController
|
| 25 |
from .views_controller.create_session.panel_codes_controller import PanelCodesController
|
|
|
|
|
|
|
|
|
| 23 |
from .views_controller.create_session.panel_basic_controller import PanelBasicController
|
| 24 |
from .views_controller.create_session.panel_tags_controller import PanelTagsController
|
| 25 |
from .views_controller.create_session.panel_codes_controller import PanelCodesController
|
| 26 |
+
from .views_controller.create_session.panel_words_controller import PanelWordsController
|
| 27 |
+
from .views_controller.create_session.panel_create_controller import PanelCreateController
|
tecnicas/controllers/models_controller/escala_controller.py
CHANGED
|
@@ -26,7 +26,7 @@ class EscalaController():
|
|
| 26 |
self.scale.save()
|
| 27 |
return self.scale
|
| 28 |
except DatabaseError as error:
|
| 29 |
-
return controller_error("
|
| 30 |
|
| 31 |
def deleteScale(self):
|
| 32 |
self.scale.delete()
|
|
@@ -67,7 +67,7 @@ class EscalaController():
|
|
| 67 |
return self.tags_relation
|
| 68 |
except DatabaseError as error:
|
| 69 |
self.deleteRelationshipsWithLabels()
|
| 70 |
-
return controller_error("
|
| 71 |
|
| 72 |
@staticmethod
|
| 73 |
def getScaleByTechnique(technique: Tecnica = None, id_technique: int = None):
|
|
|
|
| 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()
|
|
|
|
| 67 |
return self.tags_relation
|
| 68 |
except DatabaseError as error:
|
| 69 |
self.deleteRelationshipsWithLabels()
|
| 70 |
+
return controller_error("Error en guardar la relación etiqueta escala")
|
| 71 |
|
| 72 |
@staticmethod
|
| 73 |
def getScaleByTechnique(technique: Tecnica = None, id_technique: int = None):
|
tecnicas/controllers/models_controller/ordenes_controller.py
CHANGED
|
@@ -25,13 +25,13 @@ class OrdenesController():
|
|
| 25 |
|
| 26 |
def saveOrders(self):
|
| 27 |
if not self.orders:
|
| 28 |
-
return controller_error("
|
| 29 |
try:
|
| 30 |
for order in self.orders:
|
| 31 |
order.save()
|
| 32 |
return self.orders
|
| 33 |
except DatabaseError as error:
|
| 34 |
-
return controller_error("
|
| 35 |
|
| 36 |
def setPositions(self):
|
| 37 |
codes_ids_products = {}
|
|
@@ -40,21 +40,21 @@ class OrdenesController():
|
|
| 40 |
codes_expect = list(codes_ids_products.keys())
|
| 41 |
|
| 42 |
if len(self.orders) != len(self.raw_list_orders):
|
| 43 |
-
return controller_error("
|
| 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("
|
| 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("
|
| 58 |
|
| 59 |
product_use = list_product_use[0]
|
| 60 |
new_position = Posicion(
|
|
@@ -67,13 +67,13 @@ class OrdenesController():
|
|
| 67 |
|
| 68 |
def savePositions(self):
|
| 69 |
if not self.positions:
|
| 70 |
-
return controller_error("
|
| 71 |
try:
|
| 72 |
for position in self.positions:
|
| 73 |
position.save()
|
| 74 |
return self.positions
|
| 75 |
except DatabaseError as error:
|
| 76 |
-
return controller_error("
|
| 77 |
|
| 78 |
@staticmethod
|
| 79 |
def getOrderById(id: int):
|
|
|
|
| 25 |
|
| 26 |
def saveOrders(self):
|
| 27 |
if not self.orders:
|
| 28 |
+
return controller_error("No se han establecido las órdenes 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 = {}
|
|
|
|
| 40 |
codes_expect = list(codes_ids_products.keys())
|
| 41 |
|
| 42 |
if len(self.orders) != len(self.raw_list_orders):
|
| 43 |
+
return controller_error("El número 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 posición de un orden")
|
| 58 |
|
| 59 |
product_use = list_product_use[0]
|
| 60 |
new_position = Posicion(
|
|
|
|
| 67 |
|
| 68 |
def savePositions(self):
|
| 69 |
if not self.positions:
|
| 70 |
+
return controller_error("No se han establecido posiciones para guarguar")
|
| 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")
|
| 77 |
|
| 78 |
@staticmethod
|
| 79 |
def getOrderById(id: int):
|
tecnicas/controllers/models_controller/palabras_controller.py
CHANGED
|
@@ -17,7 +17,7 @@ class PalabrasController():
|
|
| 17 |
self.words = []
|
| 18 |
searched_words = list(Palabra.objects.filter(id__in=self.ids_words))
|
| 19 |
if not len(searched_words):
|
| 20 |
-
return controller_error("
|
| 21 |
self.words = searched_words
|
| 22 |
return self.words
|
| 23 |
|
|
|
|
| 17 |
self.words = []
|
| 18 |
searched_words = list(Palabra.objects.filter(id__in=self.ids_words))
|
| 19 |
if not len(searched_words):
|
| 20 |
+
return controller_error("No se han encontrado registros")
|
| 21 |
self.words = searched_words
|
| 22 |
return self.words
|
| 23 |
|
tecnicas/controllers/models_controller/sesion_controller.py
CHANGED
|
@@ -18,9 +18,9 @@ class SesionController():
|
|
| 18 |
|
| 19 |
def setSession(self):
|
| 20 |
if not self.presenter:
|
| 21 |
-
return controller_error("
|
| 22 |
elif not self.technique:
|
| 23 |
-
return controller_error("
|
| 24 |
|
| 25 |
self.sensorial_session = SesionSensorial(
|
| 26 |
tecnica=self.technique,
|
|
@@ -34,13 +34,13 @@ class SesionController():
|
|
| 34 |
|
| 35 |
def saveSession(self):
|
| 36 |
if not self.sensorial_session:
|
| 37 |
-
return controller_error("
|
| 38 |
|
| 39 |
try:
|
| 40 |
self.sensorial_session.save()
|
| 41 |
return self.sensorial_session
|
| 42 |
except DatabaseError as error:
|
| 43 |
-
return controller_error("Error al crear la
|
| 44 |
|
| 45 |
@staticmethod
|
| 46 |
def getSessionsSavesByCretor(user_name: str, page: int):
|
|
@@ -122,7 +122,7 @@ class SesionController():
|
|
| 122 |
|
| 123 |
return number_sessions/9
|
| 124 |
except Presentador.DoesNotExist:
|
| 125 |
-
return controller_error("
|
| 126 |
|
| 127 |
@staticmethod
|
| 128 |
def finishRepetion(session: SesionSensorial | str):
|
|
|
|
| 18 |
|
| 19 |
def setSession(self):
|
| 20 |
if not self.presenter:
|
| 21 |
+
return controller_error("Se requiere presentador para crear sesión")
|
| 22 |
elif not self.technique:
|
| 23 |
+
return controller_error("Se requiere técnica para crear sesión")
|
| 24 |
|
| 25 |
self.sensorial_session = SesionSensorial(
|
| 26 |
tecnica=self.technique,
|
|
|
|
| 34 |
|
| 35 |
def saveSession(self):
|
| 36 |
if not self.sensorial_session:
|
| 37 |
+
return controller_error("No se ha definido la sesión a guardar")
|
| 38 |
|
| 39 |
try:
|
| 40 |
self.sensorial_session.save()
|
| 41 |
return self.sensorial_session
|
| 42 |
except DatabaseError as error:
|
| 43 |
+
return controller_error("Error al crear la sesión sensorial")
|
| 44 |
|
| 45 |
@staticmethod
|
| 46 |
def getSessionsSavesByCretor(user_name: str, page: int):
|
|
|
|
| 122 |
|
| 123 |
return number_sessions/9
|
| 124 |
except Presentador.DoesNotExist:
|
| 125 |
+
return controller_error("Presentador invalido")
|
| 126 |
|
| 127 |
@staticmethod
|
| 128 |
def finishRepetion(session: SesionSensorial | str):
|
tecnicas/controllers/models_controller/tecnica_controller.py
CHANGED
|
@@ -30,7 +30,7 @@ class TecnicaController():
|
|
| 30 |
self.technique.save()
|
| 31 |
return self.technique
|
| 32 |
except DatabaseError:
|
| 33 |
-
return controller_error("No se ha podido guardar la
|
| 34 |
|
| 35 |
def deleteTechnique(self):
|
| 36 |
self.technique.delete()
|
|
|
|
| 30 |
self.technique.save()
|
| 31 |
return self.technique
|
| 32 |
except DatabaseError:
|
| 33 |
+
return controller_error("No se ha podido guardar la técnica")
|
| 34 |
|
| 35 |
def deleteTechnique(self):
|
| 36 |
self.technique.delete()
|
tecnicas/controllers/views_controller/create_session/panel_basic_controller.py
CHANGED
|
@@ -9,14 +9,14 @@ class PanelBasicController():
|
|
| 9 |
pass
|
| 10 |
|
| 11 |
@staticmethod
|
| 12 |
-
def
|
| 13 |
form_sesion = SesionBasicForm()
|
| 14 |
response = render(
|
| 15 |
request, "tecnicas/create_sesion/configuracion-panel-basic.html", {"form_sesion": form_sesion})
|
| 16 |
return response
|
| 17 |
|
| 18 |
@staticmethod
|
| 19 |
-
def
|
| 20 |
try:
|
| 21 |
form = SesionBasicForm(request.POST)
|
| 22 |
|
|
|
|
| 9 |
pass
|
| 10 |
|
| 11 |
@staticmethod
|
| 12 |
+
def controllGetEscalas(request: HttpRequest):
|
| 13 |
form_sesion = SesionBasicForm()
|
| 14 |
response = render(
|
| 15 |
request, "tecnicas/create_sesion/configuracion-panel-basic.html", {"form_sesion": form_sesion})
|
| 16 |
return response
|
| 17 |
|
| 18 |
@staticmethod
|
| 19 |
+
def controllPostEscalas(request: HttpRequest, name_tecnica: str):
|
| 20 |
try:
|
| 21 |
form = SesionBasicForm(request.POST)
|
| 22 |
|
tecnicas/controllers/views_controller/create_session/panel_codes_controller.py
CHANGED
|
@@ -11,7 +11,7 @@ class PanelCodesController():
|
|
| 11 |
pass
|
| 12 |
|
| 13 |
@staticmethod
|
| 14 |
-
def
|
| 15 |
(
|
| 16 |
num_products,
|
| 17 |
num_tester
|
|
@@ -29,7 +29,7 @@ class PanelCodesController():
|
|
| 29 |
return render(request, "tecnicas/create_sesion/configuracion-panel-codes.html", context_codes_form)
|
| 30 |
|
| 31 |
@staticmethod
|
| 32 |
-
def
|
| 33 |
(
|
| 34 |
num_products,
|
| 35 |
num_tester
|
|
|
|
| 11 |
pass
|
| 12 |
|
| 13 |
@staticmethod
|
| 14 |
+
def controllGetEscalas(request: HttpRequest, data):
|
| 15 |
(
|
| 16 |
num_products,
|
| 17 |
num_tester
|
|
|
|
| 29 |
return render(request, "tecnicas/create_sesion/configuracion-panel-codes.html", context_codes_form)
|
| 30 |
|
| 31 |
@staticmethod
|
| 32 |
+
def controllPostEscalas(request: HttpRequest, data):
|
| 33 |
(
|
| 34 |
num_products,
|
| 35 |
num_tester
|
tecnicas/controllers/views_controller/create_session/panel_create_controller.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest, JsonResponse
|
| 2 |
+
from django.db import transaction
|
| 3 |
+
from tecnicas.utils import general_error
|
| 4 |
+
from tecnicas.controllers import TecnicaController, EscalaController, ProductosController, OrdenesController, EstiloPalabrasController, PalabrasController, SesionController
|
| 5 |
+
from tecnicas.utils import deleteDataSession
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class PanelCreateController():
|
| 9 |
+
def __init__(self):
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
@staticmethod
|
| 13 |
+
def controllGetEscalas(request: HttpRequest, data):
|
| 14 |
+
pass
|
| 15 |
+
|
| 16 |
+
@staticmethod
|
| 17 |
+
def controllPostEscalas(request: HttpRequest):
|
| 18 |
+
if request.POST.get('action') == 'create_session':
|
| 19 |
+
if not request.session.get("form_tags") or not request.session.get("form_codes") or not request.session.get("form_words"):
|
| 20 |
+
deleteDataSession(request)
|
| 21 |
+
return general_error("No se ha especificado información necesaria para la creación de la sesión, por favor, vuelve a intentarlo")
|
| 22 |
+
|
| 23 |
+
with transaction.atomic():
|
| 24 |
+
# ////////////////////////////////////////////////////// #
|
| 25 |
+
#
|
| 26 |
+
# First step: Create technique and scale with their tags #
|
| 27 |
+
#
|
| 28 |
+
# ////////////////////////////////////////////////////// #
|
| 29 |
+
data_basic = request.session["form_basic"]
|
| 30 |
+
controllerTechnique = TecnicaController()
|
| 31 |
+
controllerTechnique.setTechniqueFromBasicData(basic=data_basic)
|
| 32 |
+
|
| 33 |
+
technique = controllerTechnique.saveTechnique()
|
| 34 |
+
if not technique:
|
| 35 |
+
return general_error("Error al guardar la técnica")
|
| 36 |
+
|
| 37 |
+
data_scale = {
|
| 38 |
+
"id_scale": data_basic["tipo_escala"],
|
| 39 |
+
"size": data_basic["tamano_escala"],
|
| 40 |
+
"technique": technique
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
controllerScale = EscalaController(data=data_scale)
|
| 44 |
+
|
| 45 |
+
scale = controllerScale.saveScale()
|
| 46 |
+
if isinstance(scale, dict):
|
| 47 |
+
return general_error(scale["error"])
|
| 48 |
+
|
| 49 |
+
dict_tags = request.session["form_tags"]
|
| 50 |
+
saved_related_tags = controllerScale.realteTags(dict_tags)
|
| 51 |
+
if "error" in saved_related_tags:
|
| 52 |
+
return general_error(saved_related_tags["error"])
|
| 53 |
+
|
| 54 |
+
# ////////////////////////////////////////////////////////// #
|
| 55 |
+
#
|
| 56 |
+
# Second step: Create orders, productos and set the position #
|
| 57 |
+
#
|
| 58 |
+
# ////////////////////////////////////////////////////////// #
|
| 59 |
+
data_codes = request.session["form_codes"]
|
| 60 |
+
|
| 61 |
+
list_codes_dict = data_codes["product_codes"]
|
| 62 |
+
|
| 63 |
+
codes = []
|
| 64 |
+
for product in list_codes_dict:
|
| 65 |
+
code = next(iter(product.values()))
|
| 66 |
+
codes.append(code)
|
| 67 |
+
|
| 68 |
+
controllerProducts = ProductosController(
|
| 69 |
+
codes=codes,
|
| 70 |
+
technique=technique
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
controllerProducts.setProductsNoSave()
|
| 74 |
+
saved_prodcuts = controllerProducts.saveProducts()
|
| 75 |
+
if isinstance(saved_prodcuts, dict):
|
| 76 |
+
return general_error(saved_prodcuts["error"])
|
| 77 |
+
|
| 78 |
+
raw_sort_codes = data_codes["sort_codes"]
|
| 79 |
+
controllerOrdes = OrdenesController(
|
| 80 |
+
raw_orders=raw_sort_codes,
|
| 81 |
+
list_products=saved_prodcuts,
|
| 82 |
+
technique=technique
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
controllerOrdes.setOrdersToSave()
|
| 86 |
+
saved_orders = controllerOrdes.saveOrders()
|
| 87 |
+
if isinstance(saved_orders, dict):
|
| 88 |
+
return general_error(saved_orders["error"])
|
| 89 |
+
|
| 90 |
+
seded_positions = controllerOrdes.setPositions()
|
| 91 |
+
if isinstance(seded_positions, dict):
|
| 92 |
+
return general_error(seded_positions["error"])
|
| 93 |
+
|
| 94 |
+
saved_postions = controllerOrdes.savePositions()
|
| 95 |
+
if isinstance(saved_postions, dict):
|
| 96 |
+
return general_error(saved_prodcuts["error"])
|
| 97 |
+
|
| 98 |
+
# /////////////////////////////////////////////////////// #
|
| 99 |
+
#
|
| 100 |
+
# Third step: Create relations technique with Words Style #
|
| 101 |
+
#
|
| 102 |
+
# /////////////////////////////////////////////////////// #
|
| 103 |
+
ids_words = request.session["form_words"]
|
| 104 |
+
words_controller = PalabrasController(ids=ids_words)
|
| 105 |
+
|
| 106 |
+
words_to_use = words_controller.setWords()
|
| 107 |
+
if isinstance(words_to_use, dict):
|
| 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 |
+
return general_error(instace_style["error"])
|
| 116 |
+
|
| 117 |
+
words_using = style_controller.relatedWords()
|
| 118 |
+
if isinstance(words_using, dict):
|
| 119 |
+
return general_error(words_using["error"])
|
| 120 |
+
|
| 121 |
+
# //////////////////////////////////////////////////////// #
|
| 122 |
+
#
|
| 123 |
+
# Fourth step: Create session and relat with the technique #
|
| 124 |
+
#
|
| 125 |
+
# //////////////////////////////////////////////////////// #
|
| 126 |
+
session_controller = SesionController(
|
| 127 |
+
name_session=data_basic["nombre_sesion"] if data_basic["nombre_sesion"] != "" else None,
|
| 128 |
+
technique=technique,
|
| 129 |
+
creator=request.user.user_presentador
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
setting_session = session_controller.setSession()
|
| 133 |
+
if isinstance(setting_session, dict):
|
| 134 |
+
return general_error(setting_session["error"])
|
| 135 |
+
|
| 136 |
+
saved_session = session_controller.saveSession()
|
| 137 |
+
if isinstance(saved_session, dict):
|
| 138 |
+
return general_error(saved_session["error"])
|
| 139 |
+
|
| 140 |
+
context = {
|
| 141 |
+
"message": "sesión creada",
|
| 142 |
+
"data": {
|
| 143 |
+
"codigo_sesion": saved_session.codigo_sesion,
|
| 144 |
+
"nombre_sesion": saved_session.nombre_sesion
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
# ////////////////////////////////// #
|
| 149 |
+
#
|
| 150 |
+
# Final step: Delete date en session #
|
| 151 |
+
#
|
| 152 |
+
# ////////////////////////////////// #
|
| 153 |
+
|
| 154 |
+
deleteDataSession(request)
|
| 155 |
+
return JsonResponse(context)
|
| 156 |
+
else:
|
| 157 |
+
return general_error("No se ha establecido acción")
|
tecnicas/controllers/views_controller/create_session/panel_tags_controller.py
CHANGED
|
@@ -10,7 +10,7 @@ class PanelTagsController():
|
|
| 10 |
pass
|
| 11 |
|
| 12 |
@staticmethod
|
| 13 |
-
def
|
| 14 |
(
|
| 15 |
type_scale,
|
| 16 |
tamano_escala,
|
|
@@ -28,7 +28,7 @@ class PanelTagsController():
|
|
| 28 |
return render(request, "tecnicas/create_sesion/configuracion-panel-tags.html", context_tags)
|
| 29 |
|
| 30 |
@staticmethod
|
| 31 |
-
def
|
| 32 |
(
|
| 33 |
type_scale,
|
| 34 |
tamano_escala,
|
|
|
|
| 10 |
pass
|
| 11 |
|
| 12 |
@staticmethod
|
| 13 |
+
def controllGetEscalas(request: HttpRequest, data):
|
| 14 |
(
|
| 15 |
type_scale,
|
| 16 |
tamano_escala,
|
|
|
|
| 28 |
return render(request, "tecnicas/create_sesion/configuracion-panel-tags.html", context_tags)
|
| 29 |
|
| 30 |
@staticmethod
|
| 31 |
+
def controllPostEscalas(request: HttpRequest, data):
|
| 32 |
(
|
| 33 |
type_scale,
|
| 34 |
tamano_escala,
|
tecnicas/controllers/views_controller/create_session/panel_words_controller.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest
|
| 2 |
+
from tecnicas.forms import WordForm
|
| 3 |
+
from django.shortcuts import render, redirect
|
| 4 |
+
from django.urls import reverse
|
| 5 |
+
from tecnicas.models import Palabra
|
| 6 |
+
import json
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class PanelWordsController():
|
| 10 |
+
def __init__(self):
|
| 11 |
+
pass
|
| 12 |
+
|
| 13 |
+
@staticmethod
|
| 14 |
+
def controllGetEscalas(request: HttpRequest):
|
| 15 |
+
form = WordForm()
|
| 16 |
+
context = {
|
| 17 |
+
"form_word": form
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
return render(request, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
| 21 |
+
|
| 22 |
+
@staticmethod
|
| 23 |
+
def controllPostEscalas(request: HttpRequest):
|
| 24 |
+
form = WordForm()
|
| 25 |
+
context = {
|
| 26 |
+
"form_word": form
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
if not request.POST.get("words"):
|
| 30 |
+
return render(request, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
| 31 |
+
|
| 32 |
+
words = json.loads(request.POST.get("words"))
|
| 33 |
+
context["words"] = words
|
| 34 |
+
|
| 35 |
+
ids_words = [word["id"] for word in words]
|
| 36 |
+
|
| 37 |
+
if len(ids_words) != len(set(ids_words)):
|
| 38 |
+
context["error"] = "existen palabras duplicadas"
|
| 39 |
+
return render(request, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
| 40 |
+
|
| 41 |
+
exist_words = Palabra.objects.filter(
|
| 42 |
+
id__in=ids_words).count() == len(ids_words)
|
| 43 |
+
|
| 44 |
+
if not exist_words:
|
| 45 |
+
context["error"] = "algunas palabras no existen"
|
| 46 |
+
return render(request, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
| 47 |
+
|
| 48 |
+
request.session["form_words"] = ids_words
|
| 49 |
+
return redirect(reverse("cata_system:creando_sesion"))
|
tecnicas/utils/__init__.py
CHANGED
|
@@ -3,4 +3,5 @@ from .code_generate import generarCodigos
|
|
| 3 |
from .personal_errors import general_error, controller_error
|
| 4 |
from .shuffle_arrays import shuffleArray
|
| 5 |
from .general_controllers import getId
|
| 6 |
-
from .to_dict import defaultdict_to_dict
|
|
|
|
|
|
| 3 |
from .personal_errors import general_error, controller_error
|
| 4 |
from .shuffle_arrays import shuffleArray
|
| 5 |
from .general_controllers import getId
|
| 6 |
+
from .to_dict import defaultdict_to_dict
|
| 7 |
+
from .delete_data_session import deleteDataSession
|
tecnicas/utils/delete_data_session.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.http import HttpRequest
|
| 2 |
+
from tecnicas.constants import FORMS_TO_CREATE_SESSION
|
| 3 |
+
from .personal_errors import general_error
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def deleteDataSession(request: HttpRequest):
|
| 7 |
+
for key in FORMS_TO_CREATE_SESSION:
|
| 8 |
+
if key in request.session:
|
| 9 |
+
del request.session[key]
|
| 10 |
+
return True
|
tecnicas/views/sessions_config/configuration_panel_basic.py
CHANGED
|
@@ -1,27 +1,18 @@
|
|
| 1 |
-
from django.shortcuts import
|
| 2 |
from django.http import HttpRequest, JsonResponse
|
| 3 |
from django.urls import reverse
|
| 4 |
-
from tecnicas.forms import SesionBasicForm
|
| 5 |
from tecnicas.controllers import PanelBasicController
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def configurationPanelBasic(req: HttpRequest):
|
| 9 |
-
|
| 10 |
-
|
| 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 == "GET":
|
| 21 |
name_tecnica = req.GET["name_tecnica"]
|
| 22 |
|
| 23 |
if name_tecnica == "escalas":
|
| 24 |
-
response = PanelBasicController.
|
| 25 |
else:
|
| 26 |
response = redirect(
|
| 27 |
reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida o sin implementar")
|
|
@@ -31,7 +22,7 @@ def configurationPanelBasic(req: HttpRequest):
|
|
| 31 |
name_tecnica = req.GET["name_tecnica"]
|
| 32 |
|
| 33 |
if name_tecnica == "escalas":
|
| 34 |
-
response = PanelBasicController.
|
| 35 |
request=req, name_tecnica=name_tecnica)
|
| 36 |
else:
|
| 37 |
response = redirect(
|
|
|
|
| 1 |
+
from django.shortcuts import redirect
|
| 2 |
from django.http import HttpRequest, JsonResponse
|
| 3 |
from django.urls import reverse
|
|
|
|
| 4 |
from tecnicas.controllers import PanelBasicController
|
| 5 |
+
from tecnicas.utils import deleteDataSession
|
| 6 |
|
| 7 |
|
| 8 |
def configurationPanelBasic(req: HttpRequest):
|
| 9 |
+
deleteDataSession(req)
|
| 10 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
if req.method == "GET":
|
| 12 |
name_tecnica = req.GET["name_tecnica"]
|
| 13 |
|
| 14 |
if name_tecnica == "escalas":
|
| 15 |
+
response = PanelBasicController.controllGetEscalas(request=req)
|
| 16 |
else:
|
| 17 |
response = redirect(
|
| 18 |
reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida o sin implementar")
|
|
|
|
| 22 |
name_tecnica = req.GET["name_tecnica"]
|
| 23 |
|
| 24 |
if name_tecnica == "escalas":
|
| 25 |
+
response = PanelBasicController.controllPostEscalas(
|
| 26 |
request=req, name_tecnica=name_tecnica)
|
| 27 |
else:
|
| 28 |
response = redirect(
|
tecnicas/views/sessions_config/configuration_panel_codes.py
CHANGED
|
@@ -2,18 +2,20 @@ from django.http import HttpRequest, JsonResponse
|
|
| 2 |
from django.shortcuts import redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from tecnicas.controllers import PanelCodesController
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def configurationPanelCodes(req: HttpRequest):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
req.session.flush()
|
| 11 |
return redirect(reverse("cata_system:seleccion_tecnica") +
|
| 12 |
"?error=datos del formulario requerido no encontrados")
|
|
|
|
|
|
|
| 13 |
|
| 14 |
if req.method == "GET":
|
| 15 |
if data_basic["name_tecnica"] == "escalas":
|
| 16 |
-
response = PanelCodesController.
|
| 17 |
req, data_basic)
|
| 18 |
else:
|
| 19 |
response = redirect(
|
|
@@ -22,7 +24,7 @@ def configurationPanelCodes(req: HttpRequest):
|
|
| 22 |
return response
|
| 23 |
elif req.method == "POST":
|
| 24 |
if data_basic["name_tecnica"] == "escalas":
|
| 25 |
-
response = PanelCodesController.
|
| 26 |
req, data_basic)
|
| 27 |
else:
|
| 28 |
response = redirect(
|
|
|
|
| 2 |
from django.shortcuts import redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from tecnicas.controllers import PanelCodesController
|
| 5 |
+
from tecnicas.utils import deleteDataSession
|
| 6 |
|
| 7 |
|
| 8 |
def configurationPanelCodes(req: HttpRequest):
|
| 9 |
+
if not req.session["form_basic"]:
|
| 10 |
+
deleteDataSession(req)
|
|
|
|
| 11 |
return redirect(reverse("cata_system:seleccion_tecnica") +
|
| 12 |
"?error=datos del formulario requerido no encontrados")
|
| 13 |
+
|
| 14 |
+
data_basic = req.session["form_basic"]
|
| 15 |
|
| 16 |
if req.method == "GET":
|
| 17 |
if data_basic["name_tecnica"] == "escalas":
|
| 18 |
+
response = PanelCodesController.controllGetEscalas(
|
| 19 |
req, data_basic)
|
| 20 |
else:
|
| 21 |
response = redirect(
|
|
|
|
| 24 |
return response
|
| 25 |
elif req.method == "POST":
|
| 26 |
if data_basic["name_tecnica"] == "escalas":
|
| 27 |
+
response = PanelCodesController.controllPostEscalas(
|
| 28 |
req, data_basic)
|
| 29 |
else:
|
| 30 |
response = redirect(
|
tecnicas/views/sessions_config/configuration_panel_tags.py
CHANGED
|
@@ -2,16 +2,20 @@ from django.http import HttpRequest, JsonResponse
|
|
| 2 |
from django.shortcuts import redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from tecnicas.controllers import PanelTagsController
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def configurationPanelTags(req: HttpRequest):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
basic_data = req.session.get("form_basic")
|
| 9 |
-
if not basic_data:
|
| 10 |
-
return redirect(reverse('cata_system:panel_configuracion_basic'))
|
| 11 |
|
| 12 |
if req.method == "GET":
|
| 13 |
if basic_data["name_tecnica"] == "escalas":
|
| 14 |
-
response = PanelTagsController.
|
| 15 |
request=req, data=basic_data)
|
| 16 |
else:
|
| 17 |
response = redirect(
|
|
@@ -19,8 +23,12 @@ def configurationPanelTags(req: HttpRequest):
|
|
| 19 |
|
| 20 |
return response
|
| 21 |
elif req.method == "POST":
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return response
|
| 25 |
else:
|
| 26 |
return JsonResponse({"message": "Método no permitido"})
|
|
|
|
| 2 |
from django.shortcuts import redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from tecnicas.controllers import PanelTagsController
|
| 5 |
+
from tecnicas.utils import deleteDataSession
|
| 6 |
|
| 7 |
|
| 8 |
def configurationPanelTags(req: HttpRequest):
|
| 9 |
+
if not req.session.get("form_basic"):
|
| 10 |
+
deleteDataSession(req)
|
| 11 |
+
return redirect(reverse('cata_system:panel_configuracion_basic') +
|
| 12 |
+
"?error=datos requeridos no encontrados")
|
| 13 |
+
|
| 14 |
basic_data = req.session.get("form_basic")
|
|
|
|
|
|
|
| 15 |
|
| 16 |
if req.method == "GET":
|
| 17 |
if basic_data["name_tecnica"] == "escalas":
|
| 18 |
+
response = PanelTagsController.controllGetEscalas(
|
| 19 |
request=req, data=basic_data)
|
| 20 |
else:
|
| 21 |
response = redirect(
|
|
|
|
| 23 |
|
| 24 |
return response
|
| 25 |
elif req.method == "POST":
|
| 26 |
+
if basic_data["name_tecnica"] == "escalas":
|
| 27 |
+
response = PanelTagsController.controllPostEscalas(
|
| 28 |
+
request=req, data=basic_data)
|
| 29 |
+
else:
|
| 30 |
+
response = redirect(
|
| 31 |
+
reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida")
|
| 32 |
return response
|
| 33 |
else:
|
| 34 |
return JsonResponse({"message": "Método no permitido"})
|
tecnicas/views/sessions_config/configuration_panel_words.py
CHANGED
|
@@ -1,44 +1,33 @@
|
|
| 1 |
-
from django.http import HttpRequest
|
| 2 |
-
from django.shortcuts import
|
| 3 |
from django.urls import reverse
|
| 4 |
-
from
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
import json
|
| 8 |
|
| 9 |
|
| 10 |
def configurationPanelWords(req: HttpRequest):
|
| 11 |
-
if not req.session.get("form_basic")
|
| 12 |
-
req
|
| 13 |
return redirect(reverse("cata_system:seleccion_tecnica") +
|
| 14 |
-
"?error=datos
|
| 15 |
|
| 16 |
-
|
| 17 |
-
context = {
|
| 18 |
-
"form_word": form
|
| 19 |
-
}
|
| 20 |
|
| 21 |
if req.method == "GET":
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
words = json.loads(req.POST.get("words"))
|
| 28 |
-
context["words"] = words
|
| 29 |
-
|
| 30 |
-
ids_words = [word["id"] for word in words]
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
req.session["form_words"] = ids_words
|
| 44 |
-
return redirect(reverse("cata_system:creando_sesion"))
|
|
|
|
| 1 |
+
from django.http import HttpRequest, JsonResponse
|
| 2 |
+
from django.shortcuts import redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
+
from tecnicas.controllers import PanelWordsController
|
| 5 |
+
from tecnicas.utils import deleteDataSession
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def configurationPanelWords(req: HttpRequest):
|
| 9 |
+
if not req.session.get("form_basic"):
|
| 10 |
+
deleteDataSession(req)
|
| 11 |
return redirect(reverse("cata_system:seleccion_tecnica") +
|
| 12 |
+
"?error=datos requeridos no encontrados")
|
| 13 |
|
| 14 |
+
basic_data = req.session["form_basic"]
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
if req.method == "GET":
|
| 17 |
+
if basic_data["name_tecnica"] == "escalas":
|
| 18 |
+
response = PanelWordsController.controllGetEscalas(req)
|
| 19 |
+
else:
|
| 20 |
+
response = redirect(
|
| 21 |
+
reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
return response
|
| 24 |
+
elif req.method == "POST":
|
| 25 |
+
if basic_data["name_tecnica"] == "escalas":
|
| 26 |
+
response = PanelWordsController.controllPostEscalas(req)
|
| 27 |
+
else:
|
| 28 |
+
response = redirect(
|
| 29 |
+
reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida")
|
| 30 |
+
|
| 31 |
+
return response
|
| 32 |
+
else:
|
| 33 |
+
return JsonResponse({"message": "Método no permitido"})
|
|
|
|
|
|
tecnicas/views/sessions_config/create_session.py
CHANGED
|
@@ -1,170 +1,34 @@
|
|
| 1 |
from django.http import HttpRequest, JsonResponse
|
| 2 |
-
from django.shortcuts import render
|
| 3 |
-
from
|
| 4 |
-
from
|
| 5 |
-
from
|
| 6 |
-
from django.db import transaction
|
| 7 |
|
| 8 |
|
| 9 |
def createSession(req: HttpRequest):
|
| 10 |
-
if req.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 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 |
-
|
| 18 |
-
with transaction.atomic():
|
| 19 |
-
# ////////////////////////////////////////////////////// #
|
| 20 |
-
#
|
| 21 |
-
# First step: Create technique and scale with their tags #
|
| 22 |
-
#
|
| 23 |
-
# ////////////////////////////////////////////////////// #
|
| 24 |
-
data_basic = req.session["form_basic"]
|
| 25 |
-
controllerTechnique = TecnicaController()
|
| 26 |
-
controllerTechnique.setTechniqueFromBasicData(basic=data_basic)
|
| 27 |
-
|
| 28 |
-
technique = controllerTechnique.saveTechnique()
|
| 29 |
-
if not technique:
|
| 30 |
-
return general_error("error al guardar la tecnica")
|
| 31 |
-
|
| 32 |
-
data_scale = {
|
| 33 |
-
"id_scale": data_basic["tipo_escala"],
|
| 34 |
-
"size": data_basic["tamano_escala"],
|
| 35 |
-
"technique": technique
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
controllerScale = EscalaController(data=data_scale)
|
| 39 |
-
|
| 40 |
-
scale = controllerScale.saveScale()
|
| 41 |
-
if isinstance(scale, dict):
|
| 42 |
-
controllerTechnique.deleteTechnique()
|
| 43 |
-
return general_error(scale["error"])
|
| 44 |
-
|
| 45 |
-
dict_tags = req.session["form_tags"]
|
| 46 |
-
saved_related_tags = controllerScale.realteTags(dict_tags)
|
| 47 |
-
if "error" in saved_related_tags:
|
| 48 |
-
return general_error(saved_related_tags["error"])
|
| 49 |
-
|
| 50 |
-
# ////////////////////////////////////////////////////////// #
|
| 51 |
-
#
|
| 52 |
-
# Second step: Create orders, productos and set the position #
|
| 53 |
-
#
|
| 54 |
-
# ////////////////////////////////////////////////////////// #
|
| 55 |
-
data_codes = req.session["form_codes"]
|
| 56 |
-
|
| 57 |
-
list_codes_dict = data_codes["product_codes"]
|
| 58 |
-
|
| 59 |
-
codes = []
|
| 60 |
-
for product in list_codes_dict:
|
| 61 |
-
code = next(iter(product.values()))
|
| 62 |
-
codes.append(code)
|
| 63 |
-
|
| 64 |
-
controllerProducts = ProductosController(
|
| 65 |
-
codes=codes,
|
| 66 |
-
technique=technique
|
| 67 |
-
)
|
| 68 |
-
|
| 69 |
-
controllerProducts.setProductsNoSave()
|
| 70 |
-
saved_prodcuts = controllerProducts.saveProducts()
|
| 71 |
-
if isinstance(saved_prodcuts, dict):
|
| 72 |
-
controllerTechnique.deleteTechnique()
|
| 73 |
-
return general_error(saved_prodcuts["error"])
|
| 74 |
-
|
| 75 |
-
raw_sort_codes = data_codes["sort_codes"]
|
| 76 |
-
controllerOrdes = OrdenesController(
|
| 77 |
-
raw_orders=raw_sort_codes,
|
| 78 |
-
list_products=saved_prodcuts,
|
| 79 |
-
technique=technique
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
controllerOrdes.setOrdersToSave()
|
| 83 |
-
saved_orders = controllerOrdes.saveOrders()
|
| 84 |
-
if isinstance(saved_orders, dict):
|
| 85 |
-
controllerTechnique.deleteTechnique()
|
| 86 |
-
return general_error(saved_orders["error"])
|
| 87 |
|
| 88 |
-
|
| 89 |
-
if isinstance(seded_positions, dict):
|
| 90 |
-
controllerTechnique.deleteTechnique()
|
| 91 |
-
return general_error(seded_positions["error"])
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
technique=technique, words=words_to_use)
|
| 113 |
-
|
| 114 |
-
instace_style = style_controller.createAndSaveInstaceStyle()
|
| 115 |
-
if isinstance(instace_style, dict):
|
| 116 |
-
controllerTechnique.deleteTechnique()
|
| 117 |
-
return general_error(instace_style["error"])
|
| 118 |
-
|
| 119 |
-
words_using = style_controller.relatedWords()
|
| 120 |
-
if isinstance(words_using, dict):
|
| 121 |
-
controllerTechnique.deleteTechnique()
|
| 122 |
-
return general_error(words_using["error"])
|
| 123 |
-
|
| 124 |
-
# //////////////////////////////////////////////////////// #
|
| 125 |
-
#
|
| 126 |
-
# Fourth step: Create session and relat with the technique #
|
| 127 |
-
#
|
| 128 |
-
# //////////////////////////////////////////////////////// #
|
| 129 |
-
session_controller = SesionController(
|
| 130 |
-
name_session=data_basic["nombre_sesion"] if data_basic["nombre_sesion"] != "" else None,
|
| 131 |
-
technique=technique,
|
| 132 |
-
creator=req.user.user_presentador
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
setting_session = session_controller.setSession()
|
| 136 |
-
if isinstance(setting_session, dict):
|
| 137 |
-
controllerTechnique.deleteTechnique()
|
| 138 |
-
return general_error(setting_session["error"])
|
| 139 |
-
|
| 140 |
-
saved_session = session_controller.saveSession()
|
| 141 |
-
if isinstance(saved_session, dict):
|
| 142 |
-
return general_error(saved_session["error"])
|
| 143 |
-
|
| 144 |
-
context = {
|
| 145 |
-
"message": "sesion creada",
|
| 146 |
-
"data": {
|
| 147 |
-
"codigo_sesion": saved_session.codigo_sesion,
|
| 148 |
-
"nombre_sesion": saved_session.nombre_sesion
|
| 149 |
-
}
|
| 150 |
-
}
|
| 151 |
-
|
| 152 |
-
# /////////////////////////////// #
|
| 153 |
-
#
|
| 154 |
-
# Final step: Delete session keys #
|
| 155 |
-
#
|
| 156 |
-
# /////////////////////////////// #
|
| 157 |
-
|
| 158 |
-
keys_forms = [
|
| 159 |
-
"form_basic",
|
| 160 |
-
"form_tags",
|
| 161 |
-
"form_codes",
|
| 162 |
-
"form_words"
|
| 163 |
-
]
|
| 164 |
-
|
| 165 |
-
for key in keys_forms:
|
| 166 |
-
if key in req.session:
|
| 167 |
-
del req.session[key]
|
| 168 |
-
|
| 169 |
-
return JsonResponse(context)
|
| 170 |
-
return general_error("ha orcurrido un error inesperado")
|
|
|
|
| 1 |
from django.http import HttpRequest, JsonResponse
|
| 2 |
+
from django.shortcuts import render, redirect
|
| 3 |
+
from django.urls import reverse
|
| 4 |
+
from tecnicas.controllers import PanelCreateController
|
| 5 |
+
from tecnicas.utils import deleteDataSession
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def createSession(req: HttpRequest):
|
| 9 |
+
if not req.session.get("form_basic"):
|
| 10 |
+
deleteDataSession(req)
|
| 11 |
+
return redirect(reverse("cata_system:seleccion_tecnica") +
|
| 12 |
+
"?error=datos requeridos no encontrados")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
basic_data = req.session["form_basic"]
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
if req.method == "GET":
|
| 17 |
+
if basic_data["name_tecnica"] == "escalas":
|
| 18 |
+
response = render(
|
| 19 |
+
req, 'tecnicas/create_sesion/creando_sesion.html')
|
| 20 |
+
else:
|
| 21 |
+
response = redirect(
|
| 22 |
+
reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida")
|
| 23 |
+
|
| 24 |
+
return response
|
| 25 |
+
if req.method == "POST":
|
| 26 |
+
if basic_data["name_tecnica"] == "escalas":
|
| 27 |
+
response = PanelCreateController.controllPostEscalas(req)
|
| 28 |
+
else:
|
| 29 |
+
response = redirect(
|
| 30 |
+
reverse("cata_system:seleccion_tecnica") + "?error=Técnica no valida")
|
| 31 |
+
|
| 32 |
+
return response
|
| 33 |
+
else:
|
| 34 |
+
return JsonResponse({"message": "Método no permitido"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|