コード例 #1
0
ファイル: utils.py プロジェクト: zilleanai/flask-unchained
def _query_to_role(query):
    kwargs = _query_to_kwargs(query)
    role = role_manager.get_by(**kwargs)
    if not role:
        click.secho(f'ERROR: Could not locate a role by {_format_query(query)}',
                    fg='white', bg='red')
        sys.exit(1)
    return role
コード例 #2
0
ファイル: utils.py プロジェクト: zilleanai/flask-unchained
def _query_to_user(query):
    kwargs = _query_to_kwargs(query)
    user = user_manager.get_by(**kwargs)
    if not user:
        click.secho(f'ERROR: Could not locate a user by {_format_query(query)}',
                    fg='white', bg='red')
        sys.exit(1)
    return user
コード例 #3
0
def url(url: str, method: str):
    """Show details for a specific URL."""
    try:
        url_rule, params = (current_app.url_map.bind('localhost')
                            .match(url, method=method, return_rule=True))
    except (NotFound, MethodNotAllowed)\
            as e:
        click.secho(str(e), fg='white', bg='red')
    else:
        headings = ('Method(s)', 'Rule', 'Params', 'Endpoint', 'View', 'Options')
        print_table(headings,
                    [(_get_http_methods(url_rule),
                      url_rule.rule if url_rule.strict_slashes
                                    else url_rule.rule + '[/]',
                      _format_dict(params),
                      url_rule.endpoint,
                      _get_rule_view(url_rule),
                      _format_rule_options(url_rule))],
                    ['<' if i > 0 else '>' for i, col in enumerate(headings)],
                    primary_column_idx=1)