Passed
Push — main ( 7fb18a...baf70b )
by Jochen
04:45
created

byceps.util.templatefunctions._format_number()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
"""
2
byceps.util.templatefunctions
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
Provide and register custom template global functions.
6
7
:Copyright: 2006-2021 Jochen Kupperschmidt
8
:License: Revised BSD (see `LICENSE` file for details)
9
"""
10
11 1
import babel
12 1
from flask_babel import get_locale, get_timezone
13
14
15 1
def register(app):
16
    """Make functions available as global functions in templates."""
17 1
    functions = [
18
        (_format_date, 'format_date'),
19
        (_format_datetime, 'format_datetime'),
20
        (_format_time, 'format_time'),
21
        (_format_number, 'format_number'),
22
    ]
23
24 1
    for f, name in functions:
25 1
        app.add_template_global(f, name)
26
27
28 1
def _format_date(*args) -> str:
29
    return babel.dates.format_date(*args, locale=get_locale())
30
31
32 1
def _format_datetime(*args) -> str:
33
    return babel.dates.format_datetime(
34
        *args, locale=get_locale(), tzinfo=get_timezone()
35
    )
36
37
38 1
def _format_time(*args) -> str:
39
    return babel.dates.format_time(
40
        *args, locale=get_locale(), tzinfo=get_timezone()
41
    )
42
43
44 1
def _format_number(*args) -> str:
45
    return babel.numbers.format_number(*args, locale=get_locale())
46