changeset 761:1ddd72f48d73

Added mgmt command to display donor info. Hall of fame donors bumped to 20.
author Brian Neal <bgneal@gmail.com>
date Sat, 11 Jan 2014 19:43:37 -0600
parents 630ecac7665f
children 840f2579ef1c
files donations/management/commands/top_donors.py sg101/templates/donations/index.html
diffstat 2 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/donations/management/commands/top_donors.py	Sat Jan 11 19:43:37 2014 -0600
@@ -0,0 +1,35 @@
+"""top_donors.py
+
+A management command to display top donor data.
+
+"""
+from optparse import make_option
+
+from django.core.management.base import BaseCommand
+
+from donations.models import Donation
+
+
+ROW_FMT = '{n:<5} {name:<32} ${amount}\n'
+
+
+class Command(BaseCommand):
+    help = "Display the top N donors and stats"
+    args = "<n>"
+    option_list = BaseCommand.option_list + (
+            make_option('-n', '--number',
+                        action='store',
+                        type='int',
+                        default=10,
+                        help='number of donors to display'),
+            )
+
+    def handle(self, *args, **kwargs):
+        """Display the top n donors and their amounts."""
+
+        n = kwargs['number']
+
+        donors = Donation.objects.top_donors(n)
+        for i, donor in enumerate(donors, start=1):
+            self.stdout.write(ROW_FMT.format(n=i, name=donor.username,
+                amount=donor.total_donations))
--- a/sg101/templates/donations/index.html	Sat Jan 11 16:11:50 2014 -0600
+++ b/sg101/templates/donations/index.html	Sat Jan 11 19:43:37 2014 -0600
@@ -106,7 +106,7 @@
 <div class="span-9 last">
 <h3>Hall of Fame Donors</h3>
 {% cache 3600 top_donors_tag %}
-   {% top_donors 10 %}
+   {% top_donors 20 %}
 {% endcache %}
 </div>