Ejemplo n.º 1
0
 def update_correlations(self, offset):
     self.count_tags()
     tags = Tag.all().fetch(10, int(offset))
     if not tags: return
     all_tags = Tag.all()
     for tag in all_tags:
         self.get_tag_relations(tag, all_tags)
Ejemplo n.º 2
0
def snippet_sitemap(request):
    languages = []
    for alias, lang in settings.SUPPORT_LANGUAGES.items():
        tags = Tag.all().filter("languages", alias).order("-number").order("-inserted_at")
        if not tags.count():
            continue
        languages.append({"alias": alias, "lang": lang, "tags": tags.fetch(10)})
    return render_to_response(
        "snippet/snippet_sitemap.html", {"SUPPORT_LANGUAGES": languages}, context_instance=RequestContext(request)
    )
Ejemplo n.º 3
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,
    )
Ejemplo n.º 4
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,
    )
Ejemplo n.º 5
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)
Ejemplo n.º 6
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,
    )
Ejemplo n.º 7
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,
    )
Ejemplo n.º 8
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,
    )
Ejemplo n.º 9
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,
    )
Ejemplo n.º 10
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,
    )
Ejemplo n.º 11
0
def sitemap(request):
    str = (
        """<?xml version="1.0" encoding="UTF-8"?>
        <urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">
            <url>
                <loc>%s/</loc>
                <changefreq>daily</changefreq>
                <priority>0.9</priority>
            </url>
        """
        % settings.SITE_DOMAIN
    )

    for alias, lang in settings.SUPPORT_LANGUAGES.items():
        str += """<url>
                    <loc>%s%s</loc>
                      <changefreq>daily</changefreq>
                      <priority>0.8</priority>
                   </url>
                """ % (
            settings.SITE_DOMAIN,
            reverse("language_snippets", kwargs={"language": alias}),
        )
    for tag in Tag.all():
        str += """<url>
                    <loc>%s%s</loc>
                      <changefreq>daily</changefreq>
                      <priority>0.8</priority>
                   </url>
                """ % (
            settings.SITE_DOMAIN,
            reverse("tag_snippets", kwargs={"tag_name": tag.get_escape_name(), "tag_id": tag.key().id()}),
        )

    for alias, lang in settings.SUPPORT_LANGUAGES.items():
        tags = Tag.all().filter("languages", alias)
        if not tags:
            continue
        for tag in tags:
            str += """<url>
                        <loc>%s%s</loc>
                          <changefreq>daily</changefreq>
                          <priority>0.8</priority>
                       </url>
                    """ % (
                settings.SITE_DOMAIN,
                reverse(
                    "language_tag_snippets",
                    kwargs={"language": alias, "tag_name": tag.get_escape_name(), "tag_id": tag.key().id()},
                ),
            )

    for snippet in Snippet.all():
        str += """<url>
                    <loc>%s%s</loc>
                    <changefreq>monthly</changefreq>
                    <priority>0.5</priority>
                </url>
                """ % (
            settings.SITE_DOMAIN,
            snippet.get_absolute_url(),
        )

    str += "</urlset>"
    return HttpResponse(str, content_type="text/xml")
Ejemplo n.º 12
0
 def get_object(self, rs):
     if len(rs) != 2: raise ObjectDoesNotExist
     return (rs[0], Tag.get_by_id(int(rs[1])))
Ejemplo n.º 13
0
 def get_object(self, tags):
     if len(tags) != 1: raise ObjectDoesNotExist
     return Tag.get_by_id(int(tags[0]))
Ejemplo n.º 14
0
 def count_tags(self):
     for t in Tag.all():
         self.counts[t.key().id()] = self.count_tag(t)
     return self.counts