示例#1
0
def admin_menu_delete(req, id):
    check_login(req)
    check_right(req, module_right)
    check_token(req, req.args.get("token"))

    item = MenuItem(id)
    if item.delete(req):
        return js_items(req)

    req.status = state.HTTP_BAD_REQUEST
    req.content_type = "application/json"
    return json.dumps({"reason": "integrity_error"})
示例#2
0
def js_items(req):
    pager = Pager(limit=-1)
    items = []
    for item in MenuItem.list(req, pager):
        items.append(item.__dict__)
    req.content_type = "application/json"
    return json.dumps({"items": items})
示例#3
0
def admin_menu_to(req, id):
    check_login(req)
    check_right(req, module_right)
    check_token(req, req.form.get("token"))

    item = MenuItem(id)

    if req.uri.endswith("to_child"):
        status = item.to_child(req)
    else:
        status = item.to_parent(req)
    if status:
        return js_items(req)

    req.status = state.HTTP_BAD_REQUEST
    req.content_type = "application/json"
    return json.dumps({"reason": "not_possible"})
示例#4
0
def admin_menu_add_update(req, id=None):
    check_login(req)
    check_right(req, module_right)
    check_token(req, req.form.get("token"))

    item = MenuItem(id)
    item.bind(req.form)
    if not item.title:
        req.status = state.HTTP_BAD_REQUEST
        req.content_type = "application/json"
        return json.dumps({"reason": "empty_title"})

    status = item.mod(req) if id else item.add(req)
    if status:
        return js_items(req)

    req.status = state.HTTP_BAD_REQUEST
    req.content_type = "application/json"
    return json.dumps({"reason": "title_exist"})
示例#5
0
def admin_menu(req):
    check_login(req)
    check_right(req, module_right)

    pager = Pager(limit=-1)
    items = MenuItem.list(req, pager)

    return generate_page(
        req, "admin/page_menu.html", token=do_create_token(req, "/admin/menu"), pager=pager, items=items
    )
示例#6
0
def refresh_menu(req, cfg_timestamp):
    """ refresh menu from db if timestamp is change """
    global timestamp
    global static_menu

    check = check_timestamp(req, cfg_timestamp)
    if check > timestamp:  # if last load was in past to timestamp file
        req.log_error("file timestamp is older, loading menu from DB...", state.LOG_INFO)
        static_menu = MenuItem.get_menu(req)
        timestamp = check