コード例 #1
0
 def test_placeholder_name_toolbar(self):
     placeholder_conf_name = 'test_placeholder'
     placeholder_conf_tag = '<div class="cms_placeholder-title">%s</div>' % placeholder_conf_name
     with SettingsOverride(
             CMS_PLACEHOLDER_CONF={'test': {
                 'name': placeholder_conf_name
             }}):
         placeholder = Placeholder()
         placeholder.slot = 'test'
         placeholder.pk = placeholder.id = 99
         context = SekizaiContext()
         context['request'] = AttributeObject(
             REQUEST={'language': 'en'},
             GET=[],
             session={},
             path='/',
             user=self.test_user,
             current_page=None,
             method='GET',
         )
         classes = [
             "cms_placeholder-bar-%s" % placeholder.pk,
             "cms_placeholder_slot::test",
         ]
         output = render_placeholder_toolbar(placeholder, context, '',
                                             'test')
         self.assertTrue(
             placeholder_conf_tag in output,
             'placeholder name %r is not in %r' %
             (placeholder_conf_name, output))
コード例 #2
0
 def test_placeholder_name_toolbar(self):
     placeholder_conf_name = 'test_placeholder'
     placeholder_conf_tag = '<div class="cms_placeholder-title">%s</div>' % placeholder_conf_name
     with SettingsOverride(CMS_PLACEHOLDER_CONF = {
                               'test': {'name':placeholder_conf_name}
                           }):
         placeholder = Placeholder()
         placeholder.slot = 'test'
         placeholder.pk = placeholder.id = 99
         context = SekizaiContext()
         context['request'] = AttributeObject(
             REQUEST={'language': 'en'},
             GET=[],
             session={},
             path='/',
             user=self.test_user,
             current_page=None,
             method='GET',
             )
         classes = [
             "cms_placeholder-bar-%s" % placeholder.pk,
             "cms_placeholder_slot::test",
             ]
         output = render_placeholder_toolbar(placeholder, context, '', 'test')
         self.assertTrue(placeholder_conf_tag in output, 'placeholder name %r is not in %r' % (placeholder_conf_name, output))
コード例 #3
0
ファイル: cms_tags.py プロジェクト: kkubasik/django-cms-2.0
    def render(self, context):
        if not 'request' in context:
            return ''
        request = context['request']
        width_var = getattr(self, 'width_var', None)
        if width_var:
            try:
                width = int(width_var.resolve(context))
                context.update({'width': width})
            except (template.VariableDoesNotExist, ValueError):
                pass

        page = request.current_page
        if not page or page == "dummy":
            return ""
        
        try:
            placeholder = page.placeholders.get(slot=self.name)
        except Placeholder.DoesNotExist:
            from cms.utils.plugins import get_placeholders
            placeholders = get_placeholders(selected_template)
            found = None
            for slot in placeholders:
                new, created = page.placeholders.get_or_create(slot=slot)
                if slot == self.name:
                    found = new
            placeholder = found
        content = self.get_content(request, page, context)
        if not content:
            if self.nodelist_or:
                content = self.nodelist_or.render(context)
            if self.edit_mode(placeholder, context):
                return render_placeholder_toolbar(placeholder, context, content)
            return content
        return content
コード例 #4
0
ファイル: cms_tags.py プロジェクト: minichate/django-cms-2.0
    def render(self, context):
        if not 'request' in context:
            return ''
        request = context['request']
        width_var = getattr(self, 'width_var', None)
        if width_var:
            try:
                width = int(width_var.resolve(context))
                context.update({'width': width})
            except (template.VariableDoesNotExist, ValueError):
                pass

        page = request.current_page
        if not page or page == "dummy":
            return ""

        placeholder = page.placeholders.get(slot=self.name)
        content = self.get_content(request, page, context)
        if not content:
            if self.nodelist_or:
                content = self.nodelist_or.render(context)
            if self.edit_mode(placeholder, context):
                return render_placeholder_toolbar(placeholder, context, content)
            return content
        return content
コード例 #5
0
ファイル: rendering.py プロジェクト: rfeldbinder/django-cms
 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = "test"
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context["request"] = AttributeObject(
         REQUEST={"language": "en"},
         GET=[],
         session={},
         path="/",
         user=self.test_user,
         current_page=None,
         method="GET",
     )
     classes = ["cms_placeholder-bar-%s" % placeholder.pk, "cms_placeholder_slot::test"]
     output = render_placeholder_toolbar(placeholder, context, "", "test")
     for cls in classes:
         self.assertTrue(cls in output, "%r is not in %r" % (cls, output))
コード例 #6
0
ファイル: cms_tags.py プロジェクト: Torkn/django-cms-2.0
    def render(self, context):
        if not "request" in context:
            return ""
        request = context["request"]
        width_var = getattr(self, "width_var", None)
        if width_var:
            try:
                width = int(width_var.resolve(context))
                context.update({"width": width})
            except (template.VariableDoesNotExist, ValueError):
                pass

        page = request.current_page
        if not page or page == "dummy":
            return ""

        try:
            placeholder = page.placeholders.get(slot=self.name)
        except Placeholder.DoesNotExist:
            from cms.utils.plugins import get_placeholders

            placeholders = get_placeholders(page.get_template())
            found = None
            for slot in placeholders:
                new, created = page.placeholders.get_or_create(slot=slot)
                if slot == self.name:
                    found = new
            placeholder = found
            if not found:
                if settings.DEBUG:
                    raise Placeholder.DoesNotExist("No placeholder '%s' found for page '%s'" % (self.name, page.pk))
                else:
                    return "<!-- ERROR:cms.utils.plugins.get_placeholders:%s -->" % self.name
        content = self.get_content(request, page, context)
        if not content:
            if self.nodelist_or:
                content = self.nodelist_or.render(context)
            if self.edit_mode(placeholder, context):
                return render_placeholder_toolbar(placeholder, context, content)
            return content
        return content
コード例 #7
0
 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = 'test'
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context['request'] = AttributeObject(
         REQUEST={'language': 'en'},
         GET=[],
         session={},
         path='/',
         user=self.test_user,
         current_page=None,
         method='GET',
     )
     classes = [
         "cms_placeholder-bar-%s" % placeholder.pk,
         "cms_placeholder_slot::test",
     ]
     output = render_placeholder_toolbar(placeholder, context, '', 'test')
     for cls in classes:
         self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
コード例 #8
0
 def test_render_placeholder_toolbar(self):
     placeholder = Placeholder()
     placeholder.slot = 'test'
     placeholder.pk = placeholder.id = 99
     context = SekizaiContext()
     context['request'] = AttributeObject(
         REQUEST={'language': 'en'},
         GET=[],
         session={},
         path='/',
         user=self.test_user,
         current_page=None,
         method='GET',
     )
     classes = [
         "cms_placeholder-%s" % placeholder.pk,
         'cms_placeholder',
     ]
     output = render_placeholder_toolbar(placeholder, context, 'test', 'en')
     for cls in classes:
         self.assertTrue(cls in output, '%r is not in %r' % (cls, output))
コード例 #9
0
    def test_render_placeholder_toolbar(self):
        placeholder = Placeholder()
        placeholder.slot = 'test'
        placeholder.pk = placeholder.id = 99
        request = AttributeObject(
            GET={'language': 'en'},
            session={},
            path='/',
            user=self.test_user,
            current_page=None,
            method='GET',
        )
        request.toolbar = CMSToolbar(request)

        context = SekizaiContext()
        context['request'] = request

        classes = [
            "cms-placeholder-%s" % placeholder.pk,
            'cms-placeholder',
        ]
        output = render_placeholder_toolbar(placeholder, context, 'test', 'en')
        for cls in classes:
            self.assertTrue(cls in output, '%r is not in %r' % (cls, output))