I am creating a form using SQLFORM.factory and I have diferent problems:

1 - I can't make "invisible" some values (that i Autofill later)

2- I can't add extraValidations to the Form (as I do when a create a 
sqlsmartgrid form).

I use SQLFORM because I use the ID of the inserted row to make an insert in 
another table.

Here is some code to show what i am doing:


*MODEL*

















































*#######################################db.define_table('t_areas',    
Field('f_nombre', type='string',          label=T('Nombre')),    
auth.signature,    format='%(f_nombre)s',    
migrate=settings.migrate)db.define_table('t_areas_archive',db.t_areas,Field('current_record','reference
 
t_areas',readable=False,writable=False))########################################db.define_table('t_documentos',
  
  Field('f_fechaingreso', type='date',          label=T('Ingreso')),    
Field('f_recibe', type='reference auth_user',          label=T('Recibe')),  
  Field('f_comentarios_multiline', type='text',          
label=T('Comentarios')),    Field('f_areaActual', type='reference 
t_areas',          label=T('Area Actual')),    Field('f_areaDestino', 
type='reference t_areas',          label=T('Area Destino')),    
auth.signature,    format='%(f_fechaingreso)s',    
migrate=settings.migrate)db.define_table('t_documentos_archive',db.t_documentos,Field('current_record','reference
 
t_documentos',readable=False,writable=False))########################################db.define_table('t_movimientos',
  
  Field('f_areaOrigen', type='reference t_areas',          
label=T('Area')),    Field('f_areaDestino', type='reference t_areas',      
    label=T('Destino')),    Field('f_documento', type='reference 
t_documentos',          label=T('Documento')),    Field('f_comentarios', 
type='text',          label=T('Comentarios')),    Field('f_fecha', 
type='date',          label=T('Fecha'),default=request.now, 
writable=False),    auth.signature,    format='%(f_area)s',    
migrate=settings.migrate)db.define_table('t_movimientos_archive',db.t_movimientos,Field('current_record','reference
 
t_movimientos',readable=False,writable=False))########################################Controller*








































* -*- coding: utf-8 -*[email protected]_login()def nuevoDocumento():    
form=SQLFORM.factory(db.t_documentos)    
db.t_documentos.f_areaActual.readable=False    if 
form.process(onvalidation=validacionesExtra).accepted:        idAreaOrigen 
= obtenerArea()        print("idAreaOrigen %s" %(idAreaOrigen))        
form.vars.f_areaOrigen = idAreaOrigen        id = 
db.t_documentos.insert(**db.t_documentos._filter_fields(form.vars))        
print(form.vars)        idDocumento=id        idAreaDestino= 
form.vars.f_areaDestino        idAreaOrigen= form.vars.f_areaOrigen        
comentario =  form.vars.f_comentarios_multiline        id = 
db.t_movimientos.insert(f_areaOrigen=idAreaOrigen,f_documento=id,f_areaDestino=idAreaDestino,f_comentarios=comentario)
  
      response.flash='Thanks for filling the form'    return 
dict(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    print (area)    print 
area.role    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):    print("VALIDACIONES")    if 
(form.vars.f_areaOrigen == form.vars.f_areaDestino):        response.flash 
= 'El area Origen y Destino deben ser distintas'        
form.errors.f_areaOrigen = 'El area Origen y Destino deben ser distintas'*One 
thing, I been looking at 
db.mytable._after_insert
db.mytable._after_update

should be the validations part of the table definition on the model?

PS: sorry for the multiple prints on the code.

-- 
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.

Reply via email to