示例#1
0
def admin_item_actions(req, item_id):
    check_login(req)
    check_right(req, module_right)
    check_token(req, req.args.get('token'),
                uri='/admin/eshop/store/%s' % item_id)

    action_type = req.args.getfirst('type', '', uni)
    if action_type == 'inc':
        kwargs = {'action_type': ACTION_INC}
    elif action_type == 'dec':
        kwargs = {'action_type': ACTION_DEC}
    elif action_type == 'pri':
        kwargs = {'action_type': ACTION_PRI}
    else:
        kwargs = {}
    kwargs['item_id'] = item_id

    pager = Pager(sort='desc')
    pager.bind(req.args)

    actions = list(a.__dict__ for a in Action.list(req, pager, **kwargs))
    req.content_type = 'application/json'
    return json.dumps({'actions': actions, 'pager': pager.__dict__})
示例#2
0
def admin_item_incdec(req, id):
    check_login(req, '/log_in?referer=/admin/eshop/store/%s' % id)
    check_right(req, module_right)
    check_token(req, req.form.get('token'), uri='/admin/eshop/store/%s' % id)

    if req.uri.endswith('/inc'):
        action_type = ACTION_INC
    elif req.uri.endswith('/dec'):
        action_type = ACTION_DEC
    elif req.uri.endswith('/pri'):
        action_type = ACTION_PRI
    else:
        raise RuntimeError('Unknow action')

    action = Action.bind(req.form, action_type)

    item = Item(id)
    if not item.action(req, action) or not item.get(req):
        req.status = state.HTTP_NOT_FOUND
        req.content_type = 'application/json'
        return json.dumps({'reason': 'item not found'})

    req.content_type = 'application/json'
    return json.dumps({'item': item.__dict__})