1
|
|
|
""" |
2
|
|
|
byceps.blueprints.admin.core.views |
3
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
4
|
|
|
|
5
|
|
|
:Copyright: 2006-2021 Jochen Kupperschmidt |
6
|
|
|
:License: Revised BSD (see `LICENSE` file for details) |
7
|
|
|
""" |
8
|
|
|
|
9
|
1 |
|
from flask import g |
10
|
|
|
|
11
|
1 |
|
from .... import config |
12
|
1 |
|
from ....services.brand import service as brand_service |
13
|
1 |
|
from ....util.authorization import register_permission_enum |
14
|
1 |
|
from ....util.framework.blueprint import create_blueprint |
15
|
1 |
|
from ....util.user_session import ( |
16
|
|
|
get_current_user, |
17
|
|
|
get_locale as get_session_locale, |
18
|
|
|
) |
19
|
|
|
|
20
|
1 |
|
from .authorization import AdminPermission |
21
|
|
|
|
22
|
|
|
|
23
|
1 |
|
blueprint = create_blueprint('core_admin', __name__) |
24
|
|
|
|
25
|
|
|
|
26
|
1 |
|
register_permission_enum(AdminPermission) |
27
|
|
|
|
28
|
|
|
|
29
|
1 |
|
@blueprint.app_context_processor |
30
|
|
|
def inject_template_variables(): |
31
|
1 |
|
def get_brand_for_site(site): |
32
|
1 |
|
return brand_service.find_brand(site.brand_id) |
33
|
|
|
|
34
|
1 |
|
def get_brand_for_party(party): |
35
|
1 |
|
return brand_service.find_brand(party.brand_id) |
36
|
|
|
|
37
|
1 |
|
return { |
38
|
|
|
'get_brand_for_site': get_brand_for_site, |
39
|
|
|
'get_brand_for_party': get_brand_for_party, |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
1 |
|
@blueprint.before_app_request |
44
|
|
|
def prepare_request_globals(): |
45
|
1 |
|
app_mode = config.get_app_mode() |
46
|
1 |
|
g.app_mode = app_mode |
47
|
|
|
|
48
|
1 |
|
locale = get_session_locale() |
49
|
|
|
|
50
|
1 |
|
required_permissions = {AdminPermission.access} |
51
|
|
|
g.user = get_current_user(required_permissions, locale) |
52
|
|
|
|