Exemplo n.º 1
0
def admin_options_edit(req, section, option):
    check_login(req)
    check_right(req, module_right)

    if section == 'morias' and option == 'debug':
        req.status = state.HTTP_BAD_REQUEST
        req.content_type = 'application/json'
        return json.dumps({'reason': 'denied_option'})

    value = req.form.getfirst('value', None, nuni)
    if value is None:
        req.status = state.HTTP_BAD_REQUEST
        req.content_type = 'application/json'
        return json.dumps({'reason': 'value_is_none'})

    item = Option(section, option)
    item.value = value
    error = item.set(req)
    if error != item:
        req.status = state.HTTP_BAD_REQUEST
        req.content_type = 'application/json'
        return json.dumps({'reason': option_errors[error]})

    req.content_type = 'application/json'
    return json.dumps({'value': value})
Exemplo n.º 2
0
def admin_options(req):
    check_login(req)
    check_right(req, module_right)

    section = req.args.getfirst('section', '', uni)
    module = req.args.getfirst('module', '', uni)
    kwargs = {}
    if section != 'all':
        kwargs['section'] = section
    if module != 'all':
        kwargs['module'] = module

    pager = Pager()
    pager.bind(req.args)
    options = Option.list(req, pager, **kwargs)
    for option in options:
        option.defaults_json = json.dumps(list(option.defaults))

    return generate_page(req, "admin/options.html", pager=pager,
                         options=options, sections=Option.sections_list(req),
                         modules=Option.modules_list(req), section=section,
                         module=module)