Spaces:
Sleeping
Sleeping
Se agregan la funcion de crear palabras nuevas en panel congfiguracion de palabras
Browse files- tecnicas/forms/__init__.py +2 -1
- tecnicas/forms/word_form.py +36 -0
- tecnicas/static/js/panel-words.js +58 -68
- tecnicas/templates/tecnicas/create_sesion/configuracion-panel-words.html +28 -1
- tecnicas/test/test_words.py +32 -14
- tecnicas/views/api_words.py +25 -16
- tecnicas/views/configuration_panel_words.py +7 -3
tecnicas/forms/__init__.py
CHANGED
|
@@ -2,4 +2,5 @@ from .sesion_basic_form import SesionBasicForm
|
|
| 2 |
from .sesion_tags_form import SesionTagsForm
|
| 3 |
from .etiqueta_form import EtiquetaForm
|
| 4 |
from .codes_form import CodesForm
|
| 5 |
-
from .catador_form import CatadorForm
|
|
|
|
|
|
| 2 |
from .sesion_tags_form import SesionTagsForm
|
| 3 |
from .etiqueta_form import EtiquetaForm
|
| 4 |
from .codes_form import CodesForm
|
| 5 |
+
from .catador_form import CatadorForm
|
| 6 |
+
from .word_form import WordForm
|
tecnicas/forms/word_form.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django import forms
|
| 2 |
+
|
| 3 |
+
from ..models import Palabra
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class WordForm(forms.ModelForm):
|
| 7 |
+
class Meta:
|
| 8 |
+
model = Palabra
|
| 9 |
+
fields = ["nombre_palabra"]
|
| 10 |
+
|
| 11 |
+
labels = {
|
| 12 |
+
"nombre_palabra": "nombre_palabra"
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
widgets = {
|
| 16 |
+
"nombre_palabra": forms.TextInput(attrs={
|
| 17 |
+
"class": "bg-gray-300 border-b text-center text-black pb-1 rounded",
|
| 18 |
+
"placeholder": "Ingrese palabra",
|
| 19 |
+
"oninput": "this.value = this.value.toLowerCase()"
|
| 20 |
+
})
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
error_messages = {
|
| 24 |
+
"nombre_palabra": {
|
| 25 |
+
"required": "parametros requeridos",
|
| 26 |
+
"unique": "palabra repetida"
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
def clean_nombre_palabra(self):
|
| 31 |
+
nombre_palabra = self.cleaned_data.get('nombre_palabra')
|
| 32 |
+
|
| 33 |
+
if nombre_palabra:
|
| 34 |
+
nombre_palabra = nombre_palabra.lower().strip()
|
| 35 |
+
|
| 36 |
+
return nombre_palabra
|
tecnicas/static/js/panel-words.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
const imgList = document.querySelector(".ct-img-list");
|
| 2 |
|
| 3 |
const listWordsSelect = [];
|
|
@@ -131,14 +134,10 @@ function showWordsFound(words) {
|
|
| 131 |
|
| 132 |
function addWordToUse(word) {
|
| 133 |
if (listWordsSelect.find((w) => w.id === word.id)) {
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
setTimeout(() => {
|
| 139 |
-
noti.classList.add("hidden");
|
| 140 |
-
}, 1800);
|
| 141 |
-
|
| 142 |
return;
|
| 143 |
}
|
| 144 |
|
|
@@ -146,7 +145,25 @@ function addWordToUse(word) {
|
|
| 146 |
updatelistWordsSelect();
|
| 147 |
}
|
| 148 |
|
| 149 |
-
function spanNotificationRed(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
function removeWordToUse(word) {
|
| 152 |
const index = listWordsSelect.findIndex((w) => w.id === word.id);
|
|
@@ -172,72 +189,45 @@ function updatelistWordsSelect() {
|
|
| 172 |
}
|
| 173 |
}
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
const
|
| 179 |
-
|
| 180 |
-
for (let i = 0; i < tagsWords.length; i++) {
|
| 181 |
-
let atributes = tagsWords.item(i).children;
|
| 182 |
-
allWords.push({
|
| 183 |
-
id: atributes[1].innerText,
|
| 184 |
-
name: atributes[0].innerText,
|
| 185 |
-
selected: false,
|
| 186 |
-
});
|
| 187 |
-
}
|
| 188 |
-
|
| 189 |
-
for (let i = 1; i <= numberWords; i++) {
|
| 190 |
-
const select = creadSelect(i);
|
| 191 |
-
selectWordsContainer.appendChild(select);
|
| 192 |
-
}
|
| 193 |
|
| 194 |
-
function
|
| 195 |
-
|
| 196 |
-
label.attributes["form"] = `palabra-${index}`;
|
| 197 |
-
label.classList.add(
|
| 198 |
-
"font-medium",
|
| 199 |
-
"py-2",
|
| 200 |
-
"px-3",
|
| 201 |
-
"bg-gray-200",
|
| 202 |
-
"capitalize",
|
| 203 |
-
"rounded",
|
| 204 |
-
"text-center"
|
| 205 |
-
);
|
| 206 |
|
| 207 |
-
const
|
| 208 |
-
|
| 209 |
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
select.required = true;
|
| 214 |
-
select.classList.add(
|
| 215 |
-
"ct-select-op",
|
| 216 |
-
"p-1",
|
| 217 |
-
"rounded",
|
| 218 |
-
"bg-gray-500",
|
| 219 |
-
"[*]:capitalize",
|
| 220 |
-
"[*]:text-white"
|
| 221 |
);
|
| 222 |
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
-
|
| 230 |
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
select.appendChild(option);
|
| 236 |
-
});
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
|
|
|
| 240 |
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
| 242 |
}
|
| 243 |
-
*/
|
|
|
|
| 1 |
+
// **************************************
|
| 2 |
+
// Logic for get to words and render UI
|
| 3 |
+
// **************************************
|
| 4 |
const imgList = document.querySelector(".ct-img-list");
|
| 5 |
|
| 6 |
const listWordsSelect = [];
|
|
|
|
| 134 |
|
| 135 |
function addWordToUse(word) {
|
| 136 |
if (listWordsSelect.find((w) => w.id === word.id)) {
|
| 137 |
+
spanNotificationRed(
|
| 138 |
+
`La palabra "${word.nombre_palabra}" ya fue seleccionada`
|
| 139 |
+
);
|
| 140 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
return;
|
| 142 |
}
|
| 143 |
|
|
|
|
| 145 |
updatelistWordsSelect();
|
| 146 |
}
|
| 147 |
|
| 148 |
+
function spanNotificationRed(errorMessage) {
|
| 149 |
+
const noti = document.querySelector(".ct-notification-red");
|
| 150 |
+
noti.textContent = errorMessage;
|
| 151 |
+
noti.classList.remove("hidden");
|
| 152 |
+
|
| 153 |
+
setTimeout(() => {
|
| 154 |
+
noti.classList.add("hidden");
|
| 155 |
+
}, 2500);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
function spanNotificationGreen(message) {
|
| 159 |
+
const noti = document.querySelector(".ct-notification-green");
|
| 160 |
+
noti.textContent = message;
|
| 161 |
+
noti.classList.remove("hidden");
|
| 162 |
+
|
| 163 |
+
setTimeout(() => {
|
| 164 |
+
noti.classList.add("hidden");
|
| 165 |
+
}, 3000);
|
| 166 |
+
}
|
| 167 |
|
| 168 |
function removeWordToUse(word) {
|
| 169 |
const index = listWordsSelect.findIndex((w) => w.id === word.id);
|
|
|
|
| 189 |
}
|
| 190 |
}
|
| 191 |
|
| 192 |
+
// **************************************
|
| 193 |
+
// Logic for post new Word
|
| 194 |
+
// **************************************
|
| 195 |
+
const formNewWord = document.querySelector(".ct-form-new-word");
|
| 196 |
+
formNewWord.addEventListener("submit", postNewWord);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
+
async function postNewWord(e) {
|
| 199 |
+
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
+
const dataForm = new FormData(this);
|
| 202 |
+
const url = "api/palabras";
|
| 203 |
|
| 204 |
+
dataForm.set(
|
| 205 |
+
"nombre_palabra",
|
| 206 |
+
dataForm.get("nombre_palabra").trim().toLowerCase()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
);
|
| 208 |
|
| 209 |
+
try {
|
| 210 |
+
const respone = await fetch(url, {
|
| 211 |
+
method: "POST",
|
| 212 |
+
headers: {
|
| 213 |
+
"X-CSRFToken": dataForm.get("csrfmiddlewaretoken"),
|
| 214 |
+
},
|
| 215 |
+
body: dataForm,
|
| 216 |
+
});
|
| 217 |
|
| 218 |
+
const jsonResponse = await respone.json();
|
| 219 |
|
| 220 |
+
if (jsonResponse.error) {
|
| 221 |
+
spanNotificationRed(`Error: ${jsonResponse.error}`);
|
| 222 |
+
return;
|
| 223 |
+
}
|
|
|
|
|
|
|
| 224 |
|
| 225 |
+
const word = jsonResponse["data"];
|
| 226 |
+
addWordToUse(word);
|
| 227 |
+
spanNotificationGreen(jsonResponse["message"]);
|
| 228 |
|
| 229 |
+
formNewWord.reset();
|
| 230 |
+
} catch (error) {
|
| 231 |
+
spanNotificationRed(`Error: ${error}`);
|
| 232 |
+
}
|
| 233 |
}
|
|
|
tecnicas/templates/tecnicas/create_sesion/configuracion-panel-words.html
CHANGED
|
@@ -27,6 +27,9 @@
|
|
| 27 |
<section class="flex-3/5 flex flex-col gap-4">
|
| 28 |
<form action="" method="get" class="ct-serach-words">
|
| 29 |
{% csrf_token %}
|
|
|
|
|
|
|
|
|
|
| 30 |
<section class="flex flex-row gap-2">
|
| 31 |
<label for="search" class="w-full">
|
| 32 |
<input type="text" name="search" id="search" placeholder="Buscar palabra"
|
|
@@ -56,8 +59,32 @@
|
|
| 56 |
</section>
|
| 57 |
</article>
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
<article
|
| 60 |
-
class="ct-notification-
|
| 61 |
</article>
|
| 62 |
</article>
|
| 63 |
</section>
|
|
|
|
| 27 |
<section class="flex-3/5 flex flex-col gap-4">
|
| 28 |
<form action="" method="get" class="ct-serach-words">
|
| 29 |
{% csrf_token %}
|
| 30 |
+
<p class="text-lg font-bold text-center mb-2 bg-gray-600 p-2 rounded text-white">
|
| 31 |
+
Dejar en blaco para buscar las primeras 10 palabras
|
| 32 |
+
</p>
|
| 33 |
<section class="flex flex-row gap-2">
|
| 34 |
<label for="search" class="w-full">
|
| 35 |
<input type="text" name="search" id="search" placeholder="Buscar palabra"
|
|
|
|
| 59 |
</section>
|
| 60 |
</article>
|
| 61 |
|
| 62 |
+
<article class="ct-new-tags bg-gray-600 p-5 flex justify-center items-center rounded-2xl">
|
| 63 |
+
<form method="post" action="" class="ct-form-new-word p-3">
|
| 64 |
+
{% csrf_token %}
|
| 65 |
+
<p class="mb-4 text-2xl font-bold text-center text-white">¿No encuentras una palabra?</p>
|
| 66 |
+
<label for="{{ form_word.nombre_palabra.id_for_label }}"
|
| 67 |
+
class="font-medium text-xl text-white flex gap-3 mb-4">
|
| 68 |
+
<p class="px-4">Nueva palabra:</p>
|
| 69 |
+
{{ form_word.nombre_palabra }}
|
| 70 |
+
</label>
|
| 71 |
+
<p
|
| 72 |
+
class="ct-error-word mb-4 font-bold bg-red-500 text-white text-md capitalize text-center rounded hidden">
|
| 73 |
+
error</p>
|
| 74 |
+
<hr class="text-white">
|
| 75 |
+
<article class="flex justify-center gap-8 mt-4 text-white font-medium tracking-wide">
|
| 76 |
+
<button class="rounded px-3 py-1 bg-green-700 active:bg-green-600" type="submit">
|
| 77 |
+
Crear y agregar a la lista
|
| 78 |
+
</button>
|
| 79 |
+
</article>
|
| 80 |
+
</form>
|
| 81 |
+
</article>
|
| 82 |
+
|
| 83 |
+
<article
|
| 84 |
+
class="ct-notification-red absolute max-md:fixed bottom-0 mb-4 left-1/2 -translate-x-1/2 bg-red-600 text-white p-2 px-4 rounded-lg text-center font-medium hidden uppercase">
|
| 85 |
+
</article>
|
| 86 |
<article
|
| 87 |
+
class="ct-notification-green absolute max-md:fixed bottom-0 mb-4 left-1/2 -translate-x-1/2 bg-green-600 text-white p-2 px-4 rounded-lg text-center font-medium hidden uppercase">
|
| 88 |
</article>
|
| 89 |
</article>
|
| 90 |
</section>
|
tecnicas/test/test_words.py
CHANGED
|
@@ -36,7 +36,8 @@ class TestsApiWords(TestCase):
|
|
| 36 |
word_name = "sal"
|
| 37 |
expected_message = "datos localizados"
|
| 38 |
|
| 39 |
-
expected_data = Palabra.objects.filter(
|
|
|
|
| 40 |
|
| 41 |
response = self.client.get(
|
| 42 |
reverse("cata_system:api_palabras")+f"?palabra={word_name}"
|
|
@@ -56,12 +57,11 @@ class TestsApiWords(TestCase):
|
|
| 56 |
word_name = "dulce"
|
| 57 |
expected_message = "palabra creada"
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
)
|
| 63 |
|
| 64 |
-
self.
|
| 65 |
|
| 66 |
res_json = response.json()
|
| 67 |
|
|
@@ -73,28 +73,46 @@ class TestsApiWords(TestCase):
|
|
| 73 |
self.assertIn("nombre_palabra", data)
|
| 74 |
self.assertEqual(data["nombre_palabra"], word_name)
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
def test_post_word_fail(self):
|
| 77 |
word_name = "salado"
|
| 78 |
expected_error = "palabra repetida"
|
| 79 |
|
|
|
|
|
|
|
| 80 |
response = self.client.post(
|
| 81 |
reverse("cata_system:api_palabras"),
|
| 82 |
-
data
|
| 83 |
)
|
| 84 |
|
| 85 |
-
self.assertEqual(response.status_code, 200)
|
| 86 |
-
|
| 87 |
res_json = response.json()
|
| 88 |
self.assertIn("error", res_json)
|
| 89 |
self.assertEqual(res_json["error"], expected_error)
|
| 90 |
-
|
| 91 |
def test_post_word_no_parameter(self):
|
| 92 |
-
expected_error = "parametros
|
| 93 |
|
| 94 |
response = self.client.post(reverse("cata_system:api_palabras"))
|
| 95 |
|
| 96 |
-
self.assertEqual(response.status_code, 200)
|
| 97 |
-
|
| 98 |
res_json = response.json()
|
| 99 |
self.assertIn("error", res_json)
|
| 100 |
-
self.assertEqual(res_json["error"], expected_error)
|
|
|
|
| 36 |
word_name = "sal"
|
| 37 |
expected_message = "datos localizados"
|
| 38 |
|
| 39 |
+
expected_data = Palabra.objects.filter(
|
| 40 |
+
nombre_palabra__contains=word_name)
|
| 41 |
|
| 42 |
response = self.client.get(
|
| 43 |
reverse("cata_system:api_palabras")+f"?palabra={word_name}"
|
|
|
|
| 57 |
word_name = "dulce"
|
| 58 |
expected_message = "palabra creada"
|
| 59 |
|
| 60 |
+
data = {
|
| 61 |
+
"nombre_palabra": word_name
|
| 62 |
+
}
|
|
|
|
| 63 |
|
| 64 |
+
response = self.client.post(reverse("cata_system:api_palabras"), data)
|
| 65 |
|
| 66 |
res_json = response.json()
|
| 67 |
|
|
|
|
| 73 |
self.assertIn("nombre_palabra", data)
|
| 74 |
self.assertEqual(data["nombre_palabra"], word_name)
|
| 75 |
|
| 76 |
+
def test_post_word_lowercase(self):
|
| 77 |
+
word_name = "AMargo"
|
| 78 |
+
expected_message = "palabra creada"
|
| 79 |
+
|
| 80 |
+
data = {
|
| 81 |
+
"nombre_palabra": word_name
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
response = self.client.post(reverse("cata_system:api_palabras"), data)
|
| 85 |
+
|
| 86 |
+
res_json = response.json()
|
| 87 |
+
|
| 88 |
+
self.assertIn("message", res_json)
|
| 89 |
+
self.assertEqual(res_json["message"], expected_message)
|
| 90 |
+
|
| 91 |
+
data = res_json["data"]
|
| 92 |
+
self.assertIn("id", data)
|
| 93 |
+
self.assertIn("nombre_palabra", data)
|
| 94 |
+
self.assertEqual(data["nombre_palabra"], word_name.lower())
|
| 95 |
+
|
| 96 |
def test_post_word_fail(self):
|
| 97 |
word_name = "salado"
|
| 98 |
expected_error = "palabra repetida"
|
| 99 |
|
| 100 |
+
data = {"nombre_palabra": word_name}
|
| 101 |
+
|
| 102 |
response = self.client.post(
|
| 103 |
reverse("cata_system:api_palabras"),
|
| 104 |
+
data
|
| 105 |
)
|
| 106 |
|
|
|
|
|
|
|
| 107 |
res_json = response.json()
|
| 108 |
self.assertIn("error", res_json)
|
| 109 |
self.assertEqual(res_json["error"], expected_error)
|
| 110 |
+
|
| 111 |
def test_post_word_no_parameter(self):
|
| 112 |
+
expected_error = "parametros requeridos"
|
| 113 |
|
| 114 |
response = self.client.post(reverse("cata_system:api_palabras"))
|
| 115 |
|
|
|
|
|
|
|
| 116 |
res_json = response.json()
|
| 117 |
self.assertIn("error", res_json)
|
| 118 |
+
self.assertEqual(res_json["error"], expected_error)
|
tecnicas/views/api_words.py
CHANGED
|
@@ -2,17 +2,22 @@ from django.http import HttpRequest, JsonResponse
|
|
| 2 |
from django.db import IntegrityError
|
| 3 |
from ..models import Palabra
|
| 4 |
from ..utils import general_error
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def words(req: HttpRequest):
|
| 8 |
if req.method == "GET":
|
| 9 |
try:
|
| 10 |
word_name = req.GET["palabra"]
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
except KeyError:
|
| 14 |
return general_error("parametros no encontrados")
|
| 15 |
-
|
| 16 |
if not fund_words:
|
| 17 |
return general_error("no existen palabras")
|
| 18 |
|
|
@@ -25,17 +30,21 @@ def words(req: HttpRequest):
|
|
| 25 |
|
| 26 |
return JsonResponse(response)
|
| 27 |
elif req.method == "POST":
|
| 28 |
-
|
| 29 |
-
word_name = req.POST["nombre_palabra"]
|
| 30 |
-
new_word = Palabra.objects.create(nombre_palabra=word_name)
|
| 31 |
-
except KeyError:
|
| 32 |
-
return general_error("parametros no encontrados")
|
| 33 |
-
except IntegrityError:
|
| 34 |
-
return general_error("palabra repetida")
|
| 35 |
|
| 36 |
-
|
| 37 |
-
"
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from django.db import IntegrityError
|
| 3 |
from ..models import Palabra
|
| 4 |
from ..utils import general_error
|
| 5 |
+
from ..forms.word_form import WordForm
|
| 6 |
|
| 7 |
|
| 8 |
def words(req: HttpRequest):
|
| 9 |
if req.method == "GET":
|
| 10 |
try:
|
| 11 |
word_name = req.GET["palabra"]
|
| 12 |
+
|
| 13 |
+
if word_name == "":
|
| 14 |
+
fund_words = Palabra.objects.all()[:10]
|
| 15 |
+
else:
|
| 16 |
+
fund_words = Palabra.objects.filter(
|
| 17 |
+
nombre_palabra__startswith=word_name)
|
| 18 |
except KeyError:
|
| 19 |
return general_error("parametros no encontrados")
|
| 20 |
+
|
| 21 |
if not fund_words:
|
| 22 |
return general_error("no existen palabras")
|
| 23 |
|
|
|
|
| 30 |
|
| 31 |
return JsonResponse(response)
|
| 32 |
elif req.method == "POST":
|
| 33 |
+
form = WordForm(req.POST)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
if form.is_valid():
|
| 36 |
+
form.cleaned_data["nombre_palabra"] = form.cleaned_data["nombre_palabra"].lower(
|
| 37 |
+
)
|
| 38 |
+
new_word = form.save()
|
| 39 |
+
send_word = {
|
| 40 |
+
"nombre_palabra": new_word.nombre_palabra,
|
| 41 |
+
"id": new_word.id
|
| 42 |
+
}
|
| 43 |
+
response = {
|
| 44 |
+
"message": "palabra creada",
|
| 45 |
+
"data": send_word
|
| 46 |
+
}
|
| 47 |
+
return JsonResponse(response)
|
| 48 |
+
else:
|
| 49 |
+
errors = form.errors.get("nombre_palabra")
|
| 50 |
+
return general_error(errors[0])
|
tecnicas/views/configuration_panel_words.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
from django.shortcuts import render
|
| 3 |
from ..models.palabra import Palabra
|
|
|
|
|
|
|
| 4 |
|
| 5 |
def configurationPanelWords(req: HttpRequest):
|
| 6 |
if req.method == "GET":
|
| 7 |
-
|
|
|
|
| 8 |
context = {
|
| 9 |
-
"words":
|
|
|
|
| 10 |
}
|
| 11 |
-
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
|
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
from django.shortcuts import render
|
| 3 |
from ..models.palabra import Palabra
|
| 4 |
+
from ..forms.word_form import WordForm
|
| 5 |
+
|
| 6 |
|
| 7 |
def configurationPanelWords(req: HttpRequest):
|
| 8 |
if req.method == "GET":
|
| 9 |
+
form = WordForm()
|
| 10 |
+
all_words = Palabra.objects.all()
|
| 11 |
context = {
|
| 12 |
+
"words": all_words,
|
| 13 |
+
"form_word": form
|
| 14 |
}
|
| 15 |
+
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|