Hello everyone I have modified an SQLFORM.Smartgrid so when i Edit a record
I only can modify a part of the data.
I need to make some validations, so I added a myValidation to the form (and
it renders OK). However no validation is made on the form and
a response.flash with the "Success!" appears after submit the form.
In the example the error is forced so the form is not submitted
Here is some code so you can see what I am doing:
Controller documento.py
# -*- coding: utf-8 -*-
@auth.requires_login()
def nuevoDocumento():
if 'edit' in request.args:
print request.args
redirect(URL('cambiarArea',
args=(request.args[3]),vars=dict(documentoID=request.args[3])))
form=SQLFORM.smartgrid(db.t_documentos)
db.t_documentos.f_areaActual.readable=False
db.t_documentos.f_areaActual.value = obtenerArea()
return dict(form=form)
@auth.requires_login()
def cambiarArea():
print request.args
query = (db.t_documentos.id ==request.args[0])
documento = db(query).select().first()
#db.t_documentos.f_areaActual = documento[f_areaActual]
form = SQLFORM.factory(db.t_documentos.f_areaActual)
form.validate(onvalidation=validacionesExtra(form,documento))
print "Nuevo!"
if form.process().accepted:
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
#print documento.f_areaActual
return dict(message="hello from
documento/cambiarArea.py",documento=documento,form=form)
def obtenerArea():
groups = db((db.auth_membership.user_id==auth.user.id)&
(db.auth_membership.group_id==db.auth_group.id)).select(db.auth_group.role)
for area in groups:
if area in ["mesa", "juridico", "titulos"]:
areaUsuario = area
break
query = (db.t_areas.f_nombre == area.role)
idArea = db.t_areas.id
ape = db(query).select(idArea).first()[idArea]
return (ape)
def validacionesExtra(form,documento):
form.errors.f_areaActual = 'El area Origen y Destino deben ser
distintas'
View cambiarArea.html
{{extend 'layout.html'}}
<h1>This is the documento/cambiarArea.html template</h1>
{{=BEAUTIFY(response._vars)}}
Here is some log that tells me that the form is getting done:
<form action="#" class="form-horizontal" enctype="multipart/form-data"
method="post"><div class="form-group"
id="no_table_f_areaActual__row"><label class="control-label col-sm-3"
for="no_table_f_areaActual" id="no_table_f_areaActual__label">Area
Actual</label><div class="col-sm-9"><select class="generic-widget
form-control" id="no_table_f_areaActual" name="f_areaActual"><option
value=""></option><option value="2">juridico</option><option
value="1">mesa</option><option value="3">titulos</option></select><span
class="help-block"></span></div></div><div class="form-group"
id="submit_record__row"><div class="col-sm-9 col-sm-offset-3"><input
class="btn btn-primary" type="submit" value="Submit" /></div></div></form>
If you need more data, please let me know
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.