annotate donations/management/commands/top_donors.py @ 821:71db8076dc3d

Bandmap WIP: geocoding integrated with add form. Add form works. Before submitting the form, client side JS makes a geocode request to Google and populates hidden lat/lon fields with the result. Successfully created a model instance on the server side. Still need to update admin dashboard, admin approval, and give out badges for adding bands to the map. Once that is done, then work on displaying the map with filtering.
author Brian Neal <bgneal@gmail.com>
date Tue, 23 Sep 2014 20:40:31 -0500
parents 1ddd72f48d73
children
rev   line source
bgneal@761 1 """top_donors.py
bgneal@761 2
bgneal@761 3 A management command to display top donor data.
bgneal@761 4
bgneal@761 5 """
bgneal@761 6 from optparse import make_option
bgneal@761 7
bgneal@761 8 from django.core.management.base import BaseCommand
bgneal@761 9
bgneal@761 10 from donations.models import Donation
bgneal@761 11
bgneal@761 12
bgneal@761 13 ROW_FMT = '{n:<5} {name:<32} ${amount}\n'
bgneal@761 14
bgneal@761 15
bgneal@761 16 class Command(BaseCommand):
bgneal@761 17 help = "Display the top N donors and stats"
bgneal@761 18 args = "<n>"
bgneal@761 19 option_list = BaseCommand.option_list + (
bgneal@761 20 make_option('-n', '--number',
bgneal@761 21 action='store',
bgneal@761 22 type='int',
bgneal@761 23 default=10,
bgneal@761 24 help='number of donors to display'),
bgneal@761 25 )
bgneal@761 26
bgneal@761 27 def handle(self, *args, **kwargs):
bgneal@761 28 """Display the top n donors and their amounts."""
bgneal@761 29
bgneal@761 30 n = kwargs['number']
bgneal@761 31
bgneal@761 32 donors = Donation.objects.top_donors(n)
bgneal@761 33 for i, donor in enumerate(donors, start=1):
bgneal@761 34 self.stdout.write(ROW_FMT.format(n=i, name=donor.username,
bgneal@761 35 amount=donor.total_donations))