Merge branch 'master' from k.sfconservancy.org

This commit is contained in:
Bradley M. Kuhn 2017-08-01 09:20:19 -07:00
commit 77ac4ba16f
2 changed files with 14 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import argparse
import collections
import csv
import datetime
import functools
import os
import sys
@ -15,14 +16,12 @@ from supporters.models import Date, Payment, Supporter
MONTH_FMT = '%Y-%m'
def month_date(arg_s):
return Date.from_pydate(datetime.datetime.strptime(arg_s, MONTH_FMT))
def parse_arguments(arglist):
parser = argparse.ArgumentParser(
prog='status_report',
description="Print a CSV report counting Supporters over time",
)
month_date = functools.partial(Date.strptime, fmt=MONTH_FMT)
parser.add_argument(
'--start-month', type=month_date, metavar='YYYY-MM',
default=Payment.objects.order_by('date').first().date,

View file

@ -2,6 +2,7 @@
import datetime
import operator
import time
from django.db import models
@ -25,6 +26,11 @@ class Date(datetime.date):
def from_pydate(cls, date):
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):
if day is None:
day = self.day
@ -106,7 +112,12 @@ class Supporter:
return expose_wrapper
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)
def _calculate_lapse_date(self, last_payment_date, supporter_type):