如何将OnDelete功能重定向到页面以索取密码,然后返回sqlform.grid页面



有人知道如何重定向到页面以索取密码,然后返回sqlform.grid页面?

在下面的代码中(对于非经理和非Supervisor),您可以看到我已经配置了OnDelete来调用on_delete函数。这有效。

on_delete函数还执行重定向get_approval,并且get_approval代码运行,但它返回到网格页面而不显示get_approval form页面。

如果我对删除并注销链接并删除所有内容。存在视图get_approval.html。

@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
                        and ('/client' in request.env.http_referer
                             or '/client/get_approval' in request.env.http_referer)))
def get_approval():
    """."""
    rec_id = request.args[0]
    rows_dic = {**general.get_members(db, SUPERVISOR_ROLE),
                **general.get_members(db, MANAGER_ROLE)}
    form = SQLFORM.factory(
        Field('user_id', label=T('Supervisor/Manager'),
              requires=IS_IN_SET(rows_dic, zero=T('Choose one...'))),
        Field('password', 'password', label=T('Password'), requires=IS_NOT_EMPTY()),
              buttons=[BUTTON(T('Submit'), _type='submit', _class='btn btn-primary')],
              formstyle='table3cols',
    )
    if form.process(keepvalues=True).accepted:
        # If passwords match it is approved.
        if (db.auth_user.password.validate(form.vars.password)[0]
                == db.auth_user(form.vars.user_id).password):
            row = db.client[rec_id]
            row.update_record(cancel_approved_by=form.vars.user_id,
                              canceled_by=session.auth.user.id, canceled_on=request.now,
                              is_active=False)
            redirect(URL('index', user_signature=True))
        else:
            response.flash = T('Wrong password')
    return dict(form=form)

@auth.requires_login()
def index():
    """."""
    # DON'T uncomment without testing.
    # session.forget(response)  # Recommended in Efficiency tricks.
    # Hidden fields in grid/view form.
    db.client.id.readable = False
    db.client.canceled_on.readable = False
    db.client.canceled_by.readable = False
    db.client.cancel_approved_by.readable = False
    # Hidden fields in create/edit form.
    db.client.canceled_on.writable = False
    db.client.canceled_by.writable = False
    db.client.cancel_approved_by.writable = False
    # ondelete is used in the grid and on_validation/on_update are used
    # in the edit form.
    if auth.has_membership(SUPERVISOR_ROLE) or auth.has_membership(MANAGER_ROLE):
        grid = SQLFORM.grid(db.client, csv=False, details=False,
                            # noconfirm=True,  # Grid only.
                            ondelete=on_delete,  # Grid only.
                            onvalidation=on_validation,  # Form only.
                            represent_none='',  # Grid/view form only.
        )
    else:
        grid = SQLFORM.grid(
            db.client, create=False, csv=False, # deletable=False,
            details=False,
            editable=False,
            # links=[lambda row: A(
                # SPAN(_class='icon trash icon-trash glyphicon glyphicon-trash') + ' '
                # + SPAN(T('Delete'), _class='buttontext button', _title='Delete'),
                # _href=URL('get_approval', args=[row.id], user_signature=True),
                # _class='button btn btn-default btn-secondary')],
            ondelete=on_delete,  # Grid only.
            represent_none='',  # Grid/view form only.
        )
    return dict(grid=grid)

@auth.requires(lambda: (auth.requires_login() and request.env.http_referer
                        and '/client' in request.env.http_referer))
def on_delete(table, rec_id):
    """Used in the grid."""
    if auth.has_membership(SUPERVISOR_ROLE) or auth.has_membership(MANAGER_ROLE):
        row = table[rec_id]
        row.update_record(cancel_approved_by=session.auth.user.id,
                          canceled_by=session.auth.user.id, canceled_on=request.now,
                          is_active=False)
        redirect(URL(user_signature=True))
    else:
        redirect(URL('get_approval', args=[rec_id], user_signature=True))

预先感谢

JM

必须将重定向命令与client_side = true一起使用。

相关内容

最新更新