當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。