• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.Site类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_oops_there_is_more_than_one

    def test_oops_there_is_more_than_one(self):
        Site.objects.create(hostname="example.com", is_default_site=True, root_page=Page.objects.get(pk=2))

        site = Site(hostname="test.com", is_default_site=True, root_page=Page.objects.get(pk=2))
        with self.assertRaises(Site.MultipleObjectsReturned):
            # If there already are multiple default sites, you're in trouble
            site.clean_fields()
开发者ID:Frankie-666,项目名称:wagtail,代码行数:7,代码来源:test_sites.py


示例2: test_duplicate_slug

    def test_duplicate_slug(self):
        from wagtail.wagtailcore.models import Site
        # Create a test Site with a root page
        root = models.TestRootPage(title='title', depth=1, path='0001', slug_en='slug_en', slug_de='slug_de')
        root.save()

        site = Site(root_page=root)
        site.save()

        # Add children to the root
        child = root.add_child(
            instance=models.TestSlugPage1(title='child1', slug_de='child', slug_en='child-en', depth=2, path='00010001')
        )

        child2 = root.add_child(
            instance=models.TestSlugPage2(title='child2', slug_de='child-2', slug_en='child2-en', depth=2,
                                          path='00010002')
        )

        # Clean should work fine as the two slugs are different
        child2.clean()

        # Make the slug equal to test if the duplicate is detected
        child2.slug_de = 'child'

        self.assertRaises(ValidationError, child2.clean)
开发者ID:sinnwerkstatt,项目名称:wagtail-modeltranslation,代码行数:26,代码来源:tests.py


示例3: test_get_unit_chat_link

    def test_get_unit_chat_link(self):
        """
        Test that pages in the site get the correct ask a librarian 
        link to their corresoinding AskPage and chat widget. Eckhart 
        and SCRC are treated differently since they're circumstances
        are slightly different.
        """
        ask_widgets = set(['law', 'crerar', 'ssa', 'uofc-ask', 'dissertation-office'])

        # Dictionary of tuples where the keys map to the ask_widget_name field  
        # of AskPages. The firs item of the tuple is a mixed dictionary of 
        # location/hours/unit information and the second item of the tuple is 
        # a random url belonging to a page of a given section of the site.
        data = {
            'law': (get_hours_and_location(StandardPage.objects.get(id=DANGELO_HOMEPAGE)), '/law/services/carrelslockers/'),
            'crerar': (get_hours_and_location(StandardPage.objects.get(id=CRERAR_HOMEPAGE)), '/crerar/science-research-services/data-support-services/'),
            'ssa': (get_hours_and_location(StandardPage.objects.get(id=SSA_HOMEPAGE)), '/ssa/about/'),
            'uofc-ask': (get_hours_and_location(StandardPage.objects.get(id=PUBLIC_HOMEPAGE)), '/research/help/offcampus/'),
            'dissertation-office': (get_hours_and_location(StandardPage.objects.get(id=DISSERTATION_HOMEPAGE)), '/research/scholar/phd/students/'),
            'eck': (get_hours_and_location(StandardPage.objects.get(id=ECKHART_HOMEPAGE)), '/eck/mathematics-research-services/'),
            'scrc': (get_hours_and_location(StandardPage.objects.get(id=SCRC_HOMEPAGE)), '/scrc/visiting/'),
        }

        # Normal chat links to regular AskPages
        for item in ask_widgets:
            request = HttpRequest()
            request.path = data[item][1]
            current_site = Site.find_for_request(request)

            a = get_unit_chat_link(data[item][0]['page_unit'], request)
            b = AskPage.objects.filter(ask_widget_name=item).first().relative_url(current_site)

            self.assertEqual(a, b)

        # Eckhart
        request_eck = HttpRequest()
        request_eck.path = data['eck'][1]
        current_site = Site.find_for_request(request_eck)
        eckurl = get_unit_chat_link(data['eck'][0]['page_unit'], request_eck)
        eckask = AskPage.objects.get(id=4646).relative_url(current_site)
        self.assertEqual(eckurl, eckask)


        # SCRC
        request_scrc = HttpRequest()
        request_scrc.path = data['scrc'][1]
        current_site = Site.find_for_request(request_scrc)
        scrcurl = get_unit_chat_link(data['scrc'][0]['page_unit'], request_scrc)
        scrcask = PublicRawHTMLPage.objects.get(id=4127).relative_url(current_site)
        self.assertEqual(scrcurl, scrcask)
开发者ID:uchicago-library,项目名称:library_website,代码行数:50,代码来源:tests.py


示例4: get_context

 def get_context(self, request):
     context = super(ConferenceSubPage, self).get_context(request)
     current_site = Site.find_for_request(request)
     context['banner_image'] = self.get_parent().conferencepage.banner_image
     context['branding_color'] = self.get_parent().conferencepage.branding_color
     context['conference_logo'] = self.get_parent().conferencepage.conference_logo 
     context['conference_title'] = self.get_parent().title
     context['conference_subtitle'] = self.get_parent().conferencepage.subtitle
     context['conference_tagline'] = self.get_parent().conferencepage.tagline
     context['has_social_media'] = self.get_parent().conferencepage.has_social_media
     context['main_registration'] = self.get_parent().conferencepage.main_registration.all()
     context['sponsors'] = self.get_parent().conferencepage.sponsors.all()
     context['organizers'] = self.get_parent().conferencepage.organizers.all()
     context['twitter_page'] = self.get_parent().conferencepage.twitter_page 
     context['facebook_page'] = self.get_parent().conferencepage.facebook_page
     context['hashtag_page'] = self.get_parent().conferencepage.hashtag_page
     context['hashtag'] = self.get_parent().conferencepage.hashtag
     context['instagram_page'] = self.get_parent().conferencepage.instagram_page
     context['youtube_page'] = self.get_parent().conferencepage.youtube_page
     context['blog_page'] = self.get_parent().conferencepage.blog_page
     context['tumblr_page'] = self.get_parent().conferencepage.tumblr_page
     context['snapchat_page'] = self.get_parent().conferencepage.snapchat_page
     context['secondary_registration'] = self.get_parent().conferencepage.sub_registration.all()
     context['secondary_registration_heading'] = self.get_parent().conferencepage.secondary_registration_heading
     context['secondary_registration_description'] = self.get_parent().conferencepage.secondary_registration_description
     context['home'] = self.get_parent().conferencepage.relative_url(current_site)
     return context
开发者ID:josearreluce,项目名称:library_website,代码行数:27,代码来源:models.py


示例5: test_with_server_name

 def test_with_server_name(self):
     request = HttpRequest()
     request.META = {
         'SERVER_NAME': 'example.com',
         'SERVER_PORT': 80
     }
     self.assertEqual(Site.find_for_request(request), self.site)
开发者ID:jschneier,项目名称:wagtail,代码行数:7,代码来源:test_sites.py


示例6: scan

def scan(request):
    site = Site.find_for_request(request)
    broken_links = broken_link_scan(site)

    return render(request, 'wagtaillinkchecker/results.html', {
        'broken_links': broken_links,
    })
开发者ID:nils-werner,项目名称:wagtail-linkchecker,代码行数:7,代码来源:views.py


示例7: test_unrecognised_host_header_routes_to_default_site

 def test_unrecognised_host_header_routes_to_default_site(self):
     # requests with an unrecognised Host: header should be directed to the default site
     request = HttpRequest()
     request.path = '/'
     request.META['HTTP_HOST'] = self.unrecognised_hostname
     request.META['SERVER_PORT'] = '80'
     self.assertEqual(Site.find_for_request(request), self.default_site)
开发者ID:MariusCC,项目名称:wagtail,代码行数:7,代码来源:test_page_model.py


示例8: _import_pages

 def _import_pages (self, exported_page_data):
     # Delete any existing pages.
     for page in Page.objects.all():
         page.delete()
     with open(exported_page_data, 'r') as fh:
         page_data = cPickle.load(fh)
     for page_name, info in page_data.items():
         self.logger.debug('Creating page {}'.format(page_name))
         page = info['class'](**info['kwargs'])
         page.save()
         self._pages[page_name] = page
     # Add a Wagtail Site, or nothing will appear anywhere.
     home_page = HomePage.objects.all()[0]
     site = Site(hostname='localhost', root_page=home_page,
                 is_default_site=True)
     site.save()
开发者ID:kcl-ddh,项目名称:chopin-online,代码行数:16,代码来源:import_all.py


示例9: live_preview

def live_preview(request):

    try:
        if u'/' == request.path:
            page = Site.find_for_request(request).root_page.specific
        else:
            logger.info("path: %s", '//'+request.path)
            page = Page.objects.get(url_path='//'+request.path).specific
    except Page.DoesNotExist:
        return {}

    content_file = os.path.join(settings.BOOTSTRAP_CONTENT_DIR, 'pages', request.path.strip('/') + '.yml')
    if not os.path.isfile(content_file):
        return {}

    content_attributes = load_attributes_from_file(content_file)

    try:
        del content_attributes['type']
    except KeyError:
        pass

    SiteNode.set_page_attributes(page, content_attributes, get_relation_mappings())

    return {'self': page}
开发者ID:bgrace,项目名称:wagtail-commons,代码行数:25,代码来源:context_processors.py


示例10: test_ports_in_request_headers_are_respected

 def test_ports_in_request_headers_are_respected(self):
     # ports in the Host: header should be respected
     request = HttpRequest()
     request.path = '/'
     request.META['HTTP_HOST'] = self.alternate_port_events_site.hostname
     request.META['SERVER_PORT'] = self.alternate_port_events_site.port
     self.assertEqual(Site.find_for_request(request), self.alternate_port_events_site)
开发者ID:MariusCC,项目名称:wagtail,代码行数:7,代码来源:test_page_model.py


示例11: get_context

    def get_context(self, request):
        context = super(ConferenceSubPage, self).get_context(request)
        current_site = Site.find_for_request(request)
        parent = self.get_parent_of_type('conference page')
        has_sidebar = parent.has_left_sidebar(context) or bool(main_reg)

        # Set social media fields dynamically and
        # get all the values from the parent page.
        # This doesn't seem like a good practice
        # How else can this be done?
        social_media_fields = [f.name for f in SocialMediaFields._meta.get_fields()]
        for field in social_media_fields:
            exec('self.' + field + ' = ' + 'parent.' + field)

        context['primary_branding_color'] = parent.primary_branding_color
        context['secondary_branding_color'] = parent.secondary_branding_color
        context['conference_logo'] = parent.conference_logo 
        context['conference_title'] = parent.title
        context['has_social_media'] = parent.has_social_media
        context['main_registration'] = parent.main_registration.all()
        context['sponsors'] = parent.sponsors.all()
        context['organizers'] = parent.organizers.all()
        context['secondary_registration'] = parent.sub_registration.all()
        context['secondary_registration_heading'] = parent.secondary_registration_heading
        context['secondary_registration_description'] = parent.secondary_registration_description
        context['home'] = parent.relative_url(current_site)
        return context
开发者ID:uchicago-library,项目名称:library_website,代码行数:27,代码来源:models.py


示例12: test_valid_headers_route_to_specific_site

 def test_valid_headers_route_to_specific_site(self):
     # requests with a known Host: header should be directed to the specific site
     request = HttpRequest()
     request.path = '/'
     request.META['HTTP_HOST'] = self.events_site.hostname
     request.META['SERVER_PORT'] = self.events_site.port
     self.assertEqual(Site.find_for_request(request), self.events_site)
开发者ID:MariusCC,项目名称:wagtail,代码行数:7,代码来源:test_page_model.py


示例13: test_port_in_http_host_header_is_ignored

 def test_port_in_http_host_header_is_ignored(self):
     # port in the HTTP_HOST header is ignored
     request = HttpRequest()
     request.path = '/'
     request.META['HTTP_HOST'] = "%s:%s" % (self.events_site.hostname, self.events_site.port)
     request.META['SERVER_PORT'] = self.alternate_port_events_site.port
     self.assertEqual(Site.find_for_request(request), self.alternate_port_events_site)
开发者ID:MariusCC,项目名称:wagtail,代码行数:7,代码来源:test_page_model.py


示例14: test_unrecognised_port_and_default_host_routes_to_default_site

 def test_unrecognised_port_and_default_host_routes_to_default_site(self):
     # requests to the default host on an unrecognised port should be directed to the default site
     request = HttpRequest()
     request.path = '/'
     request.META['HTTP_HOST'] = self.default_site.hostname
     request.META['SERVER_PORT'] = self.unrecognised_port
     self.assertEqual(Site.find_for_request(request), self.default_site)
开发者ID:MariusCC,项目名称:wagtail,代码行数:7,代码来源:test_page_model.py


示例15: test_unrecognised_port_on_known_hostname_routes_there_if_no_ambiguity

 def test_unrecognised_port_on_known_hostname_routes_there_if_no_ambiguity(self):
     # requests on an unrecognised port should be directed to the site with
     # matching hostname if there is no ambiguity
     request = HttpRequest()
     request.path = '/'
     request.META['HTTP_HOST'] = self.about_site.hostname
     request.META['SERVER_PORT'] = self.unrecognised_port
     self.assertEqual(Site.find_for_request(request), self.about_site)
开发者ID:MariusCC,项目名称:wagtail,代码行数:8,代码来源:test_page_model.py


示例16: setUp

    def setUp(self):
        self.home_page = Page.objects.get(id=2)
        self.routable_page = self.home_page.add_child(instance=RoutablePageTest(title="Routable Page", live=True))

        self.rf = RequestFactory()
        self.request = self.rf.get(self.routable_page.url)
        self.request.site = Site.find_for_request(self.request)
        self.context = {"request": self.request}
开发者ID:tomdyson,项目名称:wagtail,代码行数:8,代码来源:tests.py


示例17: test_unrecognised_port_on_known_hostname_routes_to_default_site_if_ambiguity

 def test_unrecognised_port_on_known_hostname_routes_to_default_site_if_ambiguity(self):
     # requests on an unrecognised port should be directed to the default
     # site, even if their hostname (but not port) matches more than one
     # other entry
     request = HttpRequest()
     request.path = '/'
     request.META['HTTP_HOST'] = self.events_site.hostname
     request.META['SERVER_PORT'] = self.unrecognised_port
     self.assertEqual(Site.find_for_request(request), self.default_site)
开发者ID:MariusCC,项目名称:wagtail,代码行数:9,代码来源:test_page_model.py


示例18: test_tag

    def test_tag(self):
        factory = RequestFactory()

        request = factory.get('/home/blog/tag/news/')
        request.site = Site.find_for_request(request)
        request.user = User.objects.create_user(username='test')

        response = self.bip.tag(request)
        self.assertEqual(200, response.status_code)
开发者ID:kingsdigitallab,项目名称:kdl-django,代码行数:9,代码来源:tests.py


示例19: process_request

 def process_request(self, request):
     """
     Set request.site to contain the Site object responsible for handling this request,
     according to hostname matching rules
     """
     try:
         request.site = Site.find_for_request(request)
     except Site.DoesNotExist:
         request.site = None
开发者ID:bmihelac,项目名称:wagtail,代码行数:9,代码来源:middleware.py


示例20: item_enclosure_url

 def item_enclosure_url(self, item):
     if not getattr(item.featured_image, 'file', None):
         url = item.featured_image
     else:
         url = item.featured_image.file.url
         url = "{0}://{1}{2}".format(
             "http" + ("s" if self.request.is_secure() else ""),
             Site.find_for_request(self.request).hostname,
             url
         )
     return url
开发者ID:PARINetwork,项目名称:pari,代码行数:11,代码来源:feeds.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.UserPagePermissionsProxy类代码示例发布时间:2022-05-26
下一篇:
Python models.Page类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap