>
> def app_settings():
>     vertexID = session.vertexID
>     
>     record = table(vertexID=vertexID)
>    
>     form = SQLFORM(table, record, showid=False)
>
>     if form.validate():
>         if form.deleted:
>            ...
>         else:
>             viewtypeID = int(form.vars.viewtypeID)
>
>             if record and (int(record.viewtypeID) != viewtypeID):
>                 ...
>
>             get_flash(session, None, 'success', 'success')
>             redirect(URL('app_manage', args=vertexID))
>
>     elif form.errors:
>         get_flash(response, None, 'danger', 'error')
>     elif not response.flash:
>         get_flash(response, None, 'info', 'default')
>
>     return dict(form=form)
>
>
> The problem is that if record.viewtypeID is for example 2 and in the form 
> I change
> it to for example 5 the test: (int(record.viewtypeID) != viewtypeID) fails.
> Both record.viewtypeID and  form.vars.viewtypeID have value 2
>
> When I change form.validate() to form.process().accepted
> the test: (int(record.viewtypeID) != viewtypeID) evaluates to True because 
> form.vars.viewtypeID now has the value 5
>

Note, when calling .validate(), by default, dbio=False, so the record is 
not actually updated in the database. However, with .process(), by default, 
dbio=True, so the record is updated in the database. Depending on your 
exact workflow, this could explain the discrepancy.

I could not replicate the behavior your describe above in the general case 
(i.e., the record in the database starts with a value of 2 and you change 
it to 5 for the first time in the form). However, the following sequence 
will trigger the observed behavior:

   1. viewtypeID starts at 5 in the database record
   2. load the form, change viewType to 2 and submit
   3. when the form reloads with the value of 2, now change it back to 5 
   and submit <-- this will trigger the failure observed above.

In step 2 above, although the value of 2 is submitted with the form, the 
value in the database remains 5. In step 3, the form reloads with a value 
of 2, but that does not reflect the true state of the database. When the 
value of 5 is submitted in step 3, it actually matches the value that is 
still in the database, so it appears no change was made (in other words, 
although you changed the value in the *form*, you did not change the value 
in the *database*).

If the above does not explain your case, then you'll need to provide some 
sample code that replicates what you observe.

Anthony 

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