web2py SQLFORM.grid网址

时间:2014-07-09 08:17:50

标签: grid web2py

当我尝试在我的控制器中放置form = SQLFORM.grid(db.mytable)时,请求更改为我的/ web / site / view?_signature = 520af19b1095db04dda2f1b6cbea3a03c3551e13这会导致我在控制器中的if语句崩溃。 smbd请解释为什么会发生这种情况?

如果我把user_signature = False然后在视图加载上显示网格(虽然看起来很糟糕,我仍然需要找出如何更改我的表格的视图),但是在搜索,编辑等上点击,同样的事情再次发生。网址已更改,我收到错误

有什么建议吗?

谢谢

修改

这是我的编辑功能

@auth.requires_login()
def edit():
    #Load workers
     workers = db(db.worker.w_organisation == 10).select(db.worker.w_id_w, db.worker.w_organisation, db.worker.w_first_name, db.worker.w_last_name,db.worker.w_nick_name,db.worker.w_email,db.worker.w_status,db.worker.w_note).as_list()


#Define the query object. Here we are pulling all contacts having date of birth less than 18 Nov 1990
query = ((db.worker.w_organisation == 10) & (db.worker.w_status==db.status.s_id_s))

#Define the fields to show on grid. Note: (you need to specify id field in fields section in 1.99.2
fields = (db.worker.w_first_name, db.worker.w_last_name,db.worker.w_nick_name,db.worker.w_email,db.status.s_code,db.worker.w_note)

#Define headers as tuples/dictionaries
headers = { 'worker.w_first_name' :   'Ime',
       'worker.w_last_name' : 'Priimek',
       'worker.w_nick_name' : 'Vzdevek',
       'worker.w_email' : 'E-posta',
       'status.s_code': 'Status',
       'worker.w_note' : 'Komentar' }

#Let's specify a default sort order on date_of_birth column in grid
default_sort_order=[db.worker.w_last_name]

#Creating the grid object
form = SQLFORM.grid(query=query, fields=fields, headers=headers,searchable=True, orderby=default_sort_order,create=True, \
                deletable=True, editable=True, maxtextlength=64, paginate=25,user_signature=False
                )

form = SQLFORM.grid(db.worker,user_signature=False)


workersDb = db((db.worker.w_organisation == 10) & (db.worker.w_status==db.status.s_id_s)).select(db.worker.w_id_w, \
                                                db.worker.w_organisation, db.worker.w_first_name, \
                                                db.worker.w_last_name,db.worker.w_nick_name,db.worker.w_email,\
                                                db.status.s_code,db.worker.w_note).as_list()

workersList = []


for rec in workersDb:
    status =  rec['status']['s_code']
    workers = rec['worker']

    if not rec["worker"]["w_first_name"]:
        polno_ime = rec["worker"]["w_last_name"]
    elif not rec["worker"]["w_last_name"]:
        polno_ime = rec["worker"]["w_first_name"]
    else:
        polno_ime = rec["worker"]["w_first_name"] + " " + rec["worker"]["w_last_name"] 
    rec["worker"]['w_full_name'] = polno_ime
    rec["worker"]["w_status"] = status
    data = rec["worker"]
    #print rec
    #print data
    workersList.append(rec["worker"])

# If type of arg is int, we know that user wants to edit a script with an id of the argument
if(request.args[0].isdigit()):
    script = db(getDbScript(request.args[0])).select(db.script.sc_lls, db.script.sc_name, db.script.id, db.script.sc_menu_data).first()
    formData = str(script["sc_menu_data"])
    #form = SQLFORM.grid(db.auth_user)
    #print formData
    # If we dont get any results that means that user is not giving proper request and we show him error
    #print script
    #Parsing script to be inserted into view

    if not script:      
        return error(0)
    return dict(newScript = False, script = script, formData = formData, workers = workersList, form = form)
# If the argument is new we prepare page for new script
elif request.args[0] == 'new':
    scripts = db((auth.user.organization == db.script.sc_organization)).select(db.script.sc_name, db.script.id, workers = workersList, form = form)

    return dict(newScript = True, scripts = scripts, workers = workersList, form = form)
# Else error
else:
    return error(0)

更不用说sqlgrid看起来很糟糕了,这里是链接到图片https://plus.google.com/103827646559093653557/posts/Bci4PCG4BQQ

0 个答案:

没有答案