Пример #1
0
    def get_or_create_root(self):
        """
        Creates the root node used to store all page types
        for the current site if it doesn't exist.
        """
        root_page = PageType.get_root_page(site=self._site)

        if not root_page:
            root_page = Page(
                publisher_is_draft=True,
                in_navigation=False,
                is_page_type=True,
            )
            root_page.set_tree_node(self._site)
            root_page.save()

        if not root_page.has_translation(self._language):
            api.create_title(
                language=self._language,
                title=ugettext('Page Types'),
                page=root_page,
                slug=PAGE_TYPES_ID,
                path=PAGE_TYPES_ID,
            )
        return root_page.node
Пример #2
0
    def test_wizard_create_child_page_under_page_type(self):
        """
        When a user creates a child page through the wizard,
        if the parent page is a page-type, the child page should
        also be a page-type.
        """
        site = get_current_site()
        superuser = self.get_superuser()
        source_page = create_page(
            title="Source",
            template=TEMPLATE_INHERITANCE_MAGIC,
            language="en",
        )

        with self.login_user_context(superuser):
            self.client.post(
                self.get_admin_url(PageType, 'add'),
                data={
                    'source': source_page.pk,
                    'title': 'type1',
                    'slug': 'type1',
                    '_save': 1
                },
            )

        types_root = PageType.get_root_page(site)
        parent_page = types_root.get_child_pages()[0]
        data = {
            'title': 'page-type-child',
            'slug': 'page-type-child',
            'page_type': None,
        }
        form = CreateCMSSubPageForm(
            data=data,
            wizard_page=parent_page,
            wizard_user=superuser,
            wizard_language='en',
        )
        self.assertTrue(form.is_valid())

        child_page = form.save()

        self.assertTrue(child_page.is_page_type)
        self.assertFalse(child_page.in_navigation)
        self.assertEqual(child_page.node.depth, 3)
        self.assertEqual(child_page.parent_page, parent_page)
        self.assertEqual(child_page.get_title('en'), 'page-type-child')
        self.assertEqual(child_page.get_path('en'),
                         'page_types/type1/page-type-child')
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(AddPageForm, self).__init__(*args, **kwargs)

        source_field = self.fields.get('source')

        if not source_field or source_field.widget.is_hidden:
            return

        root_page = PageType.get_root_page(site=self._site)

        if root_page:
            # Set the choicefield's choices to the various page_types
            descendants = root_page.get_descendant_pages().filter(is_page_type=True)
            titles = Title.objects.filter(page__in=descendants, language=self._language)
            choices = [('', '---------')]
            choices.extend((title.page_id, title.title) for title in titles)
            source_field.choices = choices
        else:
            choices = []

        if len(choices) < 2:
            source_field.widget = forms.HiddenInput()