Re: [web2py] Re: Loop on form.process(). Validation is not done

2012-09-14 Thread Luis Furtado
No, I don't manage the form submission.
Just use jQuery to:
1. fill in user_id
2. populate a select dropdown depending on an option on another select
3. add some titles in the form

-- index.html 
{{ extend 'modelo.html' }}
{{ =response.toolbar() }}
R_ID = {{ =session.r_id }}
{{=form}}


jQuery( document).ready( function() {

   jQuery("#r_municipio__row" ).before("

A - IDENTIFICAÇÃO DA EXPLORAÇÃO

") jQuery("#r_p_nome__row" ).before("

B - PRODUTOR

") jQuery("#r_user_id").val( {{ =auth.user_id or 0 }} ) // Copia valor do user_id da sessao para o da tabela jQuery("#r_municipio").change( function () { $.get( "ajax_freguesia", "codconc="+ $("#r_municipio").val(), function (result) { $("#r_freguesia").html( result); } ) }) }); Now I just read M.di Pierro's reply and I will try web2py 2.0.9. Luis On Friday, 14 September 2012 17:05:23 UTC+1, rochacbruno wrote: > > What do you have in your view? are you using any JavaScript to manage the > form submission? --

[web2py] Re: Loop on form.process(). Validation is not done

2012-09-14 Thread Massimo Di Pierro
Make sure you are using 2.0.9 because there is a subtle issue in 2.0.x 
(x<9) which may affect the behavior in your case.

On Friday, September 14, 2012 9:04:49 AM UTC-5, Luis Furtado wrote:
>
> I'm calling session.forget() to try and fix the problem, but it didn't.
> Anyway, the problem was there before that. I just removed it and it made 
> no difference.
>
> The whole behaviour of the app is variable. 
> Sometimes it does the validation phase and then I fill it w/o errors and, 
> after submitting, the app. goes on to the 2nd form.
> Other times it just won't do any validation and restarts the app.
> When this happens, it usually goes to an URL like this:
>
> http://127.0.0.1:8000/nova/default/f_prod?_formkey=bd681283-abd1-4e18-885b-2597984db8ee&_formname=prod%2Fcreate&cmr_convenc=98&cmr_mpb=7&cmr_seco=&cmr_verde=&codigo=4600&r_id=40&_signature=344c90d0588ad87ce1f587024fe826ccf260d2dc
>
> When all goes well there are no GET args on the URL.
> I've checked in the html code created, it is .
>
> Another problem is it never executes "session.r_id = form.vars.id" after 
> form accepted. Maybe I should address this in a different post.
>
> This is my 1st web2py app.
> What am I missing?
>
> Thanks
> Luis
>
>
> On Friday, 14 September 2012 09:10:59 UTC+1, Niphlod wrote:
>>
>> why are you calling session.forget() ?
>>
>> On Thursday, September 13, 2012 8:43:30 PM UTC+2, Luis Furtado wrote:
>>>
>>> Hello,
>>> When I submit the form no validation errors are shown and, after a few 
>>> seconds, it just shows the form again, totally blank even if I had filled 
>>> some fields.
>>> If I include @auth.requires_login() at index() it even gets back to 
>>> login instead of the form.
>>> It seems as if the application is restarted when it tries to do the 
>>> validation phase.
>>>
>>> --- MODEL 
>>> db = DAL('sqlite://storage.sqlite')
>>>
>>> db.define_table( 'concelho',   Field('codigo'),   Field('nome'),
>>>  format='%(nome)s')
>>>
>>> db.define_table( 'freguesia',
>>>Field('cod_concelho', requires= IS_IN_DB( db, db.concelho.codigo )),
>>>Field('codigo'),
>>>Field('nome'),  
>>>format='%(nome)s'
>>> )
>>>
>>> db.define_table( 'r',
>>>Field('user_id', 'integer'),
>>>Field('municipio', requires= IS_IN_DB( db, db.concelho.codigo, 
>>> '%(nome)s')),
>>>Field('freguesia', requires= IS_IN_DB( db, db.freguesia.codigo, 
>>> '%(nome)s')),
>>>Field('morada', requires= IS_NOT_EMPTY()),
>>>Field('cod_postal', requires= IS_MATCH('^\d{4}-\d{3}$')),
>>>Field('nif', requires= IS_MATCH('^\d{9}$')),
>>>Field('nat_juridica', requires= IS_IN_SET(['AUT','EMP','SOC'])),
>>>Field('ini_agricola', 'integer', requires= IS_EMPTY_OR( 
>>> IS_INT_IN_RANGE( 1970, 2012))), 
>>>Field('p_nome', requires= IS_NOT_EMPTY()),
>>>Field('nascimento', 'date', requires = IS_EMPTY_OR( IS_DATE( 
>>> format='%Y-%m-%d'))),
>>>Field('escolaridade', requires = 
>>> IS_IN_SET(['Básico','Secundário','Licenciatura','Mestrado']))
>>> )
>>>
>>> db.define_table( 'prod',
>>>Field('r_id', db.r ),
>>>Field('codigo', 'integer',label='Espécie', requires= IS_NOT_EMPTY()),
>>>Field('cmr_convenc', 'integer',label='Convencional', requires= 
>>> IS_NOT_EMPTY()),
>>>Field('cmr_mpb', 'integer',label='M.P.Biológico',requires= 
>>> IS_NOT_EMPTY())
>>> )
>>> -- CONTROLLER -
>>> def index():
>>>session.forget()
>>>session.r_id = 40 # Initial value -- will be replaced by form.vars.id
>>>
>>>form = SQLFORM( db.r)
>>>if form.process( next=URL('f_prod') ).accepted:
>>>   session.r_id = form.vars.id
>>>   response.flash = 'Success (R_ID=%s)' % session.r_id
>>>elif form.errors:
>>>   response.flash = 'ERRORS in the form'
>>>else:
>>>   response.flash = 'Form 1 of 2'
>>>
>>>return dict( form=form)
>>>
>>>
>>> def f_prod():
>>>
>>> RID = session.r_id
>>>
>>> form = SQLFORM( db.prod)
>>> if form.process().accepted:
>>>response.flash = 'Success'
>>> elif form.errors:
>>>response.flash = 'ERRORS'
>>> else:
>>>response.flash = 'Form 2 of 2'
>>>
>>> return dict( form=form, RID=RID)
>>> -
>>> What's wrong?
>>> Thanks
>>> Luis
>>>
>>>

-- 





Re: [web2py] Re: Loop on form.process(). Validation is not done

2012-09-14 Thread Bruno Rocha
What do you have in your view? are you using any JavaScript to manage the
form submission?

-- 





[web2py] Re: Loop on form.process(). Validation is not done

2012-09-14 Thread Luis Furtado
I'm calling session.forget() to try and fix the problem, but it didn't.
Anyway, the problem was there before that. I just removed it and it made no 
difference.

The whole behaviour of the app is variable. 
Sometimes it does the validation phase and then I fill it w/o errors and, 
after submitting, the app. goes on to the 2nd form.
Other times it just won't do any validation and restarts the app.
When this happens, it usually goes to an URL like this:
http://127.0.0.1:8000/nova/default/f_prod?_formkey=bd681283-abd1-4e18-885b-2597984db8ee&_formname=prod%2Fcreate&cmr_convenc=98&cmr_mpb=7&cmr_seco=&cmr_verde=&codigo=4600&r_id=40&_signature=344c90d0588ad87ce1f587024fe826ccf260d2dc

When all goes well there are no GET args on the URL.
I've checked in the html code created, it is .

Another problem is it never executes "session.r_id = form.vars.id" after 
form accepted. Maybe I should address this in a different post.

This is my 1st web2py app.
What am I missing?

Thanks
Luis


On Friday, 14 September 2012 09:10:59 UTC+1, Niphlod wrote:
>
> why are you calling session.forget() ?
>
> On Thursday, September 13, 2012 8:43:30 PM UTC+2, Luis Furtado wrote:
>>
>> Hello,
>> When I submit the form no validation errors are shown and, after a few 
>> seconds, it just shows the form again, totally blank even if I had filled 
>> some fields.
>> If I include @auth.requires_login() at index() it even gets back to login 
>> instead of the form.
>> It seems as if the application is restarted when it tries to do the 
>> validation phase.
>>
>> --- MODEL 
>> db = DAL('sqlite://storage.sqlite')
>>
>> db.define_table( 'concelho',   Field('codigo'),   Field('nome'),
>>  format='%(nome)s')
>>
>> db.define_table( 'freguesia',
>>Field('cod_concelho', requires= IS_IN_DB( db, db.concelho.codigo )),
>>Field('codigo'),
>>Field('nome'),  
>>format='%(nome)s'
>> )
>>
>> db.define_table( 'r',
>>Field('user_id', 'integer'),
>>Field('municipio', requires= IS_IN_DB( db, db.concelho.codigo, 
>> '%(nome)s')),
>>Field('freguesia', requires= IS_IN_DB( db, db.freguesia.codigo, 
>> '%(nome)s')),
>>Field('morada', requires= IS_NOT_EMPTY()),
>>Field('cod_postal', requires= IS_MATCH('^\d{4}-\d{3}$')),
>>Field('nif', requires= IS_MATCH('^\d{9}$')),
>>Field('nat_juridica', requires= IS_IN_SET(['AUT','EMP','SOC'])),
>>Field('ini_agricola', 'integer', requires= IS_EMPTY_OR( 
>> IS_INT_IN_RANGE( 1970, 2012))), 
>>Field('p_nome', requires= IS_NOT_EMPTY()),
>>Field('nascimento', 'date', requires = IS_EMPTY_OR( IS_DATE( 
>> format='%Y-%m-%d'))),
>>Field('escolaridade', requires = 
>> IS_IN_SET(['Básico','Secundário','Licenciatura','Mestrado']))
>> )
>>
>> db.define_table( 'prod',
>>Field('r_id', db.r ),
>>Field('codigo', 'integer',label='Espécie', requires= IS_NOT_EMPTY()),
>>Field('cmr_convenc', 'integer',label='Convencional', requires= 
>> IS_NOT_EMPTY()),
>>Field('cmr_mpb', 'integer',label='M.P.Biológico',requires= 
>> IS_NOT_EMPTY())
>> )
>> -- CONTROLLER -
>> def index():
>>session.forget()
>>session.r_id = 40 # Initial value -- will be replaced by form.vars.id
>>
>>form = SQLFORM( db.r)
>>if form.process( next=URL('f_prod') ).accepted:
>>   session.r_id = form.vars.id
>>   response.flash = 'Success (R_ID=%s)' % session.r_id
>>elif form.errors:
>>   response.flash = 'ERRORS in the form'
>>else:
>>   response.flash = 'Form 1 of 2'
>>
>>return dict( form=form)
>>
>>
>> def f_prod():
>>
>> RID = session.r_id
>>
>> form = SQLFORM( db.prod)
>> if form.process().accepted:
>>response.flash = 'Success'
>> elif form.errors:
>>response.flash = 'ERRORS'
>> else:
>>response.flash = 'Form 2 of 2'
>>
>> return dict( form=form, RID=RID)
>> -
>> What's wrong?
>> Thanks
>> Luis
>>
>>

-- 





[web2py] Re: Loop on form.process(). Validation is not done

2012-09-14 Thread Massimo Di Pierro
An Niphlod implies,

session.forget()

breaks the form logic. Unless you do form.process(session=False)



On Thursday, 13 September 2012 13:43:30 UTC-5, Luis Furtado wrote:
>
> Hello,
> When I submit the form no validation errors are shown and, after a few 
> seconds, it just shows the form again, totally blank even if I had filled 
> some fields.
> If I include @auth.requires_login() at index() it even gets back to login 
> instead of the form.
> It seems as if the application is restarted when it tries to do the 
> validation phase.
>
> --- MODEL 
> db = DAL('sqlite://storage.sqlite')
>
> db.define_table( 'concelho',   Field('codigo'),   Field('nome'),
>  format='%(nome)s')
>
> db.define_table( 'freguesia',
>Field('cod_concelho', requires= IS_IN_DB( db, db.concelho.codigo )),
>Field('codigo'),
>Field('nome'),  
>format='%(nome)s'
> )
>
> db.define_table( 'r',
>Field('user_id', 'integer'),
>Field('municipio', requires= IS_IN_DB( db, db.concelho.codigo, 
> '%(nome)s')),
>Field('freguesia', requires= IS_IN_DB( db, db.freguesia.codigo, 
> '%(nome)s')),
>Field('morada', requires= IS_NOT_EMPTY()),
>Field('cod_postal', requires= IS_MATCH('^\d{4}-\d{3}$')),
>Field('nif', requires= IS_MATCH('^\d{9}$')),
>Field('nat_juridica', requires= IS_IN_SET(['AUT','EMP','SOC'])),
>Field('ini_agricola', 'integer', requires= IS_EMPTY_OR( 
> IS_INT_IN_RANGE( 1970, 2012))), 
>Field('p_nome', requires= IS_NOT_EMPTY()),
>Field('nascimento', 'date', requires = IS_EMPTY_OR( IS_DATE( 
> format='%Y-%m-%d'))),
>Field('escolaridade', requires = 
> IS_IN_SET(['Básico','Secundário','Licenciatura','Mestrado']))
> )
>
> db.define_table( 'prod',
>Field('r_id', db.r ),
>Field('codigo', 'integer',label='Espécie', requires= IS_NOT_EMPTY()),
>Field('cmr_convenc', 'integer',label='Convencional', requires= 
> IS_NOT_EMPTY()),
>Field('cmr_mpb', 'integer',label='M.P.Biológico',requires= 
> IS_NOT_EMPTY())
> )
> -- CONTROLLER -
> def index():
>session.forget()
>session.r_id = 40 # Initial value -- will be replaced by form.vars.id
>
>form = SQLFORM( db.r)
>if form.process( next=URL('f_prod') ).accepted:
>   session.r_id = form.vars.id
>   response.flash = 'Success (R_ID=%s)' % session.r_id
>elif form.errors:
>   response.flash = 'ERRORS in the form'
>else:
>   response.flash = 'Form 1 of 2'
>
>return dict( form=form)
>
>
> def f_prod():
>
> RID = session.r_id
>
> form = SQLFORM( db.prod)
> if form.process().accepted:
>response.flash = 'Success'
> elif form.errors:
>response.flash = 'ERRORS'
> else:
>response.flash = 'Form 2 of 2'
>
> return dict( form=form, RID=RID)
> -
> What's wrong?
> Thanks
> Luis
>
>

-- 





[web2py] Re: Loop on form.process(). Validation is not done

2012-09-14 Thread Niphlod
why are you calling session.forget() ?

On Thursday, September 13, 2012 8:43:30 PM UTC+2, Luis Furtado wrote:
>
> Hello,
> When I submit the form no validation errors are shown and, after a few 
> seconds, it just shows the form again, totally blank even if I had filled 
> some fields.
> If I include @auth.requires_login() at index() it even gets back to login 
> instead of the form.
> It seems as if the application is restarted when it tries to do the 
> validation phase.
>
> --- MODEL 
> db = DAL('sqlite://storage.sqlite')
>
> db.define_table( 'concelho',   Field('codigo'),   Field('nome'),
>  format='%(nome)s')
>
> db.define_table( 'freguesia',
>Field('cod_concelho', requires= IS_IN_DB( db, db.concelho.codigo )),
>Field('codigo'),
>Field('nome'),  
>format='%(nome)s'
> )
>
> db.define_table( 'r',
>Field('user_id', 'integer'),
>Field('municipio', requires= IS_IN_DB( db, db.concelho.codigo, 
> '%(nome)s')),
>Field('freguesia', requires= IS_IN_DB( db, db.freguesia.codigo, 
> '%(nome)s')),
>Field('morada', requires= IS_NOT_EMPTY()),
>Field('cod_postal', requires= IS_MATCH('^\d{4}-\d{3}$')),
>Field('nif', requires= IS_MATCH('^\d{9}$')),
>Field('nat_juridica', requires= IS_IN_SET(['AUT','EMP','SOC'])),
>Field('ini_agricola', 'integer', requires= IS_EMPTY_OR( 
> IS_INT_IN_RANGE( 1970, 2012))), 
>Field('p_nome', requires= IS_NOT_EMPTY()),
>Field('nascimento', 'date', requires = IS_EMPTY_OR( IS_DATE( 
> format='%Y-%m-%d'))),
>Field('escolaridade', requires = 
> IS_IN_SET(['Básico','Secundário','Licenciatura','Mestrado']))
> )
>
> db.define_table( 'prod',
>Field('r_id', db.r ),
>Field('codigo', 'integer',label='Espécie', requires= IS_NOT_EMPTY()),
>Field('cmr_convenc', 'integer',label='Convencional', requires= 
> IS_NOT_EMPTY()),
>Field('cmr_mpb', 'integer',label='M.P.Biológico',requires= 
> IS_NOT_EMPTY())
> )
> -- CONTROLLER -
> def index():
>session.forget()
>session.r_id = 40 # Initial value -- will be replaced by form.vars.id
>
>form = SQLFORM( db.r)
>if form.process( next=URL('f_prod') ).accepted:
>   session.r_id = form.vars.id
>   response.flash = 'Success (R_ID=%s)' % session.r_id
>elif form.errors:
>   response.flash = 'ERRORS in the form'
>else:
>   response.flash = 'Form 1 of 2'
>
>return dict( form=form)
>
>
> def f_prod():
>
> RID = session.r_id
>
> form = SQLFORM( db.prod)
> if form.process().accepted:
>response.flash = 'Success'
> elif form.errors:
>response.flash = 'ERRORS'
> else:
>response.flash = 'Form 2 of 2'
>
> return dict( form=form, RID=RID)
> -
> What's wrong?
> Thanks
> Luis
>
>

--