当前位置: 首页>>代码示例>>Python>>正文


Python models.Page方法代码示例

本文整理汇总了Python中wagtail.core.models.Page方法的典型用法代码示例。如果您正苦于以下问题:Python models.Page方法的具体用法?Python models.Page怎么用?Python models.Page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wagtail.core.models的用法示例。


在下文中一共展示了models.Page方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: requests_admin

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def requests_admin(request, pk):
    """Table display of each request for a given product.

    Allows the given Page pk to refer to a direct parent of
    the ProductVariant model or be the ProductVariant model itself.
    This allows for the standard longclaw product modelling philosophy where
    ProductVariant refers to the actual product (in the case where there is
    only 1 variant) or to be variants of the product page.
    """
    page = Page.objects.get(pk=pk).specific
    if hasattr(page, 'variants'):
        requests = ProductRequest.objects.filter(
            variant__in=page.variants.all()
        )
    else:
        requests = ProductRequest.objects.filter(variant=page)
    return render(
        request,
        "productrequests/requests_admin.html",
        {'page': page, 'requests': requests}
    ) 
开发者ID:JamesRamm,项目名称:longclaw,代码行数:23,代码来源:views.py

示例2: validate_supplied_values

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def validate_supplied_values(tag, max_levels=None, parent_page=None,
                             menuitem_or_page=None):
    if max_levels is not None:
        if max_levels not in (1, 2, 3, 4, 5):
            raise ValueError(
                "The `%s` tag expects `max_levels` to be an integer value "
                "between 1 and 5. Please review your template." % tag
            )
    if parent_page is not None:
        if not isinstance(parent_page, Page):
            raise ValueError(
                "The `%s` tag expects `parent_page` to be a `Page` instance. "
                "A value of type `%s` was supplied." %
                (tag, parent_page.__class__)
            )
    if menuitem_or_page is not None:
        if not isinstance(menuitem_or_page, (Page, MenuItem)):
            raise ValueError(
                "The `%s` tag expects `menuitem_or_page` to be a `Page` or "
                "`MenuItem` instance. A value of type `%s` was supplied." %
                (tag, menuitem_or_page.__class__)
            ) 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:24,代码来源:misc.py

示例3: segment_user

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def segment_user(page, request, serve_args, serve_kwargs):
    """Apply a segment to a visitor before serving the page.

    :param page: The page being served
    :type page: wagtail.core.models.Page
    :param request: The http request
    :type request: django.http.HttpRequest

    """
    adapter = get_segment_adapter(request)
    adapter.refresh()

    forced_segment = request.GET.get('segment', None)
    if request.user.is_superuser and forced_segment is not None:
        segment = models.Segment.objects.filter(pk=forced_segment).first()
        if segment:
            adapter.set_segments([segment]) 
开发者ID:wagtail,项目名称:wagtail-personalisation,代码行数:19,代码来源:wagtail_hooks.py

示例4: test_index

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_index(self):
        url = self.blog_index.url
        res = self.client.get(url)
        self.assertEqual(res.status_code, 200)

        blog_page = self.blog_index.add_child(
            instance=BlogPage(
                title="Blog Page",
                slug="blog_page1",
                search_description="x",
                owner=self.user,
            )
        )
        url = blog_page.url
        res = self.client.get(url)
        self.assertContains(res, "Blog Page") 
开发者ID:thelabnyc,项目名称:wagtail_blog,代码行数:18,代码来源:tests.py

示例5: test_latest_entries_feed

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_latest_entries_feed(self):
        self.blog_index.add_child(
            instance=BlogPage(
                title="Blog Page",
                slug="blog_page1",
                search_description="x",
                owner=self.user,
            )
        )
        res = self.client.get(
            "{0}{1}/rss/".format(self.blog_index.url, self.blog_index.slug)
        )
        self.assertContains(res, "Blog Page")
        self.assertContains(res, "<rss")
        self.assertContains(res, 'version="2.0"')
        self.assertContains(res, "</rss>") 
开发者ID:thelabnyc,项目名称:wagtail_blog,代码行数:18,代码来源:tests.py

示例6: test_latest_entries_feed_atom

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_latest_entries_feed_atom(self):
        self.blog_index.add_child(
            instance=BlogPage(
                title="Blog Page",
                slug="blog_page1",
                search_description="x",
                owner=self.user,
            )
        )
        res = self.client.get(
            "{0}{1}/atom/".format(self.blog_index.url, self.blog_index.slug)
        )
        self.assertContains(res, "Blog Page")
        self.assertContains(res, "<feed")
        self.assertContains(res, 'xmlns="http://' 'www.w3.org/2005/Atom"')
        self.assertContains(res, "</feed>") 
开发者ID:thelabnyc,项目名称:wagtail_blog,代码行数:18,代码来源:tests.py

示例7: setUp

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def setUp(self):
        home_page = Page.objects.get(slug='home')

        blog_index_page = BlogIndexPage(
            title='Blog',
            slug='blog',
            show_in_menus=True
        )
        home_page.add_child(instance=blog_index_page)

        blog_posts = [
            BlogPost(title='First Blog Post',
                     slug='first-blog-post',
                     date=datetime.date.today(),
                     byline='Author'),
            BlogPost(title='Second Blog Post',
                     slug='second-blog-post',
                     date=datetime.date.today(),
                     byline='Author')
        ]

        for blog_post in blog_posts:
            blog_index_page.add_child(instance=blog_post) 
开发者ID:freedomofpress,项目名称:securethenews,代码行数:25,代码来源:tests.py

示例8: render_js_init

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def render_js_init(self, id_, name, value):
        if isinstance(value, Page):
            page = value
        else:
            # Value is an ID look up object
            model_class = self._get_lowest_common_page_class()
            page = self.get_instance(model_class, value)

        parent = page.get_parent() if page else None

        return "createPageChooser({id}, {model_names}, {parent}, {can_choose_root}, {user_perms});".format(
            id=json.dumps(id_),
            model_names=json.dumps([
                '{app}.{model}'.format(
                    app=model._meta.app_label,
                    model=model._meta.model_name)
                for model in self.target_models
            ]),
            parent=json.dumps(parent.id if parent else None),
            can_choose_root=('true' if self.can_choose_root else 'false'),
            user_perms=json.dumps(self.user_perms),
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:24,代码来源:widgets.py

示例9: test_before_move_page_hook_post

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_before_move_page_hook_post(self):
        def hook_func(request, page, destination):
            self.assertIsInstance(request, HttpRequest)
            self.assertIsInstance(page.specific, SimplePage)
            self.assertIsInstance(destination.specific, SimplePage)

            return HttpResponse("Overridden!")

        with self.register_hook('before_move_page', hook_func):
            response = self.client.post(reverse('wagtailadmin_pages:move_confirm', args=(self.test_page_a.id, self.section_b.id)))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b"Overridden!")

        # page should not be moved
        self.assertEqual(
            Page.objects.get(id=self.test_page_a.id).get_parent().id,
            self.section_a.id
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:21,代码来源:test_move_page.py

示例10: test_after_move_page_hook

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_after_move_page_hook(self):
        def hook_func(request, page):
            self.assertIsInstance(request, HttpRequest)
            self.assertIsInstance(page.specific, SimplePage)

            return HttpResponse("Overridden!")

        with self.register_hook('after_move_page', hook_func):
            response = self.client.post(reverse('wagtailadmin_pages:move_confirm', args=(self.test_page_a.id, self.section_b.id)))

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b"Overridden!")

        # page should be moved
        self.assertEqual(
            Page.objects.get(id=self.test_page_a.id).get_parent().id,
            self.section_b.id
        ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:test_move_page.py

示例11: test_page_edit_post

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_page_edit_post(self):
        # Tests simple editing
        post_data = {
            'title': "I've been edited!",
            'content': "Some content",
            'slug': 'hello-world',
        }
        response = self.client.post(reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )), post_data)

        # Should be redirected to edit page
        self.assertRedirects(response, reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )))

        # The page should have "has_unpublished_changes" flag set
        child_page_new = SimplePage.objects.get(id=self.child_page.id)
        self.assertTrue(child_page_new.has_unpublished_changes)

        # Page fields should not be changed (because we just created a new draft)
        self.assertEqual(child_page_new.title, self.child_page.title)
        self.assertEqual(child_page_new.content, self.child_page.content)
        self.assertEqual(child_page_new.slug, self.child_page.slug)

        # The draft_title should have a new title
        self.assertEqual(child_page_new.draft_title, post_data['title']) 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:test_edit_page.py

示例12: test_before_edit_page_hook_post

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_before_edit_page_hook_post(self):
        def hook_func(request, page):
            self.assertIsInstance(request, HttpRequest)
            self.assertEqual(page.id, self.child_page.id)

            return HttpResponse("Overridden!")

        with self.register_hook('before_edit_page', hook_func):
            post_data = {
                'title': "I've been edited!",
                'content': "Some content",
                'slug': 'hello-world-new',
                'action-publish': "Publish",
            }
            response = self.client.post(
                reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )), post_data
            )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b"Overridden!")

        # page should not be edited
        self.assertEqual(Page.objects.get(id=self.child_page.id).title, "Hello world!") 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:test_edit_page.py

示例13: test_after_edit_page_hook

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_after_edit_page_hook(self):
        def hook_func(request, page):
            self.assertIsInstance(request, HttpRequest)
            self.assertEqual(page.id, self.child_page.id)

            return HttpResponse("Overridden!")

        with self.register_hook('after_edit_page', hook_func):
            post_data = {
                'title': "I've been edited!",
                'content': "Some content",
                'slug': 'hello-world-new',
                'action-publish': "Publish",
            }
            response = self.client.post(
                reverse('wagtailadmin_pages:edit', args=(self.child_page.id, )), post_data
            )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, b"Overridden!")

        # page should be edited
        self.assertEqual(Page.objects.get(id=self.child_page.id).title, "I've been edited!") 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:test_edit_page.py

示例14: test_post_create_form

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_post_create_form(self):
        post_data = {
            'title': "New index!",
            'slug': 'new-index',
            'advert_placements-TOTAL_FORMS': '1',
            'advert_placements-INITIAL_FORMS': '0',
            'advert_placements-MAX_NUM_FORMS': '1000',
            'advert_placements-0-advert': '1',
            'advert_placements-0-colour': 'yellow',
            'advert_placements-0-id': '',
        }
        response = self.client.post(
            reverse('wagtailadmin_pages:add', args=('tests', 'standardindex', self.root_page.id)), post_data
        )

        # Find the page and check it
        page = Page.objects.get(path__startswith=self.root_page.path, slug='new-index').specific

        # Should be redirected to edit page
        self.assertRedirects(response, reverse('wagtailadmin_pages:edit', args=(page.id, )))

        self.assertEqual(page.advert_placements.count(), 1)
        self.assertEqual(page.advert_placements.first().advert.text, 'test_advert') 
开发者ID:wagtail,项目名称:wagtail,代码行数:25,代码来源:test_edit_page.py

示例15: test_post_edit_form

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Page [as 别名]
def test_post_edit_form(self):
        post_data = {
            'title': "My lovely index",
            'slug': 'my-lovely-index',
            'advert_placements-TOTAL_FORMS': '2',
            'advert_placements-INITIAL_FORMS': '1',
            'advert_placements-MAX_NUM_FORMS': '1000',
            'advert_placements-0-advert': '1',
            'advert_placements-0-colour': 'yellow',
            'advert_placements-0-id': self.index_page.advert_placements.first().id,
            'advert_placements-1-advert': '1',
            'advert_placements-1-colour': 'purple',
            'advert_placements-1-id': '',
            'action-publish': "Publish",
        }
        response = self.client.post(reverse('wagtailadmin_pages:edit', args=(self.index_page.id, )), post_data)

        # Should be redirected to explorer
        self.assertRedirects(response, reverse('wagtailadmin_explore', args=(self.root_page.id, )))

        # Find the page and check it
        page = Page.objects.get(id=self.index_page.id).specific
        self.assertEqual(page.advert_placements.count(), 2)
        self.assertEqual(page.advert_placements.all()[0].advert.text, 'test_advert')
        self.assertEqual(page.advert_placements.all()[1].advert.text, 'test_advert') 
开发者ID:wagtail,项目名称:wagtail,代码行数:27,代码来源:test_edit_page.py


注:本文中的wagtail.core.models.Page方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。