Spaces:
Sleeping
Sleeping
Se valida la existencia de palabras seleccionadas en configracion de sesion
Browse files
tecnicas/forms/atributes_form.py
DELETED
|
@@ -1,11 +0,0 @@
|
|
| 1 |
-
from django import forms
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
class AtributesForm(forms.Form):
|
| 5 |
-
def __init__(self, *args, atributes=[], **kwargs):
|
| 6 |
-
super().__init__(*args, **kwargs)
|
| 7 |
-
|
| 8 |
-
for index, atribute in enumerate(atributes):
|
| 9 |
-
self.fields[f'atributo_{index+1}'] = forms.CharField(max_length=150, required=True, min_length=3, initial=atribute, label=f"Atributo {index+1}", widget=forms.TextInput(attrs={
|
| 10 |
-
"class": "ct-atributo bg-gray-300 p-1 border-b-1 text-center w-full disabled:bg-gray-500 uppercase"
|
| 11 |
-
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tecnicas/static/js/panel-words.js
CHANGED
|
@@ -239,9 +239,9 @@ async function postNewWord(e) {
|
|
| 239 |
// Create Session
|
| 240 |
// **************************************
|
| 241 |
const formCreateSession = document.querySelector(".ct-creat-session");
|
| 242 |
-
formCreateSession.addEventListener("submit",
|
| 243 |
|
| 244 |
-
async function
|
| 245 |
e.preventDefault();
|
| 246 |
|
| 247 |
if (listWordsSelect.length === 0) {
|
|
|
|
| 239 |
// Create Session
|
| 240 |
// **************************************
|
| 241 |
const formCreateSession = document.querySelector(".ct-creat-session");
|
| 242 |
+
formCreateSession.addEventListener("submit", submitSelectWords);
|
| 243 |
|
| 244 |
+
async function submitSelectWords(e) {
|
| 245 |
e.preventDefault();
|
| 246 |
|
| 247 |
if (listWordsSelect.length === 0) {
|
tecnicas/templates/tecnicas/create_sesion/configuracion-panel-words.html
CHANGED
|
@@ -92,7 +92,7 @@
|
|
| 92 |
{% csrf_token %}
|
| 93 |
<button type="submit" name="start"
|
| 94 |
class="text-lg tracking-wider font-medium p-2 px-4 border-b-2 active:border-b-0 active:border-t-2 active:border-yellow-500 border-yellow-800 transition-all rounded-xl bg-yellow-500 text-white w-fit capitalize">
|
| 95 |
-
|
| 96 |
</button>
|
| 97 |
</form>
|
| 98 |
</article>
|
|
|
|
| 92 |
{% csrf_token %}
|
| 93 |
<button type="submit" name="start"
|
| 94 |
class="text-lg tracking-wider font-medium p-2 px-4 border-b-2 active:border-b-0 active:border-t-2 active:border-yellow-500 border-yellow-800 transition-all rounded-xl bg-yellow-500 text-white w-fit capitalize">
|
| 95 |
+
Crear sesión
|
| 96 |
</button>
|
| 97 |
</form>
|
| 98 |
</article>
|
tecnicas/views/configuration_panel_words.py
CHANGED
|
@@ -2,7 +2,7 @@ from django.http import HttpRequest
|
|
| 2 |
from django.shortcuts import render, redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from ..models.palabra import Palabra
|
| 5 |
-
from ..forms
|
| 6 |
|
| 7 |
import json
|
| 8 |
|
|
@@ -25,27 +25,18 @@ def configurationPanelWords(req: HttpRequest):
|
|
| 25 |
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
| 26 |
|
| 27 |
words = json.loads(req.POST.get("words"))
|
| 28 |
-
|
| 29 |
context["words"] = words
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# all_words = Palabra.objects.all()
|
| 35 |
-
# context = {
|
| 36 |
-
# "words": all_words,
|
| 37 |
-
# "form_word": form
|
| 38 |
-
# }
|
| 39 |
-
|
| 40 |
-
# if form.is_valid():
|
| 41 |
-
# new_word = form.cleaned_data.get("nombre_palabra")
|
| 42 |
-
# if not Palabra.objects.filter(nombre_palabra__iexact=new_word).exists():
|
| 43 |
-
# Palabra.objects.create(nombre_palabra=new_word)
|
| 44 |
-
# context["form_word"] = WordForm()
|
| 45 |
-
# context["words"] = Palabra.objects.all()
|
| 46 |
-
# else:
|
| 47 |
-
# context["error"] = "La palabra ya existe"
|
| 48 |
-
# else:
|
| 49 |
-
# context["error"] = "Error en los datos recibidos"
|
| 50 |
|
| 51 |
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
|
|
|
| 2 |
from django.shortcuts import render, redirect
|
| 3 |
from django.urls import reverse
|
| 4 |
from ..models.palabra import Palabra
|
| 5 |
+
from ..forms import WordForm
|
| 6 |
|
| 7 |
import json
|
| 8 |
|
|
|
|
| 25 |
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
| 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 |
+
if len(ids_words) != len(set(ids_words)):
|
| 33 |
+
context["error"] = "existen palabras duplicadas"
|
| 34 |
+
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
| 35 |
+
|
| 36 |
+
exist_words = Palabra.objects.filter(id__in=ids_words).count() == len(ids_words)
|
| 37 |
|
| 38 |
+
if not exist_words:
|
| 39 |
+
context["error"] = "algunas palabras no existen"
|
| 40 |
+
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
return render(req, "tecnicas/create_sesion/configuracion-panel-words.html", context)
|