chartManD commited on
Commit
5fd9ba0
·
1 Parent(s): 7630d83

Calificacion de CATA

Browse files
tecnicas/controllers/__init__.py CHANGED
@@ -37,4 +37,5 @@ from .views_controller.vocabulary_manage.create_vocabulary_controller import Cre
37
  from .views_controller.vocabulary_manage.list_vocabulary_controller import ListVocabularyController
38
 
39
  from .api_controller.rating_sacales_controller import RatingScalesController
 
40
  from .views_controller.tester_list_controller import TesterListController
 
37
  from .views_controller.vocabulary_manage.list_vocabulary_controller import ListVocabularyController
38
 
39
  from .api_controller.rating_sacales_controller import RatingScalesController
40
+ from .api_controller.rating_cata_controller import RatingCataController
41
  from .views_controller.tester_list_controller import TesterListController
tecnicas/controllers/api_controller/rating_cata_controller.py CHANGED
@@ -8,26 +8,71 @@ class RatingCataController():
8
  pass
9
 
10
  @staticmethod
11
- def saveRatingWords(request: HttpRequest, data_words: list[dict]):
12
  try:
13
  with transaction.atomic():
14
  participation = Participacion.objects.get(
15
  id=request.session["id_participation"])
16
  if not participation:
17
  raise ValueError("No está autorizado en la sesión")
18
-
19
- # ids_words = [wo.id for ]
20
-
 
 
 
 
 
 
21
  words_for_rating = Palabra.objects.filter(id__in=ids_words)
 
 
22
 
23
  technique = participation.tecnica
24
- rating = Calificacion.objects.get_or_create(
25
- num_repeticion=technique.repeticion
26
- id_producto=1
27
- id_tecnica=1
28
- id_catador=1
 
 
29
  )
30
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  except ValueError as e:
32
  print(f"Error de calificacion: {e}")
33
  return JsonResponse({"error": e}, statusstatus=500)
 
8
  pass
9
 
10
  @staticmethod
11
+ def saveRatingWords(request: HttpRequest, data_words: list[dict], data_prodct: dict):
12
  try:
13
  with transaction.atomic():
14
  participation = Participacion.objects.get(
15
  id=request.session["id_participation"])
16
  if not participation:
17
  raise ValueError("No está autorizado en la sesión")
18
+
19
+ ids_words = []
20
+ words_values = {}
21
+
22
+ # Acoplar datos para usar
23
+ for da_wo in data_words:
24
+ ids_words.append(da_wo["id"])
25
+ words_values[da_wo["word"]] = da_wo["is_check"]
26
+
27
  words_for_rating = Palabra.objects.filter(id__in=ids_words)
28
+ if not words_for_rating:
29
+ raise ValueError("No se han encontrado sus palabras")
30
 
31
  technique = participation.tecnica
32
+
33
+ # Creando la calificacion
34
+ (rating, creataed) = Calificacion.objects.get_or_create(
35
+ num_repeticion=technique.repeticion,
36
+ id_producto_id=data_prodct["id"],
37
+ id_tecnica=technique,
38
+ id_catador=request.user.user_catador
39
  )
40
+ if not rating:
41
+ raise ValueError("Problemas al crear la calificación")
42
+
43
+ # Guardando datos
44
+ data_for_save = []
45
+ for word in words_for_rating:
46
+ data_for_save.append(Dato(
47
+ id_palabra=word,
48
+ id_calificacion=rating
49
+ ))
50
+
51
+ Dato.objects.bulk_create(data_for_save)
52
+ data_saved = Dato.objects.filter(
53
+ id_calificacion=rating).only("id_palabra")
54
+ if not data_saved:
55
+ raise ValueError("Problemas al crear los datos")
56
+
57
+ # Guardando valores de datos
58
+ values_for_save = []
59
+ for data in data_saved:
60
+ word_for_rating = data.id_palabra.nombre_palabra
61
+ values_for_save.append(
62
+ ValorBooleano(
63
+ id_dato=data,
64
+ valor=words_values[word_for_rating]
65
+ )
66
+ )
67
+
68
+ ValorBooleano.objects.bulk_create(values_for_save)
69
+ values_saves = ValorBooleano.objects.filter(
70
+ id_dato__id_calificacion=rating).count()
71
+ if not values_saves:
72
+ raise ValueError("Error al guardar los datos")
73
+
74
+ return JsonResponse({"message": "Valores guardados"})
75
+
76
  except ValueError as e:
77
  print(f"Error de calificacion: {e}")
78
  return JsonResponse({"error": e}, statusstatus=500)
tecnicas/controllers/views_controller/sessions_tester/test_cata_controller.py CHANGED
@@ -2,7 +2,7 @@ from django.http import HttpRequest
2
  from django.shortcuts import redirect, render
3
  from django.urls import reverse
4
  from tecnicas.models import Producto, Participacion, Palabra, Calificacion
5
- from tecnicas.controllers import PalabrasController
6
  from .general_test_controller import GenetalTestController
7
 
8
 
 
2
  from django.shortcuts import redirect, render
3
  from django.urls import reverse
4
  from tecnicas.models import Producto, Participacion, Palabra, Calificacion
5
+ from tecnicas.controllers import PalabrasController, ParticipacionController
6
  from .general_test_controller import GenetalTestController
7
 
8
 
tecnicas/static/js/test-cata.js CHANGED
@@ -12,11 +12,11 @@ document.addEventListener("DOMContentLoaded", () => {
12
 
13
  const URL = "/cata/testers/api/ratingword/cata";
14
 
15
- let wordsData = [];
16
-
17
  const checkboxes = form.querySelectorAll('input[type="checkbox"]');
18
  checkboxes.forEach((cb) => (cb.checked = false));
19
 
 
 
20
  form.addEventListener("submit", (e) => {
21
  e.preventDefault();
22
 
@@ -76,6 +76,10 @@ document.addEventListener("DOMContentLoaded", () => {
76
 
77
  confirmBtn.addEventListener("click", async () => {
78
  modal.classList.add("hidden");
 
 
 
 
79
 
80
  try {
81
  const response = await fetch(URL, {
@@ -85,13 +89,12 @@ document.addEventListener("DOMContentLoaded", () => {
85
  "X-CSRFToken": csrfToken,
86
  "X-Requested-With": "XMLHttpRequest",
87
  },
88
- body: JSON.stringify({ words: wordsData }),
89
  });
90
 
91
  if (!response.ok) {
92
  message.textContent = "Error en la respuesta del servidor";
93
  message.classList.remove("hidden");
94
- throw new Error("Error en la respuesta del servidor");
95
  }
96
 
97
  const result = await response.json();
@@ -111,14 +114,15 @@ document.addEventListener("DOMContentLoaded", () => {
111
  <p class="text-sm italic">
112
  ${result.message}
113
  </p>
114
- <button type="button" class="cts-btn-general cts-btn-primary btn-push">
115
  Siguiente Producto
116
  </button>
117
  </section>
118
  `;
119
  } catch (err) {
120
  console.error(err);
121
- alert("Ocurrió un error al enviar los datos ");
 
122
  }
123
  });
124
  });
 
12
 
13
  const URL = "/cata/testers/api/ratingword/cata";
14
 
 
 
15
  const checkboxes = form.querySelectorAll('input[type="checkbox"]');
16
  checkboxes.forEach((cb) => (cb.checked = false));
17
 
18
+ let wordsData = [];
19
+
20
  form.addEventListener("submit", (e) => {
21
  e.preventDefault();
22
 
 
76
 
77
  confirmBtn.addEventListener("click", async () => {
78
  modal.classList.add("hidden");
79
+ const dataProduct = {
80
+ id: parseInt(document.querySelector(".id-product").textContent),
81
+ code: document.querySelector(".code-product").textContent,
82
+ };
83
 
84
  try {
85
  const response = await fetch(URL, {
 
89
  "X-CSRFToken": csrfToken,
90
  "X-Requested-With": "XMLHttpRequest",
91
  },
92
+ body: JSON.stringify({ words: wordsData, product: dataProduct }),
93
  });
94
 
95
  if (!response.ok) {
96
  message.textContent = "Error en la respuesta del servidor";
97
  message.classList.remove("hidden");
 
98
  }
99
 
100
  const result = await response.json();
 
114
  <p class="text-sm italic">
115
  ${result.message}
116
  </p>
117
+ <button type="button" class="cts-btn-general cts-btn-primary btn-push" onclick="window.location.reload();">
118
  Siguiente Producto
119
  </button>
120
  </section>
121
  `;
122
  } catch (err) {
123
  console.error(err);
124
+ message.textContent = "Error en la respuesta del servidor";
125
+ message.classList.remove("hidden");
126
  }
127
  });
128
  });
tecnicas/templates/tecnicas/forms_tester/cata.html CHANGED
@@ -90,7 +90,8 @@
90
  </form>
91
  </article>
92
 
93
- <section id="confirmModal" class="absolute w-full h-full left-0 top-0 flex justify-center items-center bg-gray-500/70 hidden">
 
94
  <div class="absolute max-w-xl bg-surface-card shadow-lg rounded-lg p-4">
95
  <div class="space-y-4">
96
  <h3 class="font-bold text-lg mb-4">Confirma tu elección</h3>
 
90
  </form>
91
  </article>
92
 
93
+ <section id="confirmModal"
94
+ class="absolute w-full h-full left-0 top-0 flex justify-center items-center bg-gray-500/70 hidden">
95
  <div class="absolute max-w-xl bg-surface-card shadow-lg rounded-lg p-4">
96
  <div class="space-y-4">
97
  <h3 class="font-bold text-lg mb-4">Confirma tu elección</h3>
tecnicas/views/apis/rating_word_cata.py CHANGED
@@ -1,5 +1,6 @@
1
  from django.http import HttpRequest, JsonResponse
2
  from tecnicas.utils import general_error
 
3
  import json
4
 
5
 
@@ -7,11 +8,13 @@ def ratingWordCata(req: HttpRequest):
7
  if req.method == "POST":
8
  try:
9
  data = json.loads(req.body.decode("utf-8"))
10
- words = data.get("words", [])
 
11
 
12
- print(words)
13
-
14
- return JsonResponse({"message": "Datos recibidos correctamente"})
 
15
  except Exception as e:
16
  print("Error:", e)
17
  return JsonResponse({"error": "Error procesando datos"}, status=400)
 
1
  from django.http import HttpRequest, JsonResponse
2
  from tecnicas.utils import general_error
3
+ from tecnicas.controllers import RatingCataController
4
  import json
5
 
6
 
 
8
  if req.method == "POST":
9
  try:
10
  data = json.loads(req.body.decode("utf-8"))
11
+ raw_words = data.get("words", [])
12
+ raw_product = data.get("product", [])
13
 
14
+ response = RatingCataController.saveRatingWords(
15
+ request=req, data_words=raw_words, data_prodct=raw_product)
16
+ return response
17
+ return JsonResponse({"message": "Error procesando datos"})
18
  except Exception as e:
19
  print("Error:", e)
20
  return JsonResponse({"error": "Error procesando datos"}, status=400)