Mercurial > public > sg101
view donations/management/commands/top_donors.py @ 989:2908859c2fe4
Smilies now use relative links.
This is for upcoming switch to SSL. Currently we do not need absolute URLs for
smilies. If this changes we can add it later.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 29 Oct 2015 20:54:34 -0500 |
parents | 1ddd72f48d73 |
children |
line wrap: on
line source
"""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))