X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/069d8476540f79fb4c37ccd219d6b794656baf0d..c3b9c1f48873577c3a29f9c67e35a98d0a84330e:/apps/catalogue/views.py diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index aa77f4b59..f585aeaa1 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -17,7 +17,7 @@ from django.template import RequestContext from django.shortcuts import render_to_response, get_object_or_404 from django.http import HttpResponse, HttpResponseRedirect, Http404, HttpResponsePermanentRedirect from django.core.urlresolvers import reverse -from django.db.models import Q +from django.db.models import Count, Sum, Q from django.contrib.auth.decorators import login_required, user_passes_test from django.utils.datastructures import SortedDict from django.views.decorators.http import require_POST @@ -128,6 +128,27 @@ def daisy_list(request): template_name='catalogue/daisy_list.html') +def counters(request): + form = forms.SearchForm() + + books = models.Book.objects.count() + books_nonempty = models.Book.objects.exclude(html_file='').count() + books_empty = models.Book.objects.filter(html_file='').count() + books_root = models.Book.objects.filter(parent=None).count() + + media = models.BookMedia.objects.count() + media_types = models.BookMedia.objects.values('type').\ + annotate(count=Count('type')).\ + order_by('type') + for mt in media_types: + mt['size'] = sum(b.file.size for b in models.BookMedia.objects.filter(type=mt['type'])) + mt['deprecated'] = models.BookMedia.objects.filter( + type=mt['type'], source_sha1=None).count() if mt['type'] in ('mp3', 'ogg') else '-' + + return render_to_response('catalogue/counters.html', + locals(), context_instance=RequestContext(request)) + + def differentiate_tags(request, tags, ambiguous_slugs): beginning = '/'.join(tag.url_chunk for tag in tags) unparsed = '/'.join(ambiguous_slugs[1:]) @@ -277,6 +298,18 @@ def book_detail(request, slug): extra_info = book.get_extra_info_value() + projects = set() + for m in book.media.filter(type='mp3'): + # ogg files are always from the same project + meta = m.get_extra_info_value() + project = meta.get('project') + if not project: + # temporary fallback + project = u'CzytamySłuchając' + + projects.add((project, meta.get('funded_by'))) + projects = sorted(projects) + form = forms.SearchForm() return render_to_response('catalogue/book_detail.html', locals(), context_instance=RequestContext(request))