コード例 #1
0
ファイル: toolbar.py プロジェクト: conrado/django-cms
 def populate(self):
     """
     Get the CMS items on the toolbar
     """
     if self.right_items is not None and self.left_items is not None:
         return
     self.right_items = []
     self.left_items = []
     # never populate the toolbar on is_staff=False
     if not self.is_staff:
         return
     with force_language(self.language):
         try:
             self.view_name = resolve(self.request.path).func.__module__
         except Resolver404:
             self.view_name = ""
     with force_language(self.toolbar_language):
         toolbars = toolbar_pool.get_toolbars()
         app_key = ""
         for key in toolbars:
             app_name = ".".join(key.split(".")[:-2])
             if app_name in self.view_name and len(key) > len(app_key):
                 app_key = key
             # if the cms_toolbar is in use, ensure it's first
         first = ('cms.cms_toolbar.BasicToolbar', 'cms.cms_toolbar.PlaceholderToolbar')
         for key in first:
             toolbar = toolbars[key](self.request, self, key == app_key, app_key)
             toolbar.populate()
         for key in toolbars:
             if key in first:
                 continue
             toolbar = toolbars[key](self.request, self, key == app_key, app_key)
             toolbar.populate()
コード例 #2
0
ファイル: toolbar.py プロジェクト: skirsdeda/django-cms
    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.obj = None
        self.redirect_url = None
        self.request = None
        self.is_staff = None
        self.edit_mode = None
        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.disable_url = get_cms_setting("CMS_TOOLBAR_URL__DISABLE")
        self.build_mode = None
        self.use_draft = None
        self.show_toolbar = None
        self.login_form = None
        self.clipboard = None
        self.language = None
        self.toolbar_language = None
        self.simple_structure_mode = get_cms_setting("TOOLBAR_SIMPLE_STRUCTURE_MODE")
        self.show_toolbar = True
        self.init_toolbar(request)

        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 = OrderedDict()
        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
コード例 #3
0
ファイル: toolbar.py プロジェクト: BertrandBordage/django-cms
    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
コード例 #4
0
ファイル: toolbar.py プロジェクト: wherka/django-cms
    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
コード例 #5
0
ファイル: toolbar.py プロジェクト: bestkatrina/Project
    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.obj = None
        self.redirect_url = None
        self.request = None
        self.is_staff = None
        self.edit_mode = None
        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.disable_url = get_cms_setting('CMS_TOOLBAR_URL__DISABLE')
        self.build_mode = None
        self.use_draft = None
        self.show_toolbar = None
        self.login_form = None
        self.clipboard = None
        self.language = None
        self.toolbar_language = None
        self.simple_structure_mode = get_cms_setting('TOOLBAR_SIMPLE_STRUCTURE_MODE')
        self.show_toolbar = True
        self.init_toolbar(request)

        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 = OrderedDict()
        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
コード例 #6
0
ファイル: toolbar.py プロジェクト: rspeed/contrib-django-cms
    def __init__(self, request, request_path=None):
        super(CMSToolbar, self).__init__()
        self.right_items = []
        self.left_items = []
        self.last_left_items = []
        self.last_right_items = []
        self.populated = False
        self.post_template_populated = False
        self.menus = {}
        self.obj = None
        self.redirect_url = None
        self.request = None
        self.is_staff = None
        self.show_toolbar = None
        self.clipboard = None
        self.language = None
        self.toolbar_language = None
        self.show_toolbar = True
        self.init_toolbar(request, request_path=request_path)
        # Internal attribute to track whether we can cache
        # a response from the current request.
        # This attribute is modified by the placeholder rendering
        # mechanism in case a placeholder rendered by the current
        # request cannot be cached.
        self._cache_disabled = self.edit_mode_active or self.show_toolbar

        with force_language(self.language):
            try:
                decorator = resolve(self.request_path).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, AttributeError):
                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 = OrderedDict()

        for key in toolbars:
            is_current_app = toolbars[key].check_current_app(
                key, self.app_name)
            toolbar = toolbars[key](
                request=self.request,
                toolbar=self,
                is_current_app=is_current_app,
                app_path=self.app_name,
            )
            self.toolbars[key] = toolbar
コード例 #7
0
 def test_toolbar_is_registered(self):
     """ Test that the toolbar is loading. """
     toolbars_items = toolbar_pool.get_toolbars()
     toolbars = [v for k, v in toolbars_items.items()]
     self.assertTrue(ThingsToolbar in toolbars)
コード例 #8
0
ファイル: toolbar.py プロジェクト: MackJay/django-cms
    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
コード例 #9
0
    def __init__(self, request):
        super(CMSToolbar, self).__init__()
        self.right_items = []
        self.left_items = []
        self.last_left_items = []
        self.last_right_items = []
        self.populated = False
        self.post_template_populated = False
        self.menus = {}
        self.obj = None
        self.redirect_url = None
        self.request = None
        self.is_staff = None
        self.edit_mode = None
        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.disable_url = get_cms_setting('CMS_TOOLBAR_URL__DISABLE')
        self.build_mode = None
        self.use_draft = None
        self.show_toolbar = None
        self.login_form = None
        self.clipboard = None
        self.language = None
        self.toolbar_language = None
        self.show_toolbar = True
        self.init_toolbar(request)
        # Internal attribute to track whether we can cache
        # a response from the current request.
        # This attribute is modified by the placeholder rendering
        # mechanism in case a placeholder rendered by the current
        # request cannot be cached.
        self._cache_disabled = self.edit_mode

        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, AttributeError):
                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 = OrderedDict()
        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
コード例 #10
0
    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