memegen.routes.index.get()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 12
nop 0
dl 0
loc 13
ccs 4
cts 4
cp 1
crap 1
rs 9.8
c 0
b 0
f 0
1 1
import random
2
from pathlib import Path
3 1
4
from flask import (Blueprint, Markup,
0 ignored issues
show
introduced by
Unable to import 'flask'
Loading history...
5 1
                   render_template, current_app, make_response)
6
from markdown import markdown
0 ignored issues
show
introduced by
Unable to import 'markdown'
Loading history...
7
8 1
from ._utils import samples
9
10
11 1
blueprint = Blueprint('index-page', __name__)
12
13 1
14 1
@blueprint.route("/")
15 1
def get():
16
    template_images = list(samples(blank=True))
17
    html = render_template(
18
        "index.html",
19
        template_images=template_images,
20
        default_template=random.choice(template_images)['key'],
21
        readme=_load_readme(),
22
        config=current_app.config,
23
    )
24 1
    response = make_response(html)
25
    response.headers['Cache-Control'] = f'max-age={60*60*12}'
26 1
    return response
27 1
28 1
29
def _load_readme():
30 1
    path = Path(current_app.config['ROOT'], 'README.md')
31
    with path.open() as f:
32
        text = f.read()
33
        content = text.split('<!--content-->')[-1]
34
        html = markdown(content, extensions=[
35
            'markdown.extensions.tables',
36
            'pymdownx.magiclink',
37
        ])
38
        return Markup(html)
39