Exemple #1
0
def tag_list(request):
    tags = Tag.all().order("-number").order("-inserted_at")
    return object_list(
        request,
        queryset=tags,
        allow_empty=True,
        template_name="snippet/tag_list.html",
        extra_context={"CURRENT_PAGE": "tag_list"},
        paginate_by=settings.TAG_LIST_PAGE_SIZE,
    )
Exemple #2
0
def user_favorites(request, user_id):
    user = UserPref.get_by_id(int(user_id))
    if not user: raise Http404
    favorites = UserFavSnippet.all().filter('user', user.key()).order('-inserted_at')
    favorites_count = favorites.count()
    snippets_count = Snippet.all().filter('author', user.key()).count()
    rev_tags, rev_languages = get_relevent_lang_tags(user)        
    return object_list(request, queryset=favorites, allow_empty=True,
                template_name='account/user_favorites.html', extra_context={'CURRENT_USER': user, 'CURRENT_PAGE': 'user_snippets', 'RELEVENT_TAGS': rev_tags, 'RELEVENT_LANGUAGES':rev_languages, 'CURRENT_USER_SNIPPERS_COUNT':snippets_count, 'CURRENT_USER_FAVORITES_COUNT':favorites_count},
                paginate_by=settings.SNIPPET_LIST_PAGE_SIZE)
Exemple #3
0
def user_tag_snippets(request, tag_name, tag_id, user_id):
    user = UserPref.get_by_id(int(user_id))
    if not user: raise Http404
    tag = Tag.get_by_id(int(tag_id))
    if not tag: raise Http404
    snippets = Tag.objects.snippets(tag)
    snippets = snippets.filter('author', user.key()).order('-published_at')
    snippets_count = Snippet.all().filter('author', user.key()).count()
    rev_tags, rev_languages = get_relevent_lang_tags(user)
    return object_list(request, queryset=snippets, allow_empty=True,
                template_name='account/user_detail.html', extra_context={'CURRENT_USER': user, 'CURRENT_PAGE': 'user_snippets', 'CURRENT_TAG': tag, 'RELEVENT_TAGS': rev_tags, 'RELEVENT_LANGUAGES':rev_languages, 'CURRENT_USER_SNIPPERS_COUNT': snippets_count},
                paginate_by=settings.SNIPPET_LIST_PAGE_SIZE)
Exemple #4
0
def snippet_list(request):
    snippets = Snippet.all().order("-published_at")

    rev_tags = Tag.all().order("-number").order("-inserted_at").fetch(settings.RELEVENT_TAG_LIMIT)

    return object_list(
        request,
        queryset=snippets,
        allow_empty=True,
        template_name="snippet/snippet_list.html",
        extra_context={"is_admin": is_admin(), "CURRENT_PAGE": "snippet_list", "RELEVENT_TAGS": rev_tags},
        paginate_by=settings.SNIPPET_LIST_PAGE_SIZE,
    )
Exemple #5
0
def tag_list(request, user_id):
    user = UserPref.get_by_id(int(user_id))
    if not user: raise Http404
    tmp_tags = UserTag.all().filter('user', user.key())
    tags = []
    for ut in tmp_tags: 
        try:
            tags.append(ut.tag)
        except:
            pass
    return object_list(request, queryset=tags, allow_empty=True,
                template_name='account/tag_list.html', extra_context={'CURRENT_USER': user, 'CURRENT_PAGE': 'user_tag_list'},
                paginate_by=settings.TAG_LIST_PAGE_SIZE)
Exemple #6
0
def language_tags(request, language):
    tags = Tag.all().filter("languages", language).order("-number").order("-inserted_at")
    for l, v in settings.SUPPORT_LANGUAGES.items():
        if l == language:
            current_language = {"name": v, "key": l}
            break
    return object_list(
        request,
        queryset=tags,
        allow_empty=True,
        template_name="snippet/tag_list.html",
        extra_context={"CURRENT_LANGUAGE": current_language, "CURRENT_PAGE": "tag_list"},
        paginate_by=settings.TAG_LIST_PAGE_SIZE,
    )
Exemple #7
0
def language_tags(request, language, user_id):
    user = UserPref.get_by_id(int(user_id))
    if not user: raise Http404
    tmp_tags = UserTag.all().filter('user', user.key())
    tags = []
    for ut in tmp_tags:
        if language in ut.tag.languages: tags.append(ut.tag)
    for l, v in settings.SUPPORT_LANGUAGES.items():
        if l == language:
            current_language = {'name':v, 'key':l}
            break;
    return object_list(request, queryset=tags, allow_empty=True,
                template_name='account/tag_list.html', extra_context={'CURRENT_USER': user, 'CURRENT_LANGUAGE': current_language, 'CURRENT_PAGE': 'user_tag_list'},
                paginate_by=settings.TAG_LIST_PAGE_SIZE)
Exemple #8
0
def user_language_snippets(request, language, user_id):
    user = UserPref.get_by_id(int(user_id))
    if not user: raise Http404
    snippets = Snippet.all().filter('author', user.key()).order('-published_at')
    snippets_count = snippets.count()
    snippets = snippets.filter('language', language).order('-published_at')
    rev_tags, rev_languages = get_relevent_lang_tags(user, language)
    for l, v in settings.SUPPORT_LANGUAGES.items():
        if l == language:
            current_language = {'name':v, 'key':l}
            break;
            
    return object_list(request, queryset=snippets, allow_empty=True,
                template_name='account/user_detail.html', extra_context={'CURRENT_USER': user, 'CURRENT_PAGE': 'user_snippets', 'CURRENT_LANGUAGE': current_language, 'RELEVENT_TAGS': rev_tags, 'RELEVENT_LANGUAGES':rev_languages, 'CURRENT_USER_SNIPPERS_COUNT': snippets_count},
                paginate_by=settings.SNIPPET_LIST_PAGE_SIZE)
Exemple #9
0
def tag_snippets(request, tag_name, tag_id):
    tag = Tag.get_by_id(int(tag_id))
    if not tag:
        raise Http404
    rev = TagCoef.all().filter("tag", tag.key()).order("distance").fetch(settings.RELEVENT_TAG_LIMIT)
    rev_tags = []
    if rev:
        rev_tags = [rt.related_tag for rt in rev]
    else:
        rev_tags = Tag.all().order("-number").order("-inserted_at").fetch(settings.RELEVENT_TAG_LIMIT)

    snippets = Tag.objects.snippets(tag)
    return object_list(
        request,
        queryset=snippets,
        allow_empty=True,
        template_name="snippet/snippet_list.html",
        extra_context={"CURRENT_TAG": tag, "CURRENT_PAGE": "snippet_list", "RELEVENT_TAGS": rev_tags},
        paginate_by=settings.SNIPPET_LIST_PAGE_SIZE,
    )
Exemple #10
0
def language_snippets(request, language):
    snippets = Snippet.all().filter("language", language).order("-published_at")
    for l, v in settings.SUPPORT_LANGUAGES.items():
        if l == language:
            current_language = {"name": v, "key": l}
            break
    rev_tags = (
        Tag.all()
        .filter("languages", language)
        .order("-number")
        .order("-inserted_at")
        .fetch(settings.RELEVENT_TAG_LIMIT)
    )

    return object_list(
        request,
        queryset=snippets,
        allow_empty=True,
        template_name="snippet/snippet_list.html",
        extra_context={"CURRENT_LANGUAGE": current_language, "CURRENT_PAGE": "snippet_list", "RELEVENT_TAGS": rev_tags},
        paginate_by=settings.SNIPPET_LIST_PAGE_SIZE,
    )
Exemple #11
0
def language_tag_snippets(request, language, tag_name, tag_id):
    tag = Tag.get_by_id(int(tag_id))
    if not tag:
        raise Http404
    rev = TagCoef.all().filter("tag", tag.key()).order("distance").fetch(settings.RELEVENT_TAG_LIMIT)
    rev_tags = []
    if rev:
        rev_tags = [rt.related_tag for rt in rev if language in rt.related_tag.languages]
    else:
        rev_tags = (
            Tag.all()
            .filter("languages", language)
            .order("-number")
            .order("-inserted_at")
            .fetch(settings.RELEVENT_TAG_LIMIT)
        )

    snippets = Tag.objects.snippets(tag)
    snippets = snippets.filter("language", language).order("-published_at")
    for l, v in settings.SUPPORT_LANGUAGES.items():
        if l == language:
            current_language = {"name": v, "key": l}
            break

    return object_list(
        request,
        queryset=snippets,
        allow_empty=True,
        template_name="snippet/snippet_list.html",
        extra_context={
            "CURRENT_LANGUAGE": current_language,
            "CURRENT_TAG": tag,
            "CURRENT_PAGE": "snippet_list",
            "RELEVENT_TAGS": rev_tags,
        },
        paginate_by=settings.SNIPPET_LIST_PAGE_SIZE,
    )
Exemple #12
0
def snippet_search(request):
    if request.GET.has_key("keyword"):
        keyword = request.GET["keyword"]
        logging.getLogger().info(keyword)
        if request.GET.has_key("search_language") and request.GET["search_language"]:
            snippets = (
                Snippet.all().filter("language", request.GET["search_language"]).search(keyword).order("-published_at")
            )
        else:
            snippets = Snippet.all().search(keyword).order("-published_at")
    else:
        if request.GET.has_key("search_language") and request.GET["search_language"]:
            snippets = Snippet.all().filter("language", request.GET["search_language"]).order("-published_at")
        else:
            snippets = Snippet.all().order("-published_at")
    rev_tags = Tag.all().order("-number").order("-inserted_at").fetch(settings.RELEVENT_TAG_LIMIT)
    return object_list(
        request,
        queryset=snippets,
        allow_empty=True,
        template_name="snippet/snippet_list.html",
        extra_context={"is_admin": is_admin(), "CURRENT_PAGE": "snippet_list", "RELEVENT_TAGS": rev_tags},
        paginate_by=settings.SNIPPET_LIST_PAGE_SIZE,
    )