|
1
|
1 |
|
from collections import OrderedDict |
|
2
|
|
|
|
|
3
|
1 |
|
from flask import Blueprint, current_app as app, request, redirect |
|
|
|
|
|
|
4
|
1 |
|
from flask_api import exceptions |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
1 |
|
from ._common import CONTRIBUTING, url_for |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
1 |
|
blueprint = Blueprint('templates', __name__, url_prefix="/templates/") |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
1 |
|
@blueprint.route("") |
|
13
|
|
|
def get(): |
|
14
|
|
|
"""Get a list of all meme templates.""" |
|
15
|
1 |
|
data = OrderedDict() |
|
16
|
1 |
|
for template in sorted(app.template_service.all()): |
|
17
|
1 |
|
url = url_for('.create', key=template.key, _external=True) |
|
18
|
1 |
|
data[template.name] = url |
|
19
|
1 |
|
return data |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
1 |
|
@blueprint.route("", methods=['POST']) |
|
23
|
|
|
def create_template(): |
|
24
|
1 |
|
raise exceptions.PermissionDenied(CONTRIBUTING) |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
1 |
|
@blueprint.route("<key>", methods=['GET', 'POST'], endpoint='create') |
|
28
|
|
|
def create_meme(key): |
|
29
|
|
|
"""Generate a meme from a template.""" |
|
30
|
1 |
|
if request.method == 'GET': |
|
31
|
1 |
|
template = app.template_service.find(key) |
|
32
|
1 |
|
if template.key != key: |
|
33
|
1 |
|
return redirect(url_for('.create', key=template.key)) |
|
34
|
|
|
|
|
35
|
1 |
|
data = OrderedDict() |
|
36
|
1 |
|
data['name'] = template.name |
|
37
|
1 |
|
data['description'] = template.link |
|
38
|
1 |
|
data['aliases'] = sorted(template.aliases + [template.key]) |
|
39
|
1 |
|
data['styles'] = template.styles |
|
40
|
1 |
|
data['example'] = url_for('links.get', key=key, |
|
41
|
|
|
path=template.sample_path, _external=True) |
|
42
|
1 |
|
return data |
|
43
|
|
|
|
|
44
|
|
|
elif request.method == 'POST': |
|
45
|
|
|
# TODO: https://github.com/jacebrowning/memegen/issues/12 |
|
46
|
|
|
raise exceptions.PermissionDenied("Feature not implemented.") |
|
47
|
|
|
|
|
48
|
|
|
else: # pragma: no cover |
|
49
|
|
|
assert None |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
1 |
|
@blueprint.route("<key>/<path:path>") |
|
53
|
|
|
def get_meme_with_path(key, path): |
|
54
|
|
|
"""Redirect if any additional path is provided.""" |
|
55
|
1 |
|
template = app.template_service.find(key) |
|
56
|
|
|
return redirect("/{}/{}".format(template.key, path)) |
|
57
|
|
|
|
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.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.