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


Python Site.find_for_request方法代码示例

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


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

示例1: get

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def get(self, request, *args, **kwargs):
        site = Site.find_for_request(request)
        if not site:
            raise Http404
        if request.resolver_match.url_name == 'entry_page_serve_slug':
            # Splitting the request path and obtaining the path_components
            # this way allows you to place the blog at the level you want on
            # your sitemap.
            # Example:
            # splited_path =  ['es', 'blog', '2016', '06', '23', 'blog-entry']
            # slicing this way you obtain:
            # path_components =  ['es', 'blog', 'blog-entry']
            # with the oldest solution you'll get ['es', 'blog-entry']
            # and a 404 will be raised
            splited_path = strip_prefix_and_ending_slash(request.path).split("/")
            path_components = splited_path[:-4] + splited_path[-1:]
        else:
            path_components = [strip_prefix_and_ending_slash(request.path).split('/')[-1]]
        page, args, kwargs = site.root_page.specific.route(request, path_components)

        for fn in hooks.get_hooks('before_serve_page'):
            result = fn(page, request, args, kwargs)
            if isinstance(result, HttpResponse):
                return result
        return page.serve(request, *args, **kwargs) 
开发者ID:APSL,项目名称:puput,代码行数:27,代码来源:views.py

示例2: test_preview_uses_correct_site

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def test_preview_uses_correct_site(self):
        # create a Site record for the child page
        Site.objects.create(hostname='childpage.example.com', root_page=self.child_page)

        post_data = {
            'title': "I've been edited!",
            'content': "Some content",
            'slug': 'hello-world',
            'action-submit': "Submit",
        }
        preview_url = reverse('wagtailadmin_pages:preview_on_edit',
                              args=(self.child_page.id,))
        response = self.client.post(preview_url, post_data)

        # Check the JSON response
        self.assertEqual(response.status_code, 200)
        self.assertJSONEqual(response.content.decode(), {'is_valid': True})

        response = self.client.get(preview_url)

        # Check that the correct site object has been selected by the site middleware
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'tests/simple_page.html')
        self.assertEqual(Site.find_for_request(response.context['request']).hostname, 'childpage.example.com') 
开发者ID:wagtail,项目名称:wagtail,代码行数:26,代码来源:test_edit_page.py

示例3: get_base_queryset

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def get_base_queryset(self):
        """
        Returns a queryset containing all pages that can be seen by this user.

        This is used as the base for get_queryset and is also used to find the
        parent pages when using the child_of and descendant_of filters as well.
        """
        # Get live pages that are not in a private section
        queryset = Page.objects.all().public().live()

        # Filter by site
        site = Site.find_for_request(self.request)
        if site:
            queryset = queryset.descendant_of(site.root_page, inclusive=True)
        else:
            # No sites configured
            queryset = queryset.none()

        return queryset 
开发者ID:wagtail,项目名称:wagtail,代码行数:21,代码来源:views.py

示例4: get_base_url

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def get_base_url(request=None):
    base_url = None

    try:
        base_url = getattr(settings, 'WAGTAILAPI_BASE_URL')
    except AttributeError:
        if request:
            site = Site.find_for_request(request)
            if site:
                base_url = site.root_url

    if base_url:
        # We only want the scheme and netloc
        base_url_parsed = urlparse(base_url)

        return base_url_parsed.scheme + '://' + base_url_parsed.netloc 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:utils.py

示例5: routablepageurl

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def routablepageurl(context, page, url_name, *args, **kwargs):
    """
    ``routablepageurl`` is similar to ``pageurl``, but works with
    pages using ``RoutablePageMixin``. It behaves like a hybrid between the built-in
    ``reverse``, and ``pageurl`` from Wagtail.

    ``page`` is the RoutablePage that URLs will be generated from.

    ``url_name`` is a URL name defined in ``page.subpage_urls``.

    Positional arguments and keyword arguments should be passed as normal
    positional arguments and keyword arguments.
    """
    request = context['request']
    site = Site.find_for_request(request)
    base_url = page.relative_url(site, request)
    routed_url = page.reverse_subpage(url_name, args=args, kwargs=kwargs)
    if not base_url.endswith('/'):
        base_url += '/'
    return base_url + routed_url 
开发者ID:wagtail,项目名称:wagtail,代码行数:22,代码来源:wagtailroutablepage_tags.py

示例6: get_setting

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def get_setting(context, model_string, use_default_site=False):
    if use_default_site:
        site = Site.objects.get(is_default_site=True)
    elif 'request' in context:
        site = Site.find_for_request(context['request'])
    else:
        raise RuntimeError('No request found in context, and use_default_site '
                           'flag not set')

    # Sadly, WeakKeyDictionary can not implement __missing__, so we have to do
    # this one manually
    try:
        context_cache = settings_cache[context]
    except KeyError:
        context_cache = settings_cache[context] = ContextCache()
    # These ones all implement __missing__ in a useful way though
    return context_cache[site][model_string] 
开发者ID:wagtail,项目名称:wagtail,代码行数:19,代码来源:jinja2tags.py

示例7: test_models_cached

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def test_models_cached(self):
        """ Accessing a setting should only hit the DB once per request instance,
        even if using that request to rendering multiple times"""
        request = self.get_request()
        get_title = '{{ settings.tests.testsetting.title }}'

        # force site query beforehand
        Site.find_for_request(request)

        with self.assertNumQueries(1):
            for i in range(1, 4):
                with self.subTest(attempt=i):
                    self.assertEqual(
                        self.render(request, get_title * i),
                        self.default_site_settings.title * i
                    ) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_templates.py

示例8: meta_tags

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def meta_tags(request, model):
    if not request:
        raise TemplateSyntaxError(
            "'meta_tags' missing request from context")
    if not model:
        raise TemplateSyntaxError(
            "'meta_tags' tag is missing a model or object")
    context = {
        'site_name': Site.find_for_request(request).site_name,
        'object': model,
    }

    meta_image = model.get_meta_image()
    if meta_image:
        meta_image = get_meta_image_url(request, meta_image)
    context['meta_image'] = meta_image

    return render_to_string('wagtailmetadata/parts/tags.html',
                            context, request=request) 
开发者ID:neon-jungle,项目名称:wagtail-metadata,代码行数:21,代码来源:tags.py

示例9: item_link

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def item_link(self, item):
        from .urls import get_entry_url
        entry_url = get_entry_url(item, self.blog_page.page_ptr, Site.find_for_request(self.request).root_page)
        return self.request.build_absolute_uri(entry_url) 
开发者ID:APSL,项目名称:puput,代码行数:6,代码来源:feeds.py

示例10: item_enclosure_url

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def item_enclosure_url(self, item):
        if item.header_image:
            site = Site.find_for_request(self.request)
            return urljoin(site.root_url, item.header_image.file.url)
        return None 
开发者ID:APSL,项目名称:puput,代码行数:7,代码来源:feeds.py

示例11: _channel_image_link

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def _channel_image_link(self):
        if self.blog_page.header_image:
            site = Site.find_for_request(self.request)
            return urljoin(site.root_url, self.blog_page.header_image.file.url) 
开发者ID:APSL,项目名称:puput,代码行数:6,代码来源:feeds.py

示例12: entry_url

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def entry_url(context, entry, blog_page):
    return get_entry_url(entry, blog_page.page_ptr, Site.find_for_request(context['request']).root_page) 
开发者ID:APSL,项目名称:puput,代码行数:4,代码来源:puput_tags.py

示例13: setUp

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def setUp(self):
        self.shipping_address = AddressFactory()
        self.billing_address = AddressFactory()
        self.email = "test@test.com"
        self.request = RequestFactory().get('/')
        self.request.session = {}
        self.request.site = Site.find_for_request(self.request)
        self.basket_id = basket_id(self.request)
        BasketItemFactory(basket_id=self.basket_id) 
开发者ID:JamesRamm,项目名称:longclaw,代码行数:11,代码来源:tests.py

示例14: dispatch

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def dispatch(self, request, *args, **kwargs):
        site = Site.find_for_request(request)
        return redirect(
            self.model_admin.url_helper.get_action_url('edit', site.pk)) 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:6,代码来源:views.py

示例15: get_site_from_request

# 需要导入模块: from wagtail.core.models import Site [as 别名]
# 或者: from wagtail.core.models.Site import find_for_request [as 别名]
def get_site_from_request(request, fallback_to_default=True):
    site = getattr(request, 'site', None)
    if isinstance(site, Site):
        return request.site
    site = Site.find_for_request(request)
    if site:
        return site
    if fallback_to_default:
        return Site.objects.filter(is_default_site=True).first()
    return None 
开发者ID:rkhleics,项目名称:wagtailmenus,代码行数:12,代码来源:misc.py


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