Пример #1
0
def get_doc_components_from_url(url, required_locale=None, check_host=True):
    """Return (locale, path, slug) if URL is a Document, False otherwise.
    If URL doesn't even point to the document view, raise _NotDocumentView.
    """
    # Extract locale and path from URL:
    parsed = urlparse(url)  # Never has errors AFAICT
    if check_host and parsed.netloc:
        # Only allow redirects on our domain
        if parsed.netloc != settings.DOMAIN:
            return False

    locale, path = split_path(parsed.path)
    if required_locale and locale != required_locale:
        return False

    try:
        with translation.override(locale):
            view, view_args, view_kwargs = resolve(parsed.path)
    except Resolver404:
        return False

    # View imports Model, Model imports utils, utils import Views.
    from kuma.wiki.views.document import document as document_view

    if view != document_view:
        raise NotDocumentView

    path = '/' + path
    return locale, path, view_kwargs['document_path']
Пример #2
0
def get_doc_components_from_url(url, required_locale=None, check_host=True):
    """Return (locale, path, slug) if URL is a Document, False otherwise.
    If URL doesn't even point to the document view, raise _NotDocumentView.
    """
    # Extract locale and path from URL:
    parsed = urlparse(url)  # Never has errors AFAICT
    if check_host and parsed.netloc:
        # Only allow redirects on our site
        site = urlparse(settings.SITE_URL)
        if parsed.scheme != site.scheme or parsed.netloc != site.netloc:
            return False

    locale, path = split_path(parsed.path)
    if required_locale and locale != required_locale:
        return False

    try:
        with translation.override(locale):
            view, view_args, view_kwargs = resolve(parsed.path)
    except Resolver404:
        return False

    # View imports Model, Model imports utils, utils import Views.
    from kuma.wiki.views.document import document as document_view

    if view != document_view:
        raise NotDocumentView

    path = '/' + path
    return locale, path, view_kwargs['document_path']