admin管理员组文章数量:1336632
I am trying to validate my fields in a more efficient way and I think I am on the right track, but I have a problem with the for loop, the code is as follows
First of all I manage all the fields through dictionaries
listaCondicion = {
"nombre" : {"min":3},
"apellido" : {"min":4},
"cedula" : {"min":7, "query":consulta.verficarCedula, "param":[f"{tipoCedula.value}-{cedula.value}",], "msj":"Esta cedula ya esta ligada a un usuario"},
"numTelefono" : {"min":7, "query":consulta.verficarNumero, "param":[f"{codigoTelefono.value}-{numTelefono.value}",], "msj":"Este numero de telefono ya esta asignado a un usuario"},
"correo" : {"min":3, "query":consulta.verificarCorreo, "param":[f"{correo.value}{tipoCorreo.value}",], "msj":"Este correo ya esta en uso"},
"ubicacion" : {"min":3, "query":consulta.verficarUbicacion, "param":[ubicacion.value,], "msj":"Esta ubicacion ya esta en uso"},
"nivelUser" : {"min":4},
"tipoCorreo" : {"min":4},
"codigoTelefono" : {"min":4}
}
Then I go through that dictionary with a for and pass it values that are inside
todoValido = True
print(todoValido)
for nombreCampo, config in listaCondicion.items():
if bool(validaciones.validarCampos(page, eval(nombreCampo), config["min"])) == True:
print("entro en la validacion de campos")
todoValido = False
if "query" in config:
if bool(validaciones.validarConsultas(page, config["query"], config["param"], config["msj"])) or todoValido == True:
todoValido = False
print("paso por validacion de la consulta")
else: print("no paso nada")
print(todoValido)
if todoValido == True:
print("pasaste a la siguiente seccion del formulario")
print()
In the interface you can see that it apparently works correctly, but I put some print in it to better follow the cycle and it always gives me this result
True
no paso nada
no paso nada
paso por consulta
no paso nada
no paso nada
no paso nada
False
I don't know what to do, it always omits the first condition, and if all the fields are correctly validated it doesn't let me go to the next form
This is the class I use to validate in case you need it
class validaciones:
#CONDICIONES
condicionAlfanum = r"^[0-9A-Za-z]*$"
condicionEspacio = r"^[^\s]+$"
def validarCampos(page, campo, min):
if not campo.value:
campo.error_text = mensaje.campoFaltante
page.update()
return False
elif len(campo.value) < min:
campo.error_text = mensaje.minimoCaracteres(min)
page.update()
return False
def validarConsultas(page, consulta, parametros, mensaje):
if db.consultaConRetorno(consulta, parametros):
page.snack_bar = SnackBar(content=Text(mensaje))
page.snack_bar.open = True
page.update()
return False
I hope you can help me, if I can make it work I will be able to apply it to all my code, thanks in advance
本文标签: problems validating form with a loop for pythonStack Overflow
版权声明:本文标题:problems validating form with a loop for python - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742380564a2464005.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论