When submit is clicked the data is not inserted. I think the problem is when I validate form and the form.accepts is not triggered.
grid_workers = SQLFORM.grid(query=query,
left=db.status.on(db.workers.w_status == db.status.id),
fields=fields, searchable=False, orderby=[db.workers.w_nick_name], create=True,
deletable=False, editable=True, paginate=100, buttons_placement='right',
showbuttontext=False,
links=links,
ui=dict(widget='',
header='',
content='',
default='',
cornerall='',
cornertop='',
cornerbottom='',
button='button btn btn-default',
buttontext='buttontext button',
buttonadd='icon plus icon-plus glyphicon glyphicon-plus',
buttonback='icon leftarrow icon-arrow-left glyphicon glyphicon-arrow-left',
buttonexport='icon downarrow icon-download glyphicon glyphicon-download',
buttondelete='icon trash icon-trash glyphicon glyphicon-trash',
buttonedit='icon pen icon-pencil glyphicon glyphicon-pencil',
buttontable='icon rightarrow icon-arrow-right glyphicon glyphicon-arrow-right',
buttonview='icon magnifier icon-zoom-in glyphicon glyphicon-eye-open',
),
exportclasses=dict(csv=False, csv_with_hidden_cols=False,
html=False, tsv_with_hidden_cols=False,json=False, tsv= False, xml = False))
def my_form_processing_new(form):
print "tukej111"
nick_name = form.vars.w_nick_name
workers = db((db.workers.w_organization == org) & (db.workers.w_nick_name == nick_name) & (db.workers.w_status != 250)).select()
partner_id = form.vars.partner_id
if workers:
form.errors.w_nick_name = T('Worker with this nick name already exists!')
if not partner_id or partner_id == '':
form.vars.partner_id = -1
def my_form_processing_edit(form):
#some code not relevant ATM
if (request.args) and (request.args[0] in ['new']):
print "juhu"
form = grid_workers.create_form
#grid_workers.element('[title=Back]').parent['_href'] = URL('settings', 'workers')
if form.accepts(request.vars, session, onvalidation=my_form_processing_new):
print "tukej"
session.flash = T('Worker inserted')
redirect(URL())
return dict(form = form, inactive_workers=query_inactive)
if (request.args) and (request.args[0] in ['edit']):
form = grid_workers.update_form
#grid_workers.element('[title=Back]').parent['_href'] = URL('settings', 'workers')
if form.accepts(request.vars, session, onvalidation = my_form_processing_edit):
my_form_processing_edit(form)
session.flash = T('Worker updated')
redirect(URL())
return dict(form = form, inactive_workers=query_inactive)
return dict(grid_workers = grid_workers, inactive_workers=query_inactive)
and my view
<div class="col-md-12 " >
{{if ('new' in request.args) or ('edit' in request.args):}}
{{=form.custom.begin}}
Status: <div>{{=form.custom.widget.w_status}}</div>
First name: <div>{{=form.custom.widget.w_first_name}}</div>
Last name: <div>{{=form.custom.widget.w_last_name}}</div>
Nick name: <div>{{=form.custom.widget.w_nick_name}}</div>
E-mail: <div>{{=form.custom.widget.w_email}}</div>
Work type: <div>{{=form.custom.widget.w_work_type}}</div>
Month hour formula: <div>{{=form.custom.widget.w_hour_formula}}</div>
Work obligation (minutes): <div>{{=form.custom.widget.w_day_obligation}}</div>
Partner ID : <div>{{=form.custom.widget.partner_id}}</div>
Comment: <div>{{=form.custom.widget.w_note}}</div>
<div>{{=form.custom.submit}}</div>
{{=form.custom.end}}
{{else:}}
{{=grid_workers}}
{{pass}}
</div>
So theĀ
if form.accepts(request.vars, session, onvalidation=my_form_processing_new) does not happen and I believe therefore the data is not inserted.