Merge branch 'master' from k.sfconservancy.org
This commit is contained in:
		
						commit
						77ac4ba16f
					
				
					 2 changed files with 14 additions and 4 deletions
				
			
		| 
						 | 
					@ -4,6 +4,7 @@ import argparse
 | 
				
			||||||
import collections
 | 
					import collections
 | 
				
			||||||
import csv
 | 
					import csv
 | 
				
			||||||
import datetime
 | 
					import datetime
 | 
				
			||||||
 | 
					import functools
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,14 +16,12 @@ from supporters.models import Date, Payment, Supporter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MONTH_FMT = '%Y-%m'
 | 
					MONTH_FMT = '%Y-%m'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def month_date(arg_s):
 | 
					 | 
				
			||||||
    return Date.from_pydate(datetime.datetime.strptime(arg_s, MONTH_FMT))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def parse_arguments(arglist):
 | 
					def parse_arguments(arglist):
 | 
				
			||||||
    parser = argparse.ArgumentParser(
 | 
					    parser = argparse.ArgumentParser(
 | 
				
			||||||
        prog='status_report',
 | 
					        prog='status_report',
 | 
				
			||||||
        description="Print a CSV report counting Supporters over time",
 | 
					        description="Print a CSV report counting Supporters over time",
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					    month_date = functools.partial(Date.strptime, fmt=MONTH_FMT)
 | 
				
			||||||
    parser.add_argument(
 | 
					    parser.add_argument(
 | 
				
			||||||
        '--start-month', type=month_date, metavar='YYYY-MM',
 | 
					        '--start-month', type=month_date, metavar='YYYY-MM',
 | 
				
			||||||
        default=Payment.objects.order_by('date').first().date,
 | 
					        default=Payment.objects.order_by('date').first().date,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import datetime
 | 
					import datetime
 | 
				
			||||||
import operator
 | 
					import operator
 | 
				
			||||||
 | 
					import time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from django.db import models
 | 
					from django.db import models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,6 +26,11 @@ class Date(datetime.date):
 | 
				
			||||||
    def from_pydate(cls, date):
 | 
					    def from_pydate(cls, date):
 | 
				
			||||||
        return cls(date.year, date.month, date.day)
 | 
					        return cls(date.year, date.month, date.day)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @classmethod
 | 
				
			||||||
 | 
					    def strptime(cls, s, fmt):
 | 
				
			||||||
 | 
					        time_tuple = time.strptime(s, fmt)
 | 
				
			||||||
 | 
					        return cls(*time_tuple[:3])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def adjust_month(self, delta, day=None):
 | 
					    def adjust_month(self, delta, day=None):
 | 
				
			||||||
        if day is None:
 | 
					        if day is None:
 | 
				
			||||||
            day = self.day
 | 
					            day = self.day
 | 
				
			||||||
| 
						 | 
					@ -106,7 +112,12 @@ class Supporter:
 | 
				
			||||||
        return expose_wrapper
 | 
					        return expose_wrapper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _supporter_type(self, payments):
 | 
					    def _supporter_type(self, payments):
 | 
				
			||||||
        return payments.last().program.rsplit(':', 1)[-1]
 | 
					        try:
 | 
				
			||||||
 | 
					            program = payments.filter(program__isnull=False).reverse()[0].program
 | 
				
			||||||
 | 
					        except IndexError:
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return program.rsplit(':', 1)[-1]
 | 
				
			||||||
    supporter_type = _expose(_supporter_type)
 | 
					    supporter_type = _expose(_supporter_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _calculate_lapse_date(self, last_payment_date, supporter_type):
 | 
					    def _calculate_lapse_date(self, last_payment_date, supporter_type):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue