-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblueprints.py
31 lines (23 loc) · 965 Bytes
/
blueprints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Blueprint creation module. Allows specifying the name and the URL prefix.
To register a blueprint, add it to the `all_blueprints` tuple.
"""
from flask import Blueprint
from innopoints.core.helpers import csrf_protect, require_json
def _factory(partial_module_string, url_prefix='/'):
"""Generates blueprint objects for view modules.
Positional arguments:
partial_module_string -- string representing a view module without
the absolute path (e.g. 'home.index' for pypi_portal.views.home.index).
url_prefix -- URL prefix passed to the blueprint.
Returns:
Blueprint instance for a view module.
"""
name = partial_module_string
import_name = 'innopoints.views'
blueprint = Blueprint(name, import_name, url_prefix=url_prefix)
return blueprint
api = _factory('api', url_prefix='/api/v1')
api.before_request(csrf_protect)
api.before_request(require_json)
auth = _factory('auth')
all_blueprints = (api, auth)