Source

django-spotnet / spotnet / stats / views.py

Full commit
from django.utils.translation import ugettext as _
try:
    from django.shortcuts import render
except ImportError:
    # for django==1.2 compatibility
    from django.shortcuts import render_to_response
    from django.template import RequestContext
    def render(request, template, context):
        return render_to_response(
            template,
            context,
            context_instance=RequestContext(request),
        )

from django.db.models import Sum
from functions import posts_per_day, posts_per_category, spotnet_table_filesize
from spotnet.models import Post


def index(request):
    return render(
        request,
        'spotnet_stats/index.html', 
        {},
    )


def general(request):
    return render(
        request,
        'spotnet_stats/general.html',
        dict(
            total_posts = Post.objects.count(),
            category_posts = posts_per_category(),
            table_filesize = spotnet_table_filesize(),
            total_filesize = Post.objects.aggregate(s=Sum('size'))['s'],
            first_post = Post.objects.order_by('posted').only('posted')[0].posted,
            last_post = Post.objects.order_by('-posted').only('posted')[0].posted,
        ),
    )

def daily_posts(request):
    postings, date_start, date_end, total_posts, dayspan = posts_per_day()
    return render(
        request,
        'spotnet_stats/daily_posts.html',
        dict(
            postings = postings,
            postings_list = '[%s]' % ','.join(str(x) for x in postings),
            total_posts = total_posts,

            date_start = date_start,
            date_end = date_end,
            dayspan = dayspan,
        ),
    )