Beispiel #1
0
def website_links(request, website_id):
    website = get_object_or_404(m.Website, id=website_id)
    page_num = request.GET.get("page", 1)
    page_num = int(page_num)

    # make sure we support the order
    order = request.GET.get("order", "pages")
    direction = request.GET.get("direction", "desc")
    other_direction = "asc" if direction == "desc" else "desc"

    if order == "target" and direction == "asc":
        sort_order = "target"
    elif order == "target" and direction == "desc":
        sort_order = "-target"
    elif order == "pages" and direction == "asc":
        sort_order = "wikipedia_page__count"
    else:
        sort_order = "-wikipedia_page__count"

    links = m.Link.objects.filter(website=website)
    links = links.values("target")
    links = links.annotate(Count("wikipedia_page"))
    links = links.order_by(sort_order)

    paginator = DiggPaginator(links, 100)
    page = paginator.page(page_num)
    links = page.object_list

    tab = "links"
    title = "website: %s" % website.url

    return render_to_response("website_links.html", dictionary=locals())
Beispiel #2
0
def website_pages(request, website_id):
    website = get_object_or_404(m.Website, id=website_id)

    page_num = request.GET.get("page", 1)
    page_num = int(page_num)

    # make sure we support the order
    order = request.GET.get("order", "update")
    direction = request.GET.get("direction", "desc")
    other_direction = "asc" if direction == "desc" else "desc"

    if order == "update" and direction == "asc":
        sort_order = "last_modified"
    elif order == "update" and direction == "desc":
        sort_order = "-last_modified"
    elif order == "links" and direction == "asc":
        sort_order = "links__count"
    else:
        sort_order = "-links__count"

    wikipedia_pages = m.WikipediaPage.objects.filter(links__website=website)
    wikipedia_pages = wikipedia_pages.annotate(Count("links"))
    wikipedia_pages = wikipedia_pages.order_by(sort_order)
    wikipedia_pages = wikipedia_pages.distinct()

    paginator = DiggPaginator(wikipedia_pages, 100)
    page = paginator.page(page_num)
    wikipedia_pages = page.object_list

    tab = "pages"
    tab_summary = "wikipedia pages %s" % website.name
    title = "website: %s" % website.url

    return render_to_response("website_pages.html", dictionary=locals())
Beispiel #3
0
def website_categories(request, website_id, page_num=1):
    website = get_object_or_404(m.Website, id=website_id)
    categories = website.categories().order_by("-pages__count")
    paginator = DiggPaginator(categories, 100)
    page = paginator.page(int(page_num))
    categories = page.object_list
    tab = "categories"
    tab_summary = "Categories for %s" % website.name
    title = "website: %s" % website.url
    return render_to_response("website_categories.html", dictionary=locals())
Beispiel #4
0
def website_pages(request, website_id):
    website = get_object_or_404(m.Website, id=website_id)

    page_num = request.GET.get("page", 1)
    page_num = int(page_num)

    # make sure we support the order
    order = request.GET.get("order", "links")
    direction = request.GET.get("direction", "desc")
    other_direction = "asc" if direction == "desc" else "desc"

    if order == "update" and direction == "asc":
        sort_order = "links__created__max"
    elif order == "update" and direction == "desc":
        sort_order = "-links__created__max"
    elif order == "views" and direction == "desc":
        sort_order = "-views"
    elif order == "views" and direction == "asc":
        sort_order = "views"
    elif order == "links" and direction == "asc":
        sort_order = "links__count"
    else:
        sort_order = "-links__count"

    wikipedia_pages = m.WikipediaPage.objects.filter(links__website=website)
    wikipedia_pages = wikipedia_pages.annotate(Count("links"))
    wikipedia_pages = wikipedia_pages.annotate(Max("links__created"))
    wikipedia_pages = wikipedia_pages.order_by(sort_order)
    wikipedia_pages = wikipedia_pages.distinct()

    paginator = DiggPaginator(wikipedia_pages, 100)
    page = paginator.page(page_num)
    wikipedia_pages = page.object_list

    tab = "pages"
    tab_summary = "wikipedia pages %s" % website.name
    title = "website: %s" % website.url
    stats_date = time.strftime("%Y%m")

    if request.GET.get("format") == "json":
        data = []
        for page in wikipedia_pages:
            data.append({"url": page.url, "title": page.title, "views": page.views, "links": page.links__count})
        return HttpResponse(json.dumps(data, indent=2), mimetype="application/json")

    return render_to_response("website_pages.html", dictionary=locals())