Author: sevein
Date: Wed Feb 16 09:22:09 2011
New Revision: 55

Log:
Add option to get a report of uniques by site_title.

Added:
   trunk/chk4upd/templatetags/get_related_objects_count.py   (contents, props 
changed)
   trunk/templates/report_uniques.html   (contents, props changed)
Modified:
   trunk/chk4upd/views.py
   trunk/templates/report.html

Added: trunk/chk4upd/templatetags/get_related_objects_count.py
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/chk4upd/templatetags/get_related_objects_count.py     Wed Feb 16 
09:22:09 2011        (r55)
@@ -0,0 +1,9 @@
+from django import template
+register = template.Library()
+
[email protected]('get_related_objects_count')
+def get_related_objects_count(value):
+
+  from qubitupdatecheck.chk4upd.models import Call
+
+  return Call.objects.filter(site_title=value).count()
\ No newline at end of file

Modified: trunk/chk4upd/views.py
==============================================================================
--- trunk/chk4upd/views.py      Mon Dec 20 13:50:45 2010        (r54)
+++ trunk/chk4upd/views.py      Wed Feb 16 09:22:09 2011        (r55)
@@ -59,7 +59,7 @@
 
   import datetime
 
-  objects = Call.objects.all().order_by('-created_at')
+  objects = Call.objects.all()
 
   # Filter by distribution (Default: "all")
   filter_distribution = request.POST.get('filter_distribution', 'all')
@@ -83,7 +83,14 @@
       httpmeta_remoteaddr = '99.199.102.26').exclude(
       created_at__lt = datetime.date(2010, 11, 19))             # Filter items 
before Nov. 19, 2010
 
-  paginator = Paginator(objects, 26)
+  if 'filter_unique' in request.POST:
+    filter_unique = True
+    uniques = objects.values_list('site_title', 
flat=True).distinct().order_by('site_title')
+    return render_to_response('report_uniques.html', locals(), 
RequestContext(request))
+
+  objects = objects.order_by('-created_at')
+
+  paginator = Paginator(objects, 25)
 
   try:
     objects = paginator.page(page)

Modified: trunk/templates/report.html
==============================================================================
--- trunk/templates/report.html Mon Dec 20 13:50:45 2010        (r54)
+++ trunk/templates/report.html Wed Feb 16 09:22:09 2011        (r55)
@@ -29,7 +29,7 @@
              $(this).removeClass('hover');
            });
 
-       $('select[name=filter_distribution], 
input[name=filter_staff]').change(function ()
+       $('[name^="filter_"]').change(function ()
          {
            $('form').submit();
          });
@@ -85,6 +85,9 @@
        
       <input type="checkbox" name="filter_staff" value="1"{% if filter_staff 
%} checked="checked"{% endif %} />
       <label for="filter_staff">Filter staff</label>
+      &nbsp;
+      <input type="checkbox" name="filter_unique" value="1"{% if filter_unique 
%} checked="checked"{% endif %} />
+      <label for="filter_unique">Filter repetitions</label>
     </form><br />
 
     <table id="report">

Added: trunk/templates/report_uniques.html
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/templates/report_uniques.html Wed Feb 16 09:22:09 2011        (r55)
@@ -0,0 +1,31 @@
+{% extends "base.html" %}
+
+{% load get_related_objects_count %}
+
+{% block title %}Report{% endblock %}
+{% block title_header %}Report{% endblock %}
+
+{% block content %}
+
+  {% if uniques %}
+
+    {{ uniques.count }} items - <a href="{% url chk4upd.views.report 
%}">Return</a>
+    
+    <br /><br />
+
+    <table id="report">
+      <tr>
+        <th>Site title</th>
+        <th>Count</th>
+      </tr>
+      {% for item in uniques %}
+        <tr class="{% cycle 'odd' 'even' %}">
+          <td>{{ item }}</td>
+          <td>{{ item|get_related_objects_count }}</td>
+        </tr>
+      {% endfor %}
+    </table>
+
+  {% endif %}
+
+{% endblock %}

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to