Passed
Push — main ( cb85db...4e2ecc )
by Jochen
04:12
created

byceps.blueprints.common.core.views   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 70
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0
wmc 7

5 Functions

Rating   Name   Duplication   Size   Complexity  
A not_found() 0 3 1
A forbidden() 0 3 1
A prepare_request_globals() 0 3 1
A inject_template_variables() 0 16 2
A add_page_arg() 0 11 2
1
"""
2
byceps.blueprints.common.core.views
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
:Copyright: 2006-2021 Jochen Kupperschmidt
6
:License: Revised BSD (see `LICENSE` file for details)
7
"""
8
9 1
from datetime import date, datetime
10
11 1
from flask import g, render_template
12
13 1
from .... import config
14 1
from ....util.authorization import (
15
    has_current_user_any_permission,
16
    has_current_user_permission,
17
    permission_registry,
18
)
19 1
from ....util.framework.blueprint import create_blueprint
20 1
from ....util.navigation import Navigation
21
22
23 1
blueprint = create_blueprint('core_common', __name__)
24
25
26 1
@blueprint.app_errorhandler(403)
27
def forbidden(error):
28 1
    return render_template('error/forbidden.html'), 403
29
30
31 1
@blueprint.app_errorhandler(404)
32
def not_found(error):
33 1
    return render_template('error/not_found.html'), 404
34
35
36 1
@blueprint.app_context_processor
37
def inject_template_variables():
38 1
    context = {
39
        'datetime': datetime,
40
        'now': datetime.utcnow(),
41
        'today': date.today(),
42
        'Navigation': Navigation,
43
        'has_current_user_any_permission': has_current_user_any_permission,
44
        'has_current_user_permission': has_current_user_permission,
45
    }
46
47
    # Make permission enums available in templates.
48 1
    for enum in permission_registry.get_enums():
49 1
        context[enum.__name__] = enum
50
51 1
    return context
52
53
54 1
@blueprint.app_template_global()
55
def add_page_arg(args, page):
56
    """Add the 'page' value.
57
58
    Used for pagination.
59
    """
60 1
    if args is None:
61
        args = {}
62
63 1
    args['page'] = page
64 1
    return args
65
66
67 1
@blueprint.before_app_request
68
def prepare_request_globals():
69
    g.app_mode = config.get_app_mode()
70