From: Radek Czajka Date: Thu, 4 Aug 2011 15:07:17 +0000 (+0200) Subject: counters stub X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/34ab7bebbd8dd9f8e7018b7d8dba10d7db1afd41?ds=sidebyside;hp=85e4c2bbb02c7a8526cf391ecfdc05c01c22f88e counters stub --- diff --git a/apps/catalogue/urls.py b/apps/catalogue/urls.py index cc97e9209..e864cdba3 100644 --- a/apps/catalogue/urls.py +++ b/apps/catalogue/urls.py @@ -25,6 +25,7 @@ urlpatterns = patterns('catalogue.views', # tools url(r'^zegar/$', 'clock', name='clock'), url(r'^xmls.zip$', 'xmls', name='xmls'), + url(r'^liczniki/$', 'counters', name='catalogue_counters'), # Public interface. Do not change this URLs. url(r'^lektura/(?P[a-zA-Z0-9-]+)\.html$', 'book_text', name='book_text'), diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index aa77f4b59..ac778d4a7 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,23 @@ def daisy_list(request): template_name='catalogue/daisy_list.html') +def counters(request): + 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'])) + + 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:]) diff --git a/wolnelektury/templates/catalogue/counters.html b/wolnelektury/templates/catalogue/counters.html new file mode 100755 index 000000000..572583c65 --- /dev/null +++ b/wolnelektury/templates/catalogue/counters.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% load i18n %} + +{% block title %}Liczniki w WolneLektury.pl{% endblock %} + +{% block bodyid %}tagged-object-list{% endblock %} + +{% block body %} +

Liczniki

+ + + + + + + {% for mt in media_types %} + + {% endfor %} +
Wszystkie utwory:{{ books }}
Utwory z własną treścią:{{ books_nonempty }}
Utwory bez własnej treści:{{ books_empty }}
Niezależne książki:{{ books_root }}
Media – {{ mt.type }}:{{ mt.count }}, {{ mt.size|filesizeformat }}
+ +{% endblock %}