Here it is:

@auth.requires_login()
# @auth.requires_signature()
def index():
    # type: () -> Dict[str, gluon.DIV]
    """Index page.

    :return: Dict with grid.
    """
    if not request.vars.sid:
        redirect(URL('default', 'index'))

    if session.sids[request.vars.sid].return_to:
        del session.sids[request.vars.sid].return_to

    session.sids[request.vars.sid].table = 'opt_cat'

    # Hidden fields in grid and edit/view form.
    db.opt_cat.id.readable = False

    db.opt_cat.one_opt_only.show_if = db.opt_cat.mandatory == False

    if SUPERVISOR_ROLE_ID in auth.user_groups:
        # Uses covering index opt_cat_is_active_name_en.
        # Uses auto index sqlite_autoindex_opt_cat_1.
        grid = SQLFORM.grid(
            db.opt_cat,
            csv=False,
            details=False,
            # Disable delete checkbox in edit form.
            editargs=dict(deletable=False),
            maxtextlength=GRID_COL_LEN_FOR_TEXT,
            ondelete=on_delete,  # Grid only.
            onvalidation=on_validation,  # And onupdate are form only.
            orderby=db.opt_cat.name,
            paginate=session.auth.user.pagination,
            # represent_none='',  # Grid and view form only.
            user_signature=False,
        )  # type: gluon.DIV
    else:
        # Hidden fields in grid and edit/view form.
        db.opt_cat.canceled_on.readable = False
        db.opt_cat.canceled_by.readable = False
        db.opt_cat.cancel_approved_by.readable = False

        # Uses covering index opt_cat_is_active_name_en (is_active=?).
        # Uses index opt_cat_is_active_name (is_active=?).
        grid = SQLFORM.grid(
            db.opt_cat.is_active == True,
            create=False,
            csv=False,
            deletable=False,
            details=False,
            editable=False,
            maxtextlength=GRID_COL_LEN_FOR_TEXT,
            orderby=db.opt_cat.name,
            paginate=session.auth.user.pagination,
            # represent_none='',  # Grid and view form only.
            user_signature=False,
        )

    # Remove icons from default buttons.
    grid.elements('span.icon', replace=None)

    if request.args:
        # Remove delete button.
        grid.element('#delete_with_approval', replace=None)

    if not request.args:
        # Sort grid's search fields list.
        grid.element('#w2p_query_fields').components = 
sort_grid_search_fields_list(grid)

        if session.sids[request.vars.sid].modified_on:
            del session.sids[request.vars.sid].modified_on
    elif 'edit' in request.args:
        # Edit uses opt_cat Pk.

        form = grid.update_form  # type: gluon.sqlhtml.SQLFORM
        # form['hidden'].update(mon=form.record.modified_on)
        # Solves the record changed while editing, but doesn't solve it
        # if the user 1st tries something that returns form.errors (eg.
        # changing a unique field to something that already exists) and
        # only after that he tries to save the record (which was changed
        # by another user). For this the only solution I've found was
        # using a session var.

        if not session.sids[request.vars.sid].modified_on:
            session.sids[request.vars.sid].modified_on = form.record.
modified_on

        if not form.record.is_active and not SUPERVISOR_ROLE_ID in auth.
user_groups:
            session.flash = T('Record was deleted while you were viewing 
the grid.')
            redirect(URL(vars={'sid': request.vars.sid}))

    return dict(grid=grid)


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to