예제 #1
0
    def test_placeholder_scanning_var(self):
        t = Template('{%load cms_tags %}{% include name %}{% placeholder "a_placeholder" %}')
        phs = sorted(node.get_declaration().slot for node in _scan_placeholders(t.nodelist))
        self.assertListEqual(phs, sorted([u'a_placeholder']))

        t = Template('{% include "placeholder_tests/outside_nested_sekizai.html" %}')
        phs = sorted(node.get_declaration().slot for node in _scan_placeholders(t.nodelist))
        self.assertListEqual(phs, sorted([u'two', u'new_one', u'base_outside']))
예제 #2
0
    def test_placeholder_scanning_var(self):
        t = Template('{%load cms_tags %}{% include name %}{% placeholder "a_placeholder" %}')
        phs = _scan_placeholders(t.nodelist)
        self.assertListEqual(sorted(phs), sorted([u'a_placeholder']))

        t = Template('{% include "placeholder_tests/outside_nested_sekizai.html" %}')
        phs = _scan_placeholders(t.nodelist)
        self.assertListEqual(sorted(phs), sorted([u'two', u'new_one', u'base_outside']))
예제 #3
0
def get_placeholders(template):
    from ..templatetags.cms_articles import ArticlePlaceholder

    compiled_template = get_template(template)

    placeholders = []
    nodes = _scan_placeholders(_get_nodelist(compiled_template), ArticlePlaceholder)
    clean_placeholders = []

    for node in nodes:
        placeholder = node.get_declaration()
        slot = placeholder.slot

        if slot in clean_placeholders:
            warnings.warn("Duplicate {{% placeholder \"{0}\" %}} "
                          "in template {1}."
                          .format(slot, template, slot),
                          DuplicatePlaceholderWarning)
        else:
            validate_placeholder_name(slot)
            placeholders.append(placeholder)
            clean_placeholders.append(slot)
    return placeholders
예제 #4
0
def get_placeholders(template):
    from ..templatetags.cms_articles import ArticlePlaceholder

    compiled_template = get_template(template)

    placeholders = []
    nodes = _scan_placeholders(_get_nodelist(compiled_template),
                               ArticlePlaceholder)
    clean_placeholders = []

    for node in nodes:
        placeholder = node.get_declaration()
        slot = placeholder.slot

        if slot in clean_placeholders:
            warnings.warn(
                "Duplicate {{% placeholder \"{0}\" %}} "
                "in template {1}.".format(slot, template, slot),
                DuplicatePlaceholderWarning)
        else:
            validate_placeholder_name(slot)
            placeholders.append(placeholder)
            clean_placeholders.append(slot)
    return placeholders