moved stats to own app, add template tags to it,
[wolnelektury.git] / apps / stats / views.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5
6 from django.db.models import Count
7 from django.shortcuts import render_to_response
8 from django.template import RequestContext
9
10 from catalogue.models import Book, BookMedia
11
12
13 def stats_page(request):
14     media = BookMedia.objects.count()
15     media_types = BookMedia.objects.values('type').\
16             annotate(count=Count('type')).\
17             order_by('type')
18     for mt in media_types:
19         mt['size'] = sum(b.file.size for b in BookMedia.objects.filter(type=mt['type']))
20         mt['deprecated'] = BookMedia.objects.filter(
21             type=mt['type'], source_sha1=None).count() if mt['type'] in ('mp3', 'ogg') else '-'
22
23     return render_to_response('stats/main.html',
24                 locals(), context_instance=RequestContext(request))