counters stub
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 4 Aug 2011 15:07:17 +0000 (17:07 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 4 Aug 2011 15:07:17 +0000 (17:07 +0200)
apps/catalogue/urls.py
apps/catalogue/views.py
wolnelektury/templates/catalogue/counters.html [new file with mode: 0755]

index cc97e92..e864cdb 100644 (file)
@@ -25,6 +25,7 @@ urlpatterns = patterns('catalogue.views',
     # tools
     url(r'^zegar/$', 'clock', name='clock'),
     url(r'^xmls.zip$', 'xmls', name='xmls'),
     # 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'),
 
     # Public interface. Do not change this URLs.
     url(r'^lektura/(?P<slug>[a-zA-Z0-9-]+)\.html$', 'book_text', name='book_text'),
index aa77f4b..ac778d4 100644 (file)
@@ -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.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
 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')
 
 
                      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:])
 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 (executable)
index 0000000..572583c
--- /dev/null
@@ -0,0 +1,21 @@
+{% 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 %}