def __init__(self, request): super(CMSToolbar, self).__init__() self.right_items = [] self.left_items = [] self.populated = False self.post_template_populated = False self.menus = {} self.request = request self.login_form = CMSToolbarLoginForm(request=request) self.is_staff = self.request.user.is_staff self.edit_mode = self.is_staff and self.request.session.get("cms_edit", False) self.edit_mode_url_on = get_cms_setting("CMS_TOOLBAR_URL__EDIT_ON") self.edit_mode_url_off = get_cms_setting("CMS_TOOLBAR_URL__EDIT_OFF") self.build_mode = self.is_staff and self.request.session.get("cms_build", False) self.use_draft = self.is_staff and self.edit_mode or self.build_mode self.show_toolbar = self.is_staff or self.request.session.get("cms_edit", False) self.obj = None self.redirect_url = None if settings.USE_I18N: self.language = get_language_from_request(request) else: self.language = settings.LANGUAGE_CODE # We need to store the current language in case the user's preferred language is different. self.toolbar_language = self.language if self.is_staff: try: user_settings = UserSettings.objects.select_related("clipboard").get(user=self.request.user) except UserSettings.DoesNotExist: user_settings = UserSettings(language=self.language, user=self.request.user) placeholder = Placeholder(slot="clipboard") placeholder.save() user_settings.clipboard = placeholder user_settings.save() if (settings.USE_I18N and user_settings.language in dict(settings.LANGUAGES)) or ( not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE ): self.toolbar_language = user_settings.language else: user_settings.language = self.language user_settings.save() self.clipboard = user_settings.clipboard with force_language(self.language): try: self.app_name = resolve(self.request.path).app_name except Resolver404: self.app_name = "" toolbars = toolbar_pool.get_toolbars() self.toolbars = SortedDict() app_key = "" for key in toolbars: app_name = ".".join(key.split(".")[:-2]) if app_name == self.app_name and len(key) > len(app_key): app_key = key for key in toolbars: toolbar = toolbars[key](self.request, self, key == app_key, app_key) self.toolbars[key] = toolbar
def __init__(self, request): super(CMSToolbar, self).__init__() self.right_items = [] self.left_items = [] self.populated = False self.post_template_populated = False self.menus = {} self.request = request self.login_form = CMSToolbarLoginForm(request=request) self.is_staff = self.request.user.is_staff self.edit_mode = self.is_staff and self.request.session.get('cms_edit', False) self.edit_mode_url_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON') self.edit_mode_url_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF') self.build_mode = self.is_staff and self.request.session.get('cms_build', False) self.use_draft = self.is_staff and self.edit_mode or self.build_mode self.show_toolbar = self.is_staff or self.request.session.get('cms_edit', False) self.obj = None self.redirect_url = None if settings.USE_I18N: self.language = get_language_from_request(request) else: self.language = settings.LANGUAGE_CODE # We need to store the current language in case the user's preferred language is different. self.toolbar_language = self.language if self.is_staff: try: user_settings = UserSettings.objects.select_related('clipboard').get(user=self.request.user) except UserSettings.DoesNotExist: user_settings = UserSettings(language=self.language, user=self.request.user) placeholder = Placeholder(slot="clipboard") placeholder.save() user_settings.clipboard = placeholder user_settings.save() if (settings.USE_I18N and user_settings.language in dict(settings.LANGUAGES)) or ( not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE): self.toolbar_language = user_settings.language else: user_settings.language = self.language user_settings.save() self.clipboard = user_settings.clipboard with force_language(self.language): try: self.app_name = resolve(self.request.path).app_name except Resolver404: self.app_name = "" toolbars = toolbar_pool.get_toolbars() self.toolbars = SortedDict() app_key = '' for key in toolbars: app_name = ".".join(key.split(".")[:-2]) if app_name == self.app_name and len(key) > len(app_key): app_key = key for key in toolbars: toolbar = toolbars[key](self.request, self, key == app_key, app_key) self.toolbars[key] = toolbar
def __init__(self, request): super(CMSToolbar, self).__init__() self.right_items = [] self.left_items = [] self.populated = False self.post_template_populated = False self.menus = {} self.request = request self.login_form = CMSToolbarLoginForm(request=request) self.is_staff = self.request.user.is_staff self.edit_mode = self.is_staff and self.request.session.get('cms_edit', False) self.edit_mode_url_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON') self.edit_mode_url_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF') self.build_mode = self.is_staff and self.request.session.get('cms_build', False) self.use_draft = self.is_staff and self.edit_mode or self.build_mode self.show_toolbar = self.is_staff or self.request.session.get('cms_edit', False) self.obj = None self.redirect_url = None if settings.USE_I18N: self.language = get_language_from_request(request) else: self.language = settings.LANGUAGE_CODE # We need to store the current language in case the user's preferred language is different. self.toolbar_language = self.language if self.is_staff: try: user_settings = UserSettings.objects.select_related('clipboard').get(user=self.request.user) except UserSettings.DoesNotExist: user_settings = UserSettings(language=self.language, user=self.request.user) placeholder = Placeholder(slot="clipboard") placeholder.save() user_settings.clipboard = placeholder user_settings.save() if (settings.USE_I18N and user_settings.language in dict(settings.LANGUAGES)) or ( not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE): self.toolbar_language = user_settings.language else: user_settings.language = self.language user_settings.save() self.clipboard = user_settings.clipboard with force_language(self.language): try: decorator = resolve(self.request.path_info).func try: # If the original view is decorated we try to extract the real function # module instead of the decorator's one if decorator and getattr(decorator, 'func_closure', False): # python 2 self.app_name = decorator.func_closure[0].cell_contents.__module__ elif decorator and getattr(decorator, '__closure__', False): # python 3 self.app_name = decorator.__closure__[0].cell_contents.__module__ else: raise AttributeError() except (TypeError, AttributeError): # no decorator self.app_name = decorator.__module__ except Resolver404: self.app_name = "" toolbars = toolbar_pool.get_toolbars() parts = self.app_name.split('.') while parts: path = '.'.join(parts) if path in installed_apps(): self.app_name = path break parts.pop() self.toolbars = SortedDict() for key in toolbars: toolbar = toolbars[key](self.request, self, toolbars[key].check_current_app(key, self.app_name), self.app_name) self.toolbars[key] = toolbar
def __init__(self, request): super(CMSToolbar, self).__init__() self.right_items = [] self.left_items = [] self.populated = False self.post_template_populated = False self.menus = {} self.request = request self.login_form = CMSToolbarLoginForm(request=request) self.is_staff = self.request.user.is_staff self.edit_mode = self.is_staff and self.request.session.get( 'cms_edit', False) self.edit_mode_url_on = get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON') self.edit_mode_url_off = get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF') self.build_mode = self.is_staff and self.request.session.get( 'cms_build', False) self.use_draft = self.is_staff and self.edit_mode or self.build_mode self.show_toolbar = self.is_staff or self.request.session.get( 'cms_edit', False) self.obj = None self.redirect_url = None if settings.USE_I18N: self.language = get_language_from_request(request) else: self.language = settings.LANGUAGE_CODE # We need to store the current language in case the user's preferred language is different. self.toolbar_language = self.language if self.is_staff: try: user_settings = UserSettings.objects.select_related( 'clipboard').get(user=self.request.user) except UserSettings.DoesNotExist: user_settings = UserSettings(language=self.language, user=self.request.user) placeholder = Placeholder(slot="clipboard") placeholder.save() user_settings.clipboard = placeholder user_settings.save() if (settings.USE_I18N and user_settings.language in dict( settings.LANGUAGES)) or (not settings.USE_I18N and user_settings.language == settings.LANGUAGE_CODE): self.toolbar_language = user_settings.language else: user_settings.language = self.language user_settings.save() self.clipboard = user_settings.clipboard with force_language(self.language): try: decorator = resolve(self.request.path_info).func try: # If the original view is decorated we try to extract the real function # module instead of the decorator's one if decorator and getattr(decorator, 'func_closure', False): # python 2 self.app_name = decorator.func_closure[ 0].cell_contents.__module__ elif decorator and getattr(decorator, '__closure__', False): # python 3 self.app_name = decorator.__closure__[ 0].cell_contents.__module__ else: raise AttributeError() except (TypeError, AttributeError): # no decorator self.app_name = decorator.__module__ except Resolver404: self.app_name = "" toolbars = toolbar_pool.get_toolbars() parts = self.app_name.split('.') while parts: path = '.'.join(parts) if path in installed_apps(): self.app_name = path break parts.pop() self.toolbars = SortedDict() for key in toolbars: toolbar = toolbars[key](self.request, self, toolbars[key].check_current_app( key, self.app_name), self.app_name) self.toolbars[key] = toolbar