This commit is contained in:
2019-10-30 14:45:02 +01:00
commit 892c80861c
10 changed files with 628 additions and 0 deletions

34
helpers.py Normal file
View File

@@ -0,0 +1,34 @@
import datetime as dt
import dateparser as dp
from sqlalchemy import Column, Integer, desc
from app.database import SessionLocal
class Invalid(Exception):
pass
def parse_date_string(date_string) -> dt.date:
try:
return dp.parse(date_string).date()
except Exception:
raise Invalid
class BaseMixIn:
id = Column(Integer, primary_key=True, index=True)
__mapper_args__ = {"order_by": desc("id")}
def __init__(self, **kwargs):
super(BaseMixIn, self).__init__(**kwargs)
self.when = dt.datetime.now()
@classmethod
def delete_most_recent(cls):
db = SessionLocal()
db.delete(db.query(cls).first())
db.commit()