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


Python models.Site方法代码示例

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


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

示例1: test_cannot_copy_footer_menu

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_cannot_copy_footer_menu(self):
        site_one = Site.objects.get(id=1)
        site_two = Site.objects.get(id=2)
        # Start by getting the footer menu for site one
        site_one_footer_menu = FlatMenu.get_for_site('footer', site_one)
        # Create a new menu from the above one, for site two
        site_two_footer_menu = site_one_footer_menu
        site_two_footer_menu.id = None
        site_two_footer_menu.site = site_two
        site_two_footer_menu.save()

        # Refetche menu one
        site_one_footer_menu = FlatMenu.get_for_site('footer', site_one)

        copy_view = self.app.get(
            '%scopy/%s/' % (self.base_flatmenu_admin_url, site_one_footer_menu.pk),
            user='test1')
        form = copy_view.forms[1]
        form['site'] = site_two.pk
        response = form.submit()

        assert 'The flat menu could not be saved due to errors' in response
        assert 'Flat menu with this Site and Handle already exists.' in response 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:25,代码来源:test_backend.py

示例2: setUp

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def setUp(self):
        # create test LinkPage
        self.parent_page = Site.objects.first().root_page
        self.link_page = LinkPage(
            content_type=ContentType.objects.get_for_model(LinkPage),
            title='RKH Website',
            link_url='https://www.rkh.co.uk',
            url_append='#testing'
        )
        self.parent_page.add_child(instance=self.link_page)

        # log in as superuser to avoid permission issues
        user = get_user_model().objects._create_user(
            username='test1', email='test1@email.com', password='password',
            is_superuser=True)
        self.client.force_login(user) 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:18,代码来源:test_backend.py

示例3: test_mainmenu_edit_multisite

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_mainmenu_edit_multisite(self):
        Site.objects.create(
            id=3, hostname='test3.com', port=80, root_page_id=2,
            is_default_site=0, site_name="Test site 3")

        response = self.client.get(
            '/admin/wagtailmenus/mainmenu/edit/1/')
        self.assertEqual(response.status_code, 200)

        # If the site id in the URL and the site GET value are the same,
        # we shouldn't be redirect, because we're already where we need to be
        response = self.client.get(
            '/admin/wagtailmenus/mainmenu/edit/2/', {'site': 2})
        self.assertEqual(response.status_code, 200)

        # If the site id in the URL and the site GET value are different,
        # we should be redirected to the edit page for the site in GET
        response = self.client.get(
            '/admin/wagtailmenus/mainmenu/edit/2/', {'site': 3})
        self.assertRedirects(response, '/admin/wagtailmenus/mainmenu/edit/3/') 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:22,代码来源:test_backend.py

示例4: test_flat_menu_get_for_site_with_default_fallback

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_flat_menu_get_for_site_with_default_fallback(self):
        site_one = Site.objects.get(pk=1)
        site_two = Site.objects.get(pk=2)

        # Site one (default) definitiely has a menu defined with the handle
        # `footer`
        menu = FlatMenu.get_for_site('footer', site_one)
        site_one_menu_pk = menu.pk
        self.assertIsNotNone(menu)

        # Site two doesn't have any menus defined, so this should return None
        menu = FlatMenu.get_for_site('footer', site_two)
        self.assertIsNone(menu)

        # But if we use the `use_default_site_menu_as_fallback` flag to fetch
        # from the default site, we should get the one defined for site_one
        menu = FlatMenu.get_for_site('footer', site_two, True)
        self.assertIsNotNone(menu)
        self.assertEqual(menu.pk, site_one_menu_pk) 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:21,代码来源:test_menu_rendering.py

示例5: test_redirect_gets_added_to_site

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_redirect_gets_added_to_site(self):
        invalid_file = tempfile.NamedTemporaryFile(mode="w+", encoding="utf-8")
        invalid_file.write("from,to\n")
        invalid_file.write("/alpha/,http://omega.test/")
        invalid_file.seek(0)

        current_site = Site.objects.first()
        site = Site.objects.create(
            hostname="random.test", root_page=current_site.root_page
        )

        out = StringIO()
        call_command(
            "import_redirects",
            src=invalid_file.name,
            site=site.pk,
            stdout=out,
            format="csv",
        )

        redirect = Redirect.objects.first()
        self.assertEqual(redirect.old_path, "/alpha")
        self.assertEqual(redirect.redirect_link, "http://omega.test/")
        self.assertEqual(redirect.site, site) 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_import_command.py

示例6: test_duplicate_redirects_with_query_string_when_match_is_for_generic

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_duplicate_redirects_with_query_string_when_match_is_for_generic(self):
        contact_page = Page.objects.get(url_path='/home/contact-us/')
        site = Site.objects.create(hostname='other.example.com', port=80, root_page=contact_page)

        # two redirects, one for any site, one for specific, both with query string
        models.Redirect.objects.create(old_path='/xmas?foo=Bar', redirect_link='/generic-with-query-string')
        models.Redirect.objects.create(site=site, old_path='/xmas?foo=Bar', redirect_link='/site-specific-with-query-string')

        # and two redirects, one for any site, one for specific, without query strings
        models.Redirect.objects.create(old_path='/xmas', redirect_link='/generic')
        models.Redirect.objects.create(site=site, old_path='/xmas', redirect_link='/site-specific')

        response = self.client.get('/xmas/?foo=Bar')
        # the redirect which matched was /generic-with-query-string
        self.assertRedirects(response, '/generic-with-query-string', status_code=301, fetch_redirect_response=False)

        # now use a non-matching query string
        response = self.client.get('/xmas/?foo=Baz')
        # the redirect which matched was /generic
        self.assertRedirects(response, '/generic', status_code=301, fetch_redirect_response=False) 
开发者ID:wagtail,项目名称:wagtail,代码行数:22,代码来源:test_redirects.py

示例7: test_duplicate_redirects_with_query_string_when_match_is_for_specific_with_qs

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_duplicate_redirects_with_query_string_when_match_is_for_specific_with_qs(self):
        contact_page = Page.objects.get(url_path='/home/contact-us/')
        site = Site.objects.create(hostname='other.example.com', port=80, root_page=contact_page)

        # two redirects, one for any site, one for specific, both with query string
        models.Redirect.objects.create(old_path='/xmas?foo=Bar', redirect_link='/generic-with-query-string')
        models.Redirect.objects.create(site=site, old_path='/xmas?foo=Bar', redirect_link='/site-specific-with-query-string')

        # and two redirects, one for any site, one for specific, without query strings
        models.Redirect.objects.create(old_path='/xmas', redirect_link='/generic')
        models.Redirect.objects.create(site=site, old_path='/xmas', redirect_link='/site-specific')

        response = self.client.get('/xmas/?foo=Bar', HTTP_HOST='other.example.com')
        # the redirect which matched was /site-specific-with-query-string
        self.assertRedirects(response, '/site-specific-with-query-string', status_code=301, fetch_redirect_response=False)

        # now use a non-matching query string
        response = self.client.get('/xmas/?foo=Baz', HTTP_HOST='other.example.com')
        # the redirect which matched was /site-specific
        self.assertRedirects(response, '/site-specific', status_code=301, fetch_redirect_response=False) 
开发者ID:wagtail,项目名称:wagtail,代码行数:22,代码来源:test_redirects.py

示例8: test_add_with_site

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_add_with_site(self):
        localhost = Site.objects.get(hostname='localhost')
        response = self.post({
            'old_path': '/test',
            'site': localhost.id,
            'is_permanent': 'on',
            'redirect_link': 'http://www.test.com/',
        })

        # Should redirect back to index
        self.assertRedirects(response, reverse('wagtailredirects:index'))

        # Check that the redirect was created
        redirects = models.Redirect.objects.filter(old_path='/test')
        self.assertEqual(redirects.count(), 1)
        self.assertEqual(redirects.first().redirect_link, 'http://www.test.com/')
        self.assertEqual(redirects.first().site, localhost) 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:test_redirects.py

示例9: test_can_reuse_path_on_other_site

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_can_reuse_path_on_other_site(self):
        localhost = Site.objects.get(hostname='localhost')
        contact_page = Page.objects.get(url_path='/home/contact-us/')
        other_site = Site.objects.create(hostname='other.example.com', port=80, root_page=contact_page)

        models.Redirect.objects.create(old_path='/test', site=localhost, redirect_link='http://elsewhere.com/')
        response = self.post({
            'old_path': '/test',
            'site': other_site.pk,
            'is_permanent': 'on',
            'redirect_link': 'http://www.test.com/',
        })

        # Should redirect back to index
        self.assertRedirects(response, reverse('wagtailredirects:index'))

        # Check that the redirect was created
        redirects = models.Redirect.objects.filter(redirect_link='http://www.test.com/')
        self.assertEqual(redirects.count(), 1) 
开发者ID:wagtail,项目名称:wagtail,代码行数:21,代码来源:test_redirects.py

示例10: test_edit_with_site

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_edit_with_site(self):
        localhost = Site.objects.get(hostname='localhost')

        response = self.post({
            'old_path': '/test',
            'is_permanent': 'on',
            'site': localhost.id,
            'redirect_link': 'http://www.test.com/ive-been-edited',
        })

        # Should redirect back to index
        self.assertRedirects(response, reverse('wagtailredirects:index'))

        # Check that the redirect was edited
        redirects = models.Redirect.objects.filter(old_path='/test')
        self.assertEqual(redirects.count(), 1)
        self.assertEqual(redirects.first().redirect_link, 'http://www.test.com/ive-been-edited')
        self.assertEqual(redirects.first().site, localhost) 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:test_redirects.py

示例11: setUp

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def setUp(self):
        root = Page.objects.first()
        other_home = Page(title='Other Root')
        root.add_child(instance=other_home)

        self.default_site = Site.objects.get(is_default_site=True)
        self.default_site_settings = TestSetting.objects.create(
            title='Site title',
            email='initial@example.com',
            site=self.default_site)

        self.other_site = Site.objects.create(hostname='other', root_page=other_home)
        self.other_site_settings = TestSetting.objects.create(
            title='Other title',
            email='other@other.com',
            site=self.other_site) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:base.py

示例12: _custom_slug_help_text

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def _custom_slug_help_text(model):
    """Helper to generate entity-appropriate help text without also triggering
    migration creation (which monkeypatching the models will do)"""

    if model.__class__.__name__ in EXTERNAL_ENTITY_NAMES:
        return (
            "Because you are adding External content, this slug will NOT be "
            "visible to the end user, but still needs to be unique within the CMS."
        )
    else:
        # Generate slug help_text that uses the default site’s real URL, falling
        # back to example.com instead of the Wagtail default.
        default_site = Site.objects.filter(is_default_site=True).first()
        base_url = default_site.root_url if default_site else "https://example.com"

        return (
            f"The name of the page as it will appear in URLs. For example, "
            f"for a post: {base_url}/posts/your-slug-here/"
        ) 
开发者ID:mdn,项目名称:developer-portal,代码行数:21,代码来源:forms.py

示例13: handle

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def handle(self, *args, **options):
        for site in Site.objects.all():
            menu_model = settings.models.MAIN_MENU_MODEL
            menu = menu_model.get_for_site(site)
            if not menu.get_menu_items_manager().exists():
                menu.add_menu_items_for_pages(
                    site.root_page.get_descendants(
                        inclusive=bool(options['add-home-links'])
                    ).filter(depth__lte=site.root_page.depth + 1)
                ) 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:12,代码来源:autopopulate_main_menus.py

示例14: test_copy_footer_menu

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_copy_footer_menu(self):
        # First check that there are 3 menus
        response = self.app.get(self.base_flatmenu_admin_url, user='test1')
        assert len(response.context['object_list']) == 3

        site_one = Site.objects.get(id=1)
        site_two = Site.objects.get(id=2)

        # Start by getting the footer menu for site one
        site_one_footer_menu = FlatMenu.get_for_site('footer', site_one)
        copy_view = self.app.get(
            '%scopy/%s/' % (self.base_flatmenu_admin_url, site_one_footer_menu.pk),
            user='test1')

        form = copy_view.forms[1]
        form['site'] = site_two.pk
        response = form.submit().follow()

        assert len(response.context['object_list']) == 4
        assert '<div class="changelist-filter col3">' in response

        # Let's just compare the two menu with the old one
        site_two_footer_menu = FlatMenu.get_for_site('footer', site_two)

        assert site_one_footer_menu.pk != site_two_footer_menu.pk
        assert site_one_footer_menu.heading == site_two_footer_menu.heading
        assert site_one_footer_menu.get_menu_items_manager().count() == site_two_footer_menu.get_menu_items_manager().count() 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:29,代码来源:test_backend.py

示例15: test_exclude

# 需要导入模块: from wagtail.core import models [as 别名]
# 或者: from wagtail.core.models import Site [as 别名]
def test_exclude(self):
        panels = extract_panel_definitions_from_model_class(Site, exclude=['hostname'])
        for panel in panels:
            self.assertNotEqual(panel.field_name, 'hostname') 
开发者ID:wagtail,项目名称:wagtail,代码行数:6,代码来源:test_edit_handlers.py


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