How to use the fair.utility.ContextClass function in fair

To help you get started, we’ve selected a few fair examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github remyzane / fair-api / fair / ui / doc.py View on Github external
def doc_ui():
    views = app.api.url_map[request.url_rule.rule[:-5]]
    apis = []
    for view_func in views:
        meta = view_func.meta       # type: Meta
        response_doc = rst_to_html(meta.response_cls.__doc__)
        apis.append(ContextClass(title=text_to_html(meta.title), description=text_to_html(meta.description),
                                 methods=meta.http_methods, meta=meta, response_doc=response_doc))
    return render_template('doc.html', apis=apis)    # url 为 flask 模板内置变量
github remyzane / fair-api / fair / ui / exe.py View on Github external
def exe_ui():
    c = ContextClass()
    c.method = request.args.get('method', None)
    views = app.api.url_map[request.url_rule.rule[:-5]]
    c.meta = None                       # type: Meta
    for view_func in views:
        if not c.method:
            c.meta = view_func.meta
            method = 'GET' if 'GET' in c.meta.http_methods else random.choice(c.meta.http_methods)
            return redirect(request.url_rule.rule + '?method=' + method)
        if c.method in view_func.meta.http_methods:
            c.meta = view_func.meta
            break
    if not c.meta:
        return 'Http method [%s] not support' % c.method

    context = {'api_config': {}, 'api_json_p': None}
github remyzane / fair-api / fair / utility.py View on Github external
def __data__(self):
        data = self.__dict__
        for key, value in data.items():
            if isinstance(value, ContextClass):
                data[key] = value.__data__
        return data
github remyzane / fair-api / fair / ui / __init__.py View on Github external
def get_view_context(views):

    context = ContextClass()


    if len(views) == 1:
        view_func = tuple(views)[0]
        http_methods = views[view_func]
    else:
        method = request.args.get('method', None)
        if method:
            method = method.upper()
            for view_func, http_methods in views.items():
                if method in http_methods:
                    pass