-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
33 lines (29 loc) · 909 Bytes
/
helpers.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
28
29
30
31
32
33
from models import db
import dateutil.parser
import babel
#----------------------------------------------------------------------------#
# Helpers.
#----------------------------------------------------------------------------#
def safe_commit():
status = False
try:
db.session.commit()
status = True
except Exception as e:
db.session.rollback()
print('APP Exception')
print(e)
finally:
db.session.close()
return status
#----------------------------------------------------------------------------#
# Filters.
#----------------------------------------------------------------------------#
def format_datetime(value, format='medium'):
value = str(value)
date = dateutil.parser.parse(value)
if format == 'full':
format="EEEE MMMM, d, y 'at' h:mma"
elif format == 'medium':
format="EE MM, dd, y h:mma"
return babel.dates.format_datetime(date, format)