Merge branch 'master' of github.com:Gluejar/regluit
commit
6a6ee190e4
|
@ -10,7 +10,7 @@ from decimal import Decimal as D
|
||||||
|
|
||||||
from regluit.experimental.gutenberg import unicode_csv
|
from regluit.experimental.gutenberg import unicode_csv
|
||||||
|
|
||||||
def amazon_payments(fname=r"/Users/raymondyee/Downloads/All-Activity-With-Balance-Jan-01-2012-Jul-02-2012.csv"):
|
def amazon_payments(fname=r"/Users/raymondyee/Downloads/All-Activity-Jan-01-2012-Jul-17-2012.csv"):
|
||||||
r0 = unicode_csv.UnicodeReader(f=open(fname), encoding="iso-8859-1")
|
r0 = unicode_csv.UnicodeReader(f=open(fname), encoding="iso-8859-1")
|
||||||
# grab the header
|
# grab the header
|
||||||
header = r0.next()
|
header = r0.next()
|
||||||
|
@ -63,31 +63,32 @@ def transactions_with_payment_info(transactions, payments=None):
|
||||||
|
|
||||||
def stats_for_campaign(c):
|
def stats_for_campaign(c):
|
||||||
print "transactions by statuses", c.transaction_set.values('status').annotate(count_status=Count('status'))
|
print "transactions by statuses", c.transaction_set.values('status').annotate(count_status=Count('status'))
|
||||||
|
|
||||||
# total amount -- aggregate transactions that are Complete, Active, Pending, Error, Failed
|
# distinguish among campaigns that are Active, Successful, or Closed
|
||||||
valid_trans = c.transaction_set.filter(Q(status='Complete') | Q(status='Active') | Q(status='Pending') | Q(status='Error') | Q(status='Failed') )
|
if c.status == 'ACTIVE':
|
||||||
|
# nothing collected yet -- can tally all Active transactions for a total
|
||||||
print "total amount for valid transactions", valid_trans.aggregate(Sum('amount'))['amount__sum']
|
valid_trans = c.transaction_set.filter(Q(status='Complete') | Q(status='Active') | Q(status='Pending') | Q(status='Error') | Q(status='Failed') )
|
||||||
print "maximum amount for valid transactions", valid_trans.aggregate(Max('amount'))['amount__max']
|
total_amount = c.transaction_set.filter(Q(status='Active')).aggregate(Sum('amount'))['amount__sum']
|
||||||
print
|
print "expected amount for active campaign", total_amount
|
||||||
|
elif c.status == 'SUCCESSFUL':
|
||||||
|
# how to not double count transactions wih Error or Failed status that have an Active or Completed followup?
|
||||||
|
valid_trans = c.transaction_set.filter(Q(status='Complete') | Q(status='Active') )
|
||||||
|
uid_ok_trans = set([x[0] for x in c.transaction_set.filter(Q(status='Complete') | Q(status='Active')).values_list('user')])
|
||||||
|
cleared_amount = c.transaction_set.filter(Q(status='Complete')).aggregate(Sum('amount'))['amount__sum']
|
||||||
|
failed_errored_amount = sum([t.amount for t in c.transaction_set.filter(Q(status='Pending') | Q(status='Error') | Q(status='Failed') ) if t.user.id not in uid_ok_trans])
|
||||||
|
print "cleared amount for Successful campaign", cleared_amount
|
||||||
|
print "failed_errored_amount for Successful campaign", failed_errored_amount
|
||||||
|
elif c.status == 'CLOSED':
|
||||||
|
valid_trans = c.transaction_set.filter(Q(status='Complete'))
|
||||||
|
total_amount = c.transaction_set.filter(Q(status='Complete')).aggregate(Sum('amount'))['amount__sum']
|
||||||
|
print "total amount for Closed campaign", total_amount
|
||||||
|
else:
|
||||||
|
valid_trans = c.transaction_set.filter(Q(status='Complete') | Q(status='Active') | Q(status='Pending') | Q(status='Error') | Q(status='Failed') )
|
||||||
|
|
||||||
# distribution?
|
# distribution?
|
||||||
clusters = valid_trans.values('amount').annotate(count_amount=Count('amount')).order_by('-amount')
|
clusters = valid_trans.values('amount').annotate(count_amount=Count('amount')).order_by('-amount')
|
||||||
for t in clusters:
|
for t in clusters:
|
||||||
print "{0}\t{1}\t{2}".format(t['amount'], t['count_amount'], t['count_amount']*t['amount'])
|
print "{0}\t{1}\t{2}".format(t['amount'], t['count_amount'], t['count_amount']*t['amount'])
|
||||||
#print [(t['amount'], t['count_amount']*t['amount']) for t in clusters]
|
|
||||||
|
|
||||||
# calculate the problematic pledges
|
|
||||||
problem_trans = c.transaction_set.filter(Q(status='Pending') | Q(status='Error') | Q(status='Failed'))
|
|
||||||
|
|
||||||
# first list all the problem pledges
|
|
||||||
for (i, t) in enumerate(problem_trans):
|
|
||||||
print i, t.user, t.amount, t.status, t.local_status, t.preapproval_key, t.approved, t.error
|
|
||||||
|
|
||||||
# let's consider the Error ones first
|
|
||||||
|
|
||||||
# donors sorted by donation and time
|
|
||||||
# top 10
|
|
||||||
|
|
||||||
c_users = set([u[0] for u in c.transaction_set.values_list('user__username')])
|
c_users = set([u[0] for u in c.transaction_set.values_list('user__username')])
|
||||||
|
|
||||||
|
@ -111,6 +112,7 @@ def stats_for_campaign(c):
|
||||||
# tally up different classes of statuses we have for c
|
# tally up different classes of statuses we have for c
|
||||||
|
|
||||||
# who has modified a transaction and never cancelled it?
|
# who has modified a transaction and never cancelled it?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -131,9 +133,10 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# breakdown of Transactions by status
|
# breakdown of Transactions by status
|
||||||
print "transactions by status", Transaction.objects.values('status').annotate(count_status=Count('status'))
|
print "transactions by status", Transaction.objects.values('status').annotate(count_status=Count('status'))
|
||||||
|
print
|
||||||
|
|
||||||
# distribution of donations for *Oral Literature*
|
# distribution of donations for *Oral Literature*
|
||||||
print "stats for Oral Literature in Africa"
|
print "stats for *Oral Literature in Africa*"
|
||||||
|
|
||||||
c3 = Campaign.objects.get(id=3)
|
c3 = Campaign.objects.get(id=3)
|
||||||
stats_for_campaign(c3)
|
stats_for_campaign(c3)
|
||||||
|
|
|
@ -882,8 +882,8 @@ class LibraryThingTest(TestCase):
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
|
||||||
#testcases = [WorkMapperTest,FreebaseBooksTest, OpenLibraryTest,GoogleBooksTest]
|
testcases = [WorkMapperTest,FreebaseBooksTest, OpenLibraryTest,GoogleBooksTest, LibraryThingTest]
|
||||||
testcases = []
|
#testcases = []
|
||||||
suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases])
|
suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases])
|
||||||
suites.addTest(LibraryThingTest('test_cache'))
|
suites.addTest(LibraryThingTest('test_cache'))
|
||||||
#suites.addTest(SettingsTest('test_dev_me_alignment')) # give option to test this alignment
|
#suites.addTest(SettingsTest('test_dev_me_alignment')) # give option to test this alignment
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
{% extends "basepledge.html" %}
|
||||||
|
{% load humanize %}
|
||||||
|
|
||||||
|
{% block title %}Pledge Recharge{% endblock %}
|
||||||
|
|
||||||
|
{% block extra_extra_head %}
|
||||||
|
<link type="text/css" rel="stylesheet" href="/static/css/campaign.css" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block doccontent %}
|
||||||
|
|
||||||
|
{% if error %}
|
||||||
|
{{error}}
|
||||||
|
{% else %}
|
||||||
|
{% if transaction %}
|
||||||
|
<div>Thank you for pledging ${{ transaction.amount|intcomma}} to the campaign for <a href="{% url work work.id %}">{{ work.title }}</a>.
|
||||||
|
The attempt to collect your payment was unsucessful.<br> <br>
|
||||||
|
Please authorize another attempt to collect your pledge of ${{ transaction.amount|intcomma }}
|
||||||
|
by clicking on the following link:
|
||||||
|
<a href="{{recharge_url|safe}}">Authorize recharge via {{payment_processor}} payments</a>.</div>
|
||||||
|
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<div>You do not currently need to authorize another payment for the successful campaign for <a href="{% url work work.id %}">{{ work.title }}</a>. </div>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -663,13 +663,11 @@ class PledgeView(FormView):
|
||||||
return_url=return_url, nevermind_url=nevermind_url, anonymous=anonymous, premium=premium)
|
return_url=return_url, nevermind_url=nevermind_url, anonymous=anonymous, premium=premium)
|
||||||
|
|
||||||
if url:
|
if url:
|
||||||
logger.info("PledgeView paypal: " + url)
|
logger.info("PledgeView url: " + url)
|
||||||
print >> sys.stderr, "PledgeView paypal: ", url
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
else:
|
else:
|
||||||
response = t.reference
|
logger.error("Attempt to produce transaction id {0} failed".format(t.id))
|
||||||
logger.info("PledgeView paypal: Error " + str(t.reference))
|
return HttpResponse("Our attempt to enable your transaction failed. We have logged this error.")
|
||||||
return HttpResponse(response)
|
|
||||||
|
|
||||||
class PledgeModifyView(FormView):
|
class PledgeModifyView(FormView):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue