Completed
Push — master ( b5954e...236f10 )
by Jace
10s
created

get_with_name()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
cc 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1 1
from collections import OrderedDict
2
3 1
from flask import Blueprint, current_app as app, redirect
0 ignored issues
show
Configuration introduced by
The import flask could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
4 1
from webargs import fields, flaskparser
0 ignored issues
show
Configuration introduced by
The import webargs could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
5
6 1
from ._common import route
7
8
9 1
blueprint = Blueprint('aliases', __name__)
10
11 1
FILTER = {
12
    'name': fields.Str(missing="")  # pylint: disable=no-member
13
}
14
15
16 1
@blueprint.route("/aliases/")
17 1
@flaskparser.use_kwargs(FILTER)
18
def get(name):
19
    """Get a list of all matching aliases."""
20 1
    if name:
21 1
        return redirect(route('.get_with_name', name=name))
22
    else:
23 1
        return _get_aliases()
24
25
26 1
@blueprint.route("/aliases/<name>")
27
def get_with_name(name):
28
    """Get a list of all matching aliases."""
29 1
    return _get_aliases(name)
30
31
32 1
def _get_aliases(name=""):
33 1
    items = OrderedDict()
34
35 1
    for alias in sorted(app.template_service.aliases(name)):
36 1
        template = app.template_service.find(alias)
37
38 1
        data = OrderedDict()
39 1
        data['styles'] = sorted(template.styles)
40 1
        data['template'] = \
41
            route('templates.create', key=template.key, _external=True)
42
43 1
        items[alias] = data
44
45
    return items
46