# 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<slug>[a-zA-Z0-9-]+)\.html$', 'book_text', name='book_text'),
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
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:])
--- /dev/null
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block title %}Liczniki w WolneLektury.pl{% endblock %}
+
+{% block bodyid %}tagged-object-list{% endblock %}
+
+{% block body %}
+ <h1>Liczniki</h1>
+
+ <table>
+ <tr><td>Wszystkie utwory:</td><td>{{ books }}</td></tr>
+ <tr><td>Utwory z własną treścią:</td><td>{{ books_nonempty }}</td></tr>
+ <tr><td>Utwory bez własnej treści:</td><td>{{ books_empty }}</td></tr>
+ <tr><td>Niezależne książki:</td><td>{{ books_root }}</td></tr>
+ {% for mt in media_types %}
+ <tr><td>Media – {{ mt.type }}:</td><td>{{ mt.count }}, {{ mt.size|filesizeformat }}</td></tr>
+ {% endfor %}
+ </table>
+
+{% endblock %}