[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

div class=modal hidden fade in id=modal-edit-document
div class=modal-header
button type=button class=close data-dismiss=modalx/button
h3Editar pregunta:/h3
/div
form action={{=URL('save_contest_template' , 
args=[selected_contest_id])}} type=POST 
div class=modal-body
{{for q in questions:}}
dl
dtOrden (lugar dentro del formulario):/dtddinput 
placeholder={{=q['t_order']}} name=t_order-{{=q['id']}} type=text 
class=input-large//dd
dtPregunta:/dt
ddinput id=template_name 
placeholder={{=q['name']}} name=question-{{=q['id']}} type=text 
class=input-large //dd
dtAyuda:/dt
ddtextarea rows=3 name=help-{{=q['id']}} 
placeholder={{=q['help']}} /textarea/dd
dtObligatorio:input type=checkbox value='on' 
name=required-{{=q['id']}} {{if q['is_required']:}} checked{{pass}} 
//dt
dtMas de un autor:input type=checkbox 
name=authors-{{=q['id']}} {{if q['many_authors']:}} checked{{pass}} 
//dt
dtMostrar en resumen a usuario:input type=checkbox 
name=user_summary-{{=q['id']}}  {{if q['user_summary']:}} 
checked{{pass}}//dt
dtMostrar en resumen a administrador:input 
type=checkbox name=admin_summary-{{=q['id']}}  {{if 
q['admin_summary']:}} checked{{pass}}//dt
/dl  
{{pass}}
/div
div class=modal-footer
button  class=btn btn-success type=submit Guardar 
cambios/button
a href=# class=btn btn-danger 
data-dismiss=modalCerrar/a
/div
/form
/div

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.