Completed
Pull Request — master (#244)
by Jace
07:52 queued 06:28
created

_samples()   A

Complexity

Conditions 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 9.6666
1 1
import random
2
3 1
from flask import Blueprint, Response, render_template, current_app
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 ._settings import GITHUB_SLUG
6 1
from ._utils import get_tid, route
7
8
9 1
blueprint = Blueprint('index', __name__, url_prefix="/")
10
11
12 1
@blueprint.route("")
13
def get_index():
14 1
    template_images = list(_samples(blank=True))
15 1
    sample_images = list(_samples())
16 1
    return Response(render_template(
17
        "index.html",
18
        template_images=template_images,
19
        default_template=random.choice(template_images)['key'],
20
        sample_images=sample_images,
21
        github_slug=GITHUB_SLUG,
22
        ga_tid=get_tid(),
23
    ))
24
25
26 1
def _samples(blank=False):
27
    """Generate dictionaries of sample image data for template rendering."""
28 1
    for template in sorted(current_app.template_service.all()):
29 1
        path = "_" if blank else template.sample_path
30 1
        url = route('image.get', key=template.key, path=path)
31 1
        yield {
32
            'key': template.key,
33
            'name': template.name,
34
            'url': url,
35
        }
36