pull/91/head
eric 2018-02-07 18:34:05 -05:00
parent cb50e931bd
commit 6dbe9bdaeb
2 changed files with 8 additions and 4 deletions

View File

@ -77,7 +77,6 @@ class Processor(baseprocessor.Processor):
This Execute function debits the user credits and pledge and credits the recipient.
'''
def __init__(self, transaction=None):
print transaction
self.transaction = transaction
amount = transaction.amount
# make sure transaction hasn't already been executed

View File

@ -2,18 +2,23 @@ from django.core.management.base import BaseCommand
from django.contrib.auth.models import User
class Command(BaseCommand):
help = "grant (or debit or redeem) credit to a user"
help = "grant (or debit or redeem) credit to a user. \
Usage: grant_user_credit <username> <amount> <action>\
amount is dollars or 'all' "
args = "<username> <amount> <action>"
def handle(self, username, amount, action="credit", *args, **kwargs):
if action not in ("debit", "redeem", "credit"):
print 'action should be in ("debit", "redeem", "credit")'
return
user = User.objects.get(username=username)
if amount == 'all':
amount = user.credit.available
if action in ("debit", "redeem" ):
amount = -int(amount)
elif action == "credit":
amount = int(amount)
user = User.objects.get(username=username)
notify = action != "redeem"
user.credit.add_to_balance(amount, notify=notify)
print "%s now has a balance of %s credits" % (username, user.credit.balance)
print "{}ed ${} from {}".format(action, amount, username)
print "{} now has a balance of {} credits".format(username, user.credit.balance)