示例#1
0
def _i18n_redirect(request, url_path):
    """ Redirect to a url with the default language code. """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    # Check only, if url_path is right (if there exist a pagetree object)
    # otherwise -> 404 would be raised
    #     try:
    #         PageTree.objects.get_page_from_url(request, url_path)
    #     except PageTree.DoesNotExist, err:
    #         msg = _("Page not found")
    #         if settings.DEBUG or request.user.is_staff:
    #             msg += " url path: %r (%s)" % (url_path, err)
    #         raise http.Http404(msg)

    lang_code = request.LANGUAGE_CODE
    #     FIXME:
    url = reverse('PyLucid-render_page',
                  kwargs={
                      'url_lang_code': lang_code,
                      'url_path': url_path
                  })

    if not url.endswith("/"):
        url += "/"

    if request.GET:
        # Add GET query string
        # We don't use request.GET.urlencode() here, because it can change the key positions
        full_path = request.get_full_path()
        get_string = full_path.split("?", 1)[1]
        url += "?" + get_string

    # redirect to url with lang_code
    return http.HttpResponseRedirect(url)
示例#2
0
def _i18n_redirect(request, url_path):
    """ Redirect to a url with the default language code. """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    # Check only, if url_path is right (if there exist a pagetree object)
    # otherwise -> 404 would be raised
#     try:
#         PageTree.objects.get_page_from_url(request, url_path)
#     except PageTree.DoesNotExist, err:
#         msg = _("Page not found")
#         if settings.DEBUG or request.user.is_staff:
#             msg += " url path: %r (%s)" % (url_path, err)
#         raise http.Http404(msg)

    lang_code = request.LANGUAGE_CODE
#     FIXME:
    url = reverse('PyLucid-render_page', kwargs={'url_lang_code': lang_code, 'url_path': url_path})

    if not url.endswith("/"):
        url += "/"

    if request.GET:
        # Add GET query string
        # We don't use request.GET.urlencode() here, because it can change the key positions
        full_path = request.get_full_path()
        get_string = full_path.split("?", 1)[1]
        url += "?" + get_string

    # redirect to url with lang_code
    return http.HttpResponseRedirect(url)
示例#3
0
def redirect_to_lang_url(request, url_slugs):
    if Language.objects.is_language_code(url_slugs):
        # url_splug is a language code and not a page tree slug
        return root_page(request)

    # activate language via auto detection
    i18n.activate_auto_language(request)

    pagetree, prefix_url, rest_url = get_page_from_url(request, url_slugs)
    return _redirect(request, pagetree)
示例#4
0
def redirect_to_lang_url(request, url_slugs):
    if Language.objects.is_language_code(url_slugs):
        # url_splug is a language code and not a page tree slug
        return root_page(request)

    # activate language via auto detection
    i18n.activate_auto_language(request)

    pagetree, prefix_url, rest_url = get_page_from_url(request, url_slugs)
    return _redirect(request, pagetree)
示例#5
0
文件: views.py 项目: daqing15/PyLucid
def lang_root_page(request, url_lang_code):
    """ url with lang code but no page slug """

    if _lang_code_is_pagetree(request, url_lang_code):
        # The url doesn't contain a language code, it's a pagetree slug
        return _i18n_redirect(request, url_path=url_lang_code)

    # activate i18n
    i18n.activate_auto_language(request)

    return _render_root_page(request, url_lang_code)
示例#6
0
def root_page(request):
    """
    redirect to a url with language code
    We can't serve the root page here, because it will be cached in current
    language with "/" as key. So a other client with other language will see
    the page always in the cached language and not in his preferred language
    """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    pagetree = _get_root_page(request)
    return _redirect(request, pagetree)
示例#7
0
def root_page(request):
    """
    redirect to a url with language code
    We can't serve the root page here, because it will be cached in current
    language with "/" as key. So a other client with other language will see
    the page always in the cached language and not in his preferred language
    """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    pagetree = _get_root_page(request)
    return _redirect(request, pagetree)
示例#8
0
文件: views.py 项目: BIGGANI/PyLucid
def permalink(request, page_id, url_rest=""):
    """ resolve a permalink and redirect to the real url. """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    try:
        pagetree = PageTree.on_site.get(id=page_id)
    except PageTree.DoesNotExist, err:
        # TODO: Try to search with the additional url data (url_rest)
        msg = "Page not found"
        if settings.DEBUG:
            msg += " PageTree ID: %r (%s)" % (page_id, err)
        raise http.Http404(msg)
示例#9
0
文件: views.py 项目: BIGGANI/PyLucid
def resolve_url(request, url_lang_code, url_path):
    """ url with lang_code and sub page path """
    if _lang_code_is_pagetree(request, url_lang_code):
        # url_lang_code doesn't contain a language code, it's a pagetree slug
        new_url = "%s/%s" % (url_lang_code, url_path)
        return _i18n_redirect(request, url_path=new_url)

    # activate language via auto detection
    i18n.activate_auto_language(request)

    pagetree, prefix_url, rest_url = _get_pagetree(request, url_path)

    return _render_page(request, pagetree, url_lang_code, prefix_url, rest_url)
示例#10
0
def permalink(request, page_id, url_rest=""):
    """ resolve a permalink and redirect to the real url. """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    try:
        pagetree = PageTree.on_site.get(id=page_id)
    except PageTree.DoesNotExist, err:
        # TODO: Try to search with the additional url data (url_rest)
        msg = "Page not found"
        if settings.DEBUG:
            msg += " PageTree ID: %r (%s)" % (page_id, err)
        raise http.Http404(msg)
示例#11
0
文件: views.py 项目: BIGGANI/PyLucid
def root_page(request):
    """
    redirect to a url with language code
    We can't serve the root page here, because it will be cached in current
    language with "/" as key. So a other client with other language will see
    the page always in the cached language and not in his preferred language
    """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    pagetree = _get_root_page(request)

    pagemeta = PageTree.objects.get_pagemeta(request, pagetree, show_lang_errors=False)
    url = pagemeta.get_absolute_url()

    return http.HttpResponseRedirect(url)
示例#12
0
文件: views.py 项目: BIGGANI/PyLucid
def _i18n_redirect(request, url_path):
    """ Redirect to a url with the default language code. """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    # Check only, if url_path is right (if there exist a pagetree object)
    # otherwise -> 404 would be raised
    _get_pagetree(request, url_path)

    lang_code = request.LANGUAGE_CODE
    url = reverse('PyLucid-resolve_url', kwargs={'url_lang_code': lang_code, 'url_path': url_path})

    if not url.endswith("/"):
        url += "/"

    if request.GET:
        # Add GET query string
        # We don't use request.GET.urlencode() here, because it can change the key positions
        full_path = request.get_full_path()
        get_string = full_path.split("?", 1)[1]
        url += "?" + get_string

    # redirect to url with lang_code
    return http.HttpResponseRedirect(url)
示例#13
0
文件: views.py 项目: daqing15/PyLucid
def root_page(request):
    """ render the first root page in system default language """
    # activate language via auto detection
    i18n.activate_auto_language(request)

    return _render_root_page(request)