コード例 #1
0
ファイル: views.py プロジェクト: pombredanne/PyLucid
def detail_view(request, term=None):

    error_msg = _("Unknown lexicon term.")

    if term in ("", None):  # e.g.: term not in url or GET parameter 'empty'
        if settings.DEBUG or request.user.is_staff:
            error_msg += " (No term given.)"
        messages.error(request, error_msg)
        return

    queryset = LexiconEntry.on_site.filter(is_public=True)
    queryset = queryset.filter(term=term)

    entry, tried_languages = LexiconEntry.objects.get_by_prefered_language(request, queryset)

    if entry is None:
        if settings.DEBUG or request.user.is_staff or settings.PYLUCID.I18N_DEBUG:
            error_msg += " (term: %r, tried languages: %s)" % (term, ", ".join([l.code for l in tried_languages]))
        messages.error(request, error_msg)
        return summary(request)

    new_url = i18n.assert_language(request, entry.language, check_url_language=True)
    if new_url:
        # the current language is not the same as entry language -> redirect to right url
        # e.g. someone followed a external link to this article, but his preferred language
        # is a other language as this article. Activate the article language and "reload"
        return http.HttpResponseRedirect(new_url)

    #    if entry.language != request.PYLUCID.current_language:
    #        # The item exist in a other language than the client preferred language
    #        msg = _(
    #            "Info: This lexicon entry is written in %(article_lang)s."
    #            " However you prefer %(client_lang)s."
    #        ) % {
    #            "article_lang": entry.language.description,
    #            "client_lang": request.PYLUCID.current_language.description,
    #        }
    #        if settings.DEBUG or request.user.is_staff or settings.PYLUCID.I18N_DEBUG:
    #            msg += "(tried languages: %s)" % ", ".join([l.code for l in tried_languages])
    #        messages.info(request, msg)

    _add_breadcrumb(request, title="%s: %s" % (entry.term, entry.short_definition), url=request.path)

    # Change permalink from the blog root page to this entry detail view
    permalink = entry.get_permalink(request)
    request.PYLUCID.context["page_permalink"] = permalink  # for e.g. the HeadlineAnchor

    # Add comments in this view to the current lexicon entry and not to PageMeta
    request.PYLUCID.object2comment = entry

    # For adding page update information into context by pylucid context processor
    request.PYLUCID.updateinfo_object = entry

    context = {"entry": entry, "page_permalink": permalink}  # Change the permalink in the global page template
    return context
コード例 #2
0
ファイル: views.py プロジェクト: daqing15/PyLucid
def detail_view(request, id, title):
    """
    Display one blog entry with a comment form.
    """
    # Get all blog entries, that the current user can see
    queryset = _get_queryset(request, filter_language=False)

    try:
        entry = queryset.get(pk=id)
    except BlogEntry.DoesNotExist:
        # It's possible that the user comes from a external link.
        msg = "Blog entry doesn't exist."
        if settings.DEBUG or request.user.is_staff:
            msg += " (ID %r wrong.)" % id
        messages.error(request, msg)
        return summary(request)

    new_url = i18n.assert_language(request, entry.language)
    if new_url:
        # the current language is not the same as entry language -> redirect to right url
        # e.g. someone followed a external link to this article, but his preferred language
        # is a other language as this article. Activate the article language and "reload"
        return http.HttpResponsePermanentRedirect(new_url)

    # Add link to the breadcrumbs ;)
    _add_breadcrumb(request, entry.headline, _("Article '%s'") % entry.headline)

    tag_cloud = BlogEntry.objects.get_tag_cloud(request)

    # Change permalink from the blog root page to this entry detail view
    permalink = entry.get_permalink(request)
    request.PYLUCID.context["page_permalink"] = permalink # for e.g. the HeadlineAnchor

    # Add comments in this view to the current blog entry and not to PageMeta
    request.PYLUCID.object2comment = entry

    # For adding page update information into context by pylucid context processor
    request.PYLUCID.updateinfo_object = entry

    context = {
        "page_title": entry.headline, # Change the global title with blog headline
        "entry": entry,
        "tag_cloud": tag_cloud,
        "CSS_PLUGIN_CLASS_NAME": settings.PYLUCID.CSS_PLUGIN_CLASS_NAME,
        "page_permalink": permalink, # Change the permalink in the global page template
    }
    return context
コード例 #3
0
ファイル: views.py プロジェクト: BIGGANI/PyLucid
    e.g:
        en + de exists as languages
        user prefered de and called /en/foobar
        foobar does only exist in en not in de
    """

    if entry is None:
        # Entry not found -> Display summary with error message as 404 page
        if settings.DEBUG or request.user.is_staff or settings.PYLUCID.I18N_DEBUG:
            error_msg += " (term: %r, tried languages: %s)" % (term, ", ".join([l.code for l in tried_languages]))
        messages.error(request, error_msg)
        response = summary(request)
        response.status_code = 404 # Send as 404 page, so that search engines doesn't index this. 
        return response

    new_url = i18n.assert_language(request, entry.language, check_url_language=True)
    if new_url:
        # the current language is not the same as entry language -> redirect to right url
        # e.g. someone followed a external link to this article, but his preferred language
        # is a other language as this article. Activate the article language and "reload"
        return http.HttpResponseRedirect(new_url)

#    if entry.language != request.PYLUCID.current_language:
#        # The item exist in a other language than the client preferred language
#        msg = _(
#            "Info: This lexicon entry is written in %(article_lang)s."
#            " However you prefer %(client_lang)s."
#        ) % {
#            "article_lang": entry.language.description,
#            "client_lang": request.PYLUCID.current_language.description,
#        }
コード例 #4
0
ファイル: views.py プロジェクト: xuanxu11/PyLucid
        user prefered de and called /en/foobar
        foobar does only exist in en not in de
    """

    if entry is None:
        # Entry not found -> Display summary with error message as 404 page
        if settings.DEBUG or request.user.is_staff or settings.PYLUCID.I18N_DEBUG:
            error_msg += " (term: %r, tried languages: %s)" % (term, ", ".join(
                [l.code for l in tried_languages]))
        messages.error(request, error_msg)
        response = summary(request)
        response.status_code = 404  # Send as 404 page, so that search engines doesn't index this.
        return response

    new_url = i18n.assert_language(request,
                                   entry.language,
                                   check_url_language=True)
    if new_url:
        # the current language is not the same as entry language -> redirect to right url
        # e.g. someone followed a external link to this article, but his preferred language
        # is a other language as this article. Activate the article language and "reload"
        return http.HttpResponseRedirect(new_url)


#    if entry.language != request.PYLUCID.current_language:
#        # The item exist in a other language than the client preferred language
#        msg = _(
#            "Info: This lexicon entry is written in %(article_lang)s."
#            " However you prefer %(client_lang)s."
#        ) % {
#            "article_lang": entry.language.description,