-
Notifications
You must be signed in to change notification settings - Fork 21
/
models.py
27 lines (22 loc) · 890 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from datetime import datetime
from functools import wraps
from timeless import DB
class TimestampsMixin:
"""Mixin for adding created_on and updated_on attributes
to any models that need to keep track of their updates.
"""
created_on = DB.Column(DB.DateTime, default=datetime.utcnow,
nullable=False)
updated_on = DB.Column(DB.DateTime, default=datetime.utcnow,
onupdate=datetime.utcnow, nullable=False)
def validate_required(*expected_args):
""" Validate input params as mandatory """
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
for arg in expected_args:
if arg not in kwargs:
raise KeyError("Missing required param: {}".format(arg))
return func(*args, **kwargs)
return wrapper
return decorator