def test_cannot_be_duplicated_in_template(self):
        self.prepare_template_file("""{% load fp_container_tags %}
{% block main-content %}
{% fp_object_container first-container %}
{% fp_object_container first-container %}
{% templatetag opencomment %}
{% endblock %}
""")
        with self.assertRaises(exceptions.ImproperlyConfigured):
            get_container_names_from_template(self.template_name)
    def test_cannot_be_duplicated_in_template(self):
        self.prepare_template_file("""{% load fp_container_tags %}
{% block main-content %}
{% fp_object_container first-container %}
{% fp_object_container first-container %}
{% templatetag opencomment %}
{% endblock %}
""")
        with self.assertRaises(exceptions.ImproperlyConfigured):
            get_container_names_from_template(self.template_name)
    def save(self, update_slugs=True, *args, **kwargs):
        if update_slugs:
            parent = self.get_parent()
            slug = slugify(self.title)
            if parent:
                self.slug = '%s%s%s' % (
                    parent.slug,
                    self._slug_separator,
                    slug
                )
            else:
                self.slug = slug

        # Enforce slug uniqueness here as MySQL can't handle a unique index on
        # the slug field
        try:
            match = self.__class__.objects.get(slug=self.slug)
        except self.__class__.DoesNotExist:
            pass
        else:
            if match.id != self.id:
                raise ValidationError(
                    _("A category with slug '%(slug)s' already exists") % {
                        'slug': self.slug
                    })

        super(Page, self).save(*args, **kwargs)

        existing_containers = [c.variable_name for c in self.containers.all()]
        for cname in get_container_names_from_template(self.page_type.template):
            if cname not in existing_containers:
                self.containers.create(
                    page=self,
                    variable_name=cname,
                )
    def test_can_be_extracted_from_template(self):
        self.prepare_template_file("""{% load fp_container_tags %}
{% block main-content %}
{% fp_object_container first-container %}
{% templatetag opencomment %}
{% endblock %}
{% fp_object_container another-container %}
""")
        self.assertSequenceEqual(
            get_container_names_from_template(self.template_name),
            [u'first-container', u'another-container'])
    def test_can_be_extracted_from_template(self):
        self.prepare_template_file("""{% load fp_container_tags %}
{% block main-content %}
{% fp_object_container first-container %}
{% templatetag opencomment %}
{% endblock %}
{% fp_object_container another-container %}
""")
        self.assertSequenceEqual(
            get_container_names_from_template(self.template_name),
            [u'first-container', u'another-container'])
    def setUp(self):
        super(TestContainerWithObject, self).setUp()
        self.prepare_template_file("{% load fp_container_tags %}"
                                   "{% fp_object_container test-container %}")

        page_type = models.PageType.objects.create(
            name="Example Type", template_name=self.template_name)
        self.page = FancyPage.add_root(node__name="Some Title",
                                       page_type=page_type)
        self.container_names = get_container_names_from_template(
            self.page.page_type.template_name)
    def setUp(self):
        super(TestContainerWithObject, self).setUp()
        self.prepare_template_file(
            "{% load fp_container_tags %}"
            "{% fp_object_container test-container %}")

        page_type = models.PageType.objects.create(
            name="Example Type", template_name=self.template_name)
        self.page = FancyPage.add_root(
            node__name="Some Title", page_type=page_type)
        self.container_names = get_container_names_from_template(
            self.page.page_type.template_name)
    def test_empty_container_name_list_is_returned_when_unknown_page_type(self):
        page_type = models.PageType()
        page_type.template = models.PageTemplate.objects.create(
            title="Test Template",
            description="For testing",
            template_name="somewhere_else.html"
        )
        self.prepare_template_file("""{% load fp_container_tags %}
{% block main-content %}
{% fancypages-container first-container %}
{% templatetag opencomment %}
{% endblock %}
{% fancypages-container another-container %}
""")
        self.assertSequenceEqual(get_container_names_from_template(page_type.template), [])
    def test_can_extract_container_names_from_template(self):
        page_type = models.PageType.objects.create(
            name='Article',
            code='article',
            template=self.template
        )
        self.prepare_template_file("""{% load fp_container_tags %}
{% block main-content %}
{% fancypages-container first-container %}
{% templatetag opencomment %}
{% endblock %}
{% fancypages-container another-container %}
""")
        self.assertSequenceEqual(
            get_container_names_from_template(page_type.template),
            [u'first-container', u'another-container']
        )
    def test_can_be_assigned_to_a_page(self):
        page_type = models.PageType.objects.create(
            name='Article',
            code='article',
            template=self.template
        )

        self.prepare_template_file("{% load fp_container_tags %}"
                                   "{% fancypages-container test-container %}")

        basic_page = models.Page.add_root(
            title = "Some Title",
            page_type=page_type,
        )

        container_names = get_container_names_from_template(page_type.template)
        self.assertEquals(container_names, [u'test-container'])

        self.assertEquals(basic_page.containers.count(), 1)