Add months_due public api.

master
q3k 2013-08-07 14:50:09 +02:00
parent 98c8d83855
commit ce5c9fb296
2 changed files with 26 additions and 0 deletions

View File

@ -38,6 +38,19 @@ class Member(db.Model):
active = db.Column(db.Boolean)
api_keys = db.relationship("APIKey")
def get_last_paid(self):
year, month, oldest = 0, 0, 0
for mt in self.transfers:
age = mt.year * 12 + (mt.month - 1)
if age > oldest:
oldest = age
year = mt.year
month = mt.month
if year == 0:
return None, None
else:
return year, month
def get_next_unpaid(self):
year, month, oldest = 0, 0, 0
for mt in self.transfers:

View File

@ -88,6 +88,19 @@ def manamana(year=None, month=None):
now = datetime.datetime.now()
return api_month(year=now.year, month=now.month)
@api_method("/months_due/<membername>", private=False)
def api_months_due(membername):
member = models.Member.query.filter_by(username=membername).first()
if not member:
return False
year, month = member.get_last_paid()
if not year:
return False
now = datetime.datetime.now()
then_timestamp = year * 12 + (month-1)
now_timestamp = now.year * 12 + (now.month-1)
return now_timestamp - then_timestamp
@app.route("/login", methods=["POST", "GET"])
def login():