comparison donations/management/commands/top_donors.py @ 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
children
comparison
equal deleted inserted replaced
760:630ecac7665f 761:1ddd72f48d73
1 """top_donors.py
2
3 A management command to display top donor data.
4
5 """
6 from optparse import make_option
7
8 from django.core.management.base import BaseCommand
9
10 from donations.models import Donation
11
12
13 ROW_FMT = '{n:<5} {name:<32} ${amount}\n'
14
15
16 class Command(BaseCommand):
17 help = "Display the top N donors and stats"
18 args = "<n>"
19 option_list = BaseCommand.option_list + (
20 make_option('-n', '--number',
21 action='store',
22 type='int',
23 default=10,
24 help='number of donors to display'),
25 )
26
27 def handle(self, *args, **kwargs):
28 """Display the top n donors and their amounts."""
29
30 n = kwargs['number']
31
32 donors = Donation.objects.top_donors(n)
33 for i, donor in enumerate(donors, start=1):
34 self.stdout.write(ROW_FMT.format(n=i, name=donor.username,
35 amount=donor.total_donations))