forked from django-cms/django-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolbar_base.py
40 lines (32 loc) · 1.23 KB
/
toolbar_base.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
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
from django.forms import MediaDefiningClass
from six import with_metaclass
from cms.exceptions import LanguageError
from cms.utils import get_current_site, get_language_from_request
from cms.utils.i18n import get_language_object
class CMSToolbar(with_metaclass(MediaDefiningClass)):
supported_apps = None
def __init__(self, request, toolbar, is_current_app, app_path):
self.request = request
self.toolbar = toolbar
self.is_current_app = is_current_app
self.app_path = app_path
self.current_site = get_current_site()
try:
self.current_lang = get_language_object(get_language_from_request(self.request), self.current_site.pk)['code']
except LanguageError:
self.current_lang = None
def populate(self):
pass
def post_template_populate(self):
pass
@classmethod
def check_current_app(cls, key, app_name):
if cls.supported_apps is None:
local_apps = ".".join(key.split(".")[:-2]),
else:
local_apps = cls.supported_apps
for local_app in local_apps:
if app_name and local_app and app_name.startswith(local_app):
return True
return False