[web2py] Problem with checkboxes

2013-01-30 Thread nicormoreno
I have a really stupid problem with checkboxes in web2py, i cant get the 
value once a form submit, this is my code:

A javascript modal that show the form



x
Editar pregunta:



{{for q in questions:}}

Orden (lugar dentro del formulario):
Pregunta:

Ayuda:

Obligatorio:
Mas de un autor:
Mostrar en resumen a usuario:
Mostrar en resumen a administrador:
  
{{pass}}


Guardar 
cambios
Cerrar




And the code to save the info in the database:

@auth.requires_membership('admin')
def save_contest_template():
contest_id = request.args[0]

questions_db = 
db(contest_id==db.contest_field.contest).select(db.contest_field.ALL)
for q in questions_db:   
var = "question-" + str(q['id'])  
if request.vars[var] != "":
q.update_record(name=request.vars[var])
var = "help-"+ str(q['id'])
if request.vars[var] != "":
q.update_record(help=request.vars[var])
var = "t_order-"+ str(q['id'])
if request.vars[var] != "":
q.update_record(t_order=request.vars[var])
var = "required-"+ str(q['id']) 
try:
if request.vars[var] is not None:
q.update_record(is_required=True)
except KeyError ,e:
q.update_record(is_required=False)
var = "authors-"+ str(q['id']) 
try:
if request.vars[var] is not None:
q.update_record(many_authors=True)
except KeyError ,e:
q.update_record(many_authors=False)
var = "user_summary-"+ str(q['id']) 
try:
if request.vars[var] is not None:
q.update_record(user_summary=True)
except KeyError ,e:
q.update_record(user_summary=False)
var = "admin_summary-"+ str(q['id']) 
try:
if request.vars[var] is not None:
q.update_record(admin_summary=True)
except KeyError ,e:
q.update_record(admin_summary=False)
redirect(URL('contestedit?contest='+contest_id+'&activeTab=2'))

it works fine for the non checkbox values, but i cant get the checked state 
from checkboxes, i google a litle and find that the checkboxes should have 
value='on' when they are checked, but thats not working for me either

-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Problem with checkboxes widget

2010-09-05 Thread Fran
I'm running latest stable release (Bzr r2247) & trying to use this for
a multiselect field:
widget = SQLFORM.widgets.checkboxes.widget

But it's not working properly.
The create form works fine - the widget appears to work fine & the
database is indeed populated properly with the expected:
'|8|9|7|'
This displays fine in read screens.
However it fails to work in update forms - the checkboxes don't show
up as checked & so if the record is saved then the previous checkbox
states are lost :/

I tracked this down to:
http://bazaar.launchpad.net/~mdipierro/web2py/devel/annotate/head:/gluon/sqlhtml.py#L268
(value = '|8|9|7|')
values = not isinstance(value,(list,tuple)) and [value] or value
(values = ['|8|9|7|'])
k in values
(False)

The old, commented, code works fine though:
values = re.compile('[\w\-:]+').findall(str(value))
(values = ['8', '9', '7'])
k in values
(True)

I think the change was made to avoid a relatively slow call to 're'
right?
However it seems not to work properly...

Many thanks :)
Fran.