Spaces:
Sleeping
Sleeping
Se impleneta la funcion de actualizar un catador en la busqueda
Browse files
tecnicas/templates/tecnicas/catador-buscar.html
CHANGED
|
@@ -35,6 +35,18 @@
|
|
| 35 |
</label>
|
| 36 |
</section>
|
| 37 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
{% if form_catador %}
|
| 39 |
<form action="" method="post">
|
| 40 |
{% csrf_token %}
|
|
@@ -86,7 +98,7 @@
|
|
| 86 |
onclick="enableInputs()">
|
| 87 |
actualizar
|
| 88 |
</button>
|
| 89 |
-
<button type="
|
| 90 |
class="ct-btn-guardar uppercase text-lg tracking-wider font-medium p-2 px-4 border-b-2 active:border-b-0 active:border-t-2 border-green-800 transition-all rounded-xl bg-green-600 active:bg-green-400 text-white w-fit hidden">
|
| 91 |
guardar
|
| 92 |
</button>
|
|
@@ -106,6 +118,12 @@
|
|
| 106 |
<script>
|
| 107 |
const inputs = document.getElementsByClassName("ct-inputs-pos-cata")
|
| 108 |
disableInputs()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
function disableInputs () {
|
| 111 |
for (let index = 0; index < inputs.length; index++) {
|
|
|
|
| 35 |
</label>
|
| 36 |
</section>
|
| 37 |
</form>
|
| 38 |
+
{% if error %}
|
| 39 |
+
<p class="ct-notifica bg-red-500 text-center text-lg py-1 font-bold text-white tracking-wide capitalize rounded-2xl">
|
| 40 |
+
{{ error }}
|
| 41 |
+
</p>
|
| 42 |
+
{% endif %}
|
| 43 |
+
|
| 44 |
+
{% if message %}
|
| 45 |
+
<p class="ct-notifica bg-green-600 text-center text-lg py-1 font-bold text-white tracking-wide capitalize rounded-2xl">
|
| 46 |
+
{{ message }}
|
| 47 |
+
</p>
|
| 48 |
+
{% endif %}
|
| 49 |
+
|
| 50 |
{% if form_catador %}
|
| 51 |
<form action="" method="post">
|
| 52 |
{% csrf_token %}
|
|
|
|
| 98 |
onclick="enableInputs()">
|
| 99 |
actualizar
|
| 100 |
</button>
|
| 101 |
+
<button type="submit"
|
| 102 |
class="ct-btn-guardar uppercase text-lg tracking-wider font-medium p-2 px-4 border-b-2 active:border-b-0 active:border-t-2 border-green-800 transition-all rounded-xl bg-green-600 active:bg-green-400 text-white w-fit hidden">
|
| 103 |
guardar
|
| 104 |
</button>
|
|
|
|
| 118 |
<script>
|
| 119 |
const inputs = document.getElementsByClassName("ct-inputs-pos-cata")
|
| 120 |
disableInputs()
|
| 121 |
+
setTimeout(() => {
|
| 122 |
+
const notifications = document.getElementsByClassName("ct-notifica")
|
| 123 |
+
for (let index = 0; index < notifications.length; index++) {
|
| 124 |
+
notifications.item(index).classList.add("hidden")
|
| 125 |
+
}
|
| 126 |
+
}, 1800)
|
| 127 |
|
| 128 |
function disableInputs () {
|
| 129 |
for (let index = 0; index < inputs.length; index++) {
|
tecnicas/views/catador_search.py
CHANGED
|
@@ -1,25 +1,56 @@
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
-
from django.shortcuts import render
|
| 3 |
from django.db import Error
|
|
|
|
| 4 |
from ..forms import CatadorForm
|
| 5 |
from ..models import Catador
|
| 6 |
|
| 7 |
def searchCatador(req : HttpRequest):
|
| 8 |
if req.method == "GET":
|
|
|
|
|
|
|
| 9 |
try:
|
| 10 |
user = req.GET["user"]
|
| 11 |
except:
|
| 12 |
user = False
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
context = {}
|
| 15 |
-
if user:
|
| 16 |
-
try:
|
| 17 |
-
catador = Catador.objects.get(usuarioCatador=user)
|
| 18 |
-
print(catador.fechaNacimiento)
|
| 19 |
-
context["form_catador"] = CatadorForm(instance=catador)
|
| 20 |
-
except Error:
|
| 21 |
-
context["error"] = "usuario no encontrado"
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return render(req, "tecnicas/catador-buscar.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
return render(req, "tecnicas/catador-buscar.html")
|
|
|
|
| 1 |
from django.http import HttpRequest
|
| 2 |
+
from django.shortcuts import render, get_object_or_404
|
| 3 |
from django.db import Error
|
| 4 |
+
from django.core.exceptions import ObjectDoesNotExist
|
| 5 |
from ..forms import CatadorForm
|
| 6 |
from ..models import Catador
|
| 7 |
|
| 8 |
def searchCatador(req : HttpRequest):
|
| 9 |
if req.method == "GET":
|
| 10 |
+
context = {}
|
| 11 |
+
|
| 12 |
try:
|
| 13 |
user = req.GET["user"]
|
| 14 |
except:
|
| 15 |
user = False
|
| 16 |
+
|
| 17 |
+
if not user:
|
| 18 |
+
return render(req, "tecnicas/catador-buscar.html")
|
| 19 |
|
| 20 |
+
try:
|
| 21 |
+
catador = Catador.objects.get(usuarioCatador=user)
|
| 22 |
+
context["form_catador"] = CatadorForm(instance=catador)
|
| 23 |
+
except Catador.DoesNotExist:
|
| 24 |
+
context["error"] = "usuario no encontrado"
|
| 25 |
+
|
| 26 |
+
return render(req, "tecnicas/catador-buscar.html", context)
|
| 27 |
+
elif req.method == "POST":
|
| 28 |
context = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
try:
|
| 31 |
+
infoCata = req.POST
|
| 32 |
+
except:
|
| 33 |
+
infoCata = False
|
| 34 |
+
|
| 35 |
+
nameUser = req.POST["usuarioCatador"]
|
| 36 |
+
|
| 37 |
+
if not infoCata:
|
| 38 |
+
context["error"] = "ha ocurrido un error en recueperar los datos"
|
| 39 |
return render(req, "tecnicas/catador-buscar.html", context)
|
| 40 |
+
|
| 41 |
+
user = get_object_or_404(Catador, usuarioCatador=nameUser)
|
| 42 |
+
|
| 43 |
+
modelForm = CatadorForm(infoCata, instance=user)
|
| 44 |
+
|
| 45 |
+
try:
|
| 46 |
+
if not modelForm.is_valid():
|
| 47 |
+
context["error"] = "ha ocurrido un error en guardar los datos"
|
| 48 |
+
return render(req, "tecnicas/catador-buscar.html", context)
|
| 49 |
+
modelForm.save()
|
| 50 |
+
context["form_catador"] = modelForm
|
| 51 |
+
context["message"] = "usuario actualizado"
|
| 52 |
+
except:
|
| 53 |
+
context["form_catador"] = modelForm
|
| 54 |
+
context["error"] = "ha ocurrido un error en guardar los datos"
|
| 55 |
|
| 56 |
+
return render(req, "tecnicas/catador-buscar.html", context)
|