I combine two (crud.create with keepvalues=True) forms on one page
and below the forms a SQLTABLE (not using jqgrid because I don't know
how to pass a query to jqgrid) with an 'edit' link in the first
column. I want to get back to the same screen after one of the
entries in the SQLTABLE has been edited with the updated information
for that record the only change on that page.
And I don't know how to do it. Is it possible?
My model:
db.define_table('clm01',
Field("service_provider",db.service_provider,
requires=IS_IN_DB(db,db.service_provider.id,
'%(name)s'),label="Service provider"),
Field('trainer'),
Field('date','date'),
Field('focus'),
Field('length'),
Field("planned", 'integer'),
Field('actual', 'integer'),
Field('difference', 'integer'),
signature)
db.define_table('clm01_data',
Field('form_id', db.clm01, writable = False, readable= False),
Field('teacher', db.teacher,
requires = IS_IN_DB(db,'teacher.id',
'%(surname)s, %(name)s')),
Field("school",db.school,label="School",
requires=IS_IN_DB(db,db.school.id, '%(name)s')),
Field('position'),
Field('day_1', 'boolean'),
Field('day_2', 'boolean'),
signature)
db.clm01_data.id.represent = lambda id:
A('edit',_href=URL(r=request,c='default',f='edit_clm01_data',args=str(id)))
And controller:
@auth.requires_login()
def clm01_create():
form=SQLFORM.factory(db.clm01, db.clm01_data)
if form.accepts(request.vars, keepvalues = True):
if db((db.clm01.service_provider ==
request.vars.service_provider) &
(db.clm01.focus == request.vars.focus) &
(db.clm01.date == request.vars.date)).count() == 0:
id = db.clm01.insert(**db.clm01._filter_fields(form.vars))
form.vars.form_id=id
else:
form.vars.form_id = db((db.clm01.service_provider
== request.vars.service_provider) &
(db.clm01.focus ==
request.vars.focus) &
(db.clm01.date ==
request.vars.date)).select(db.clm01.id)[0]['id']
if form.vars.form_id:
if db((db.clm01_data.form_id == form.vars.form_id) &
(db.clm01_data.teacher == form.vars.teacher) &
(db.clm01_data.school ==
form.vars.school)).count() == 0:
id =
db.clm01_data.insert(**db.clm01_data._filter_fields(form.vars))
data = SQLTABLE(db((db.clm01_data.form_id == form.vars.form_id) &
(db.teacher.id == db.clm01_data.teacher) &
(db.school.id ==
db.clm01_data.school)).select( db.clm01_data.id,
db.clm01_data.form_id,
db.teacher.surname,
db.teacher.name,
db.school.name,
db.clm01_data.position,
db.clm01_data.day_1,
db.clm01_data.day_2),
headers = {'clm01.id' : 'ID',
'clm01_data.form_id' : 'Form ID',
'teacher.surname' : 'Teacher surname',
'teacher.name' : 'Teacher name',
'school.name' : 'School',
'clm01_data.position' : 'Position',
'clm01_data.day_1' : 'Day 1',
'clm01_data.day_2' : 'Day 2'})
return dict(form=form,data = data)
def edit_clm01_data():
for fld in db.clm01_data.fields():
if (fld == 'day_2') :
db.clm01_data[fld].writable = True
else:
db.clm01_data[fld].writable = False
db.clm01_data.teacher.represent = lambda id:
db.teacher(id).surname + ' ' + db.teacher(id).name
form = crud.update(db.clm01_data,request.raw_args, next =
URL(r=request, f='clm01_create',vars=request.vars),
deletable = False)
return dict(form=form,data = data)
Regards
Johann
--
May grace and peace be yours in abundance through the full knowledge
of God and of Jesus our Lord! His divine power has given us
everything we need for life and godliness through the full knowledge
of the one who called us by his own glory and excellence.
2 Pet. 1:2b,3a