def test_cached_template_not_corrupted_by_placeholder_scan(self): """ This is the test for the low-level code that caused the bug: the placeholder scan corrupts the nodelist of the extends node, which is retained by the cached template loader, and future renders of that template will render the super block twice. """ nodelist = _get_nodelist(get_template("placeholder_tests/test_super_extends_2.html")) self.assertNotIn('one', nodelist[0].blocks.keys(), "test_super_extends_1.html contains a block called 'one', " "but _2.html does not.") _get_placeholder_slots("placeholder_tests/test_super_extends_2.html") nodelist = _get_nodelist(get_template("placeholder_tests/test_super_extends_2.html")) self.assertNotIn('one', nodelist[0].blocks.keys(), "test_super_extends_1.html still should not contain a block " "called 'one' after rescanning placeholders.")
def test_cached_template_not_corrupted_by_placeholder_scan(self): """ This is the test for the low-level code that caused the bug: the placeholder scan corrupts the nodelist of the extends node, which is retained by the cached template loader, and future renders of that template will render the super block twice. """ nodelist = _get_nodelist(get_template("placeholder_tests/test_super_extends_2.html")) self.assertNotIn('one', nodelist[0].blocks.keys(), "test_super_extends_1.html contains a block called 'one', " "but _2.html does not.") get_placeholders("placeholder_tests/test_super_extends_2.html") nodelist = _get_nodelist(get_template("placeholder_tests/test_super_extends_2.html")) self.assertNotIn('one', nodelist[0].blocks.keys(), "test_super_extends_1.html still should not contain a block " "called 'one' after rescanning placeholders.")
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
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