Completed
Pull Request — master (#178)
by Jace
02:29 queued 01:15
created

get_with_text()   A

Complexity

Conditions 3

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3
Metric Value
cc 3
dl 0
loc 22
ccs 18
cts 18
cp 1
crap 3
rs 9.2
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
5 1
from ..domain import Text
6
7 1
from ._common import route
8
9
10 1
blueprint = Blueprint('links', __name__, url_prefix="/")
11
12
13 1
@blueprint.route("<key>")
14
def get_without_text(key):
15 1
    template = app.template_service.find(key)
16 1
    return redirect(route('templates.create', key=template.key))
17
18
19 1
@blueprint.route("<key>/<path:path>", endpoint='get')
20
def get_with_text(key, path):
21
    """Get links for generated images."""
22 1
    template = app.template_service.find(key)
23 1
    if template.key != key:
24 1
        return redirect(route('.get', key=template.key, path=path))
25
26 1
    text = Text(path)
27 1
    if text.path != path:
28 1
        return redirect(route('.get', key=key, path=text.path))
29
30 1
    data = OrderedDict()
31 1
    data['direct'] = OrderedDict()
32 1
    visible_url = route('image.get', key=key, path=path, _external=True)
33 1
    data['direct']['visible'] = visible_url
34 1
    code = app.link_service.encode(key, path)
35 1
    masked_url = route('image.get_encoded', code=code, _external=True)
36 1
    data['direct']['masked'] = masked_url
37 1
    data['markdown'] = OrderedDict()
38 1
    data['markdown']['visible'] = "![{k}]({u})".format(k=key, u=visible_url)
39 1
    data['markdown']['masked'] = "![{k}]({u})".format(k=key, u=masked_url)
40 1
    return data
41
42
43 1
@blueprint.route("_<code>")
44
def get_encoded(code):
45 1
    key, path = app.link_service.decode(code)
46
    return redirect(route('.get', key=key, path=path))
47