-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (54 loc) · 1.91 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from flask import Flask, redirect, url_for
from routes.authenticated.views import authenticated
from routes.unauthenticated.views import unauthenticated
from routes.webhook.views import webhook
from routes.ajax.views import ajax
from routes.api.views import api
import base64
from datetime import datetime
app = Flask(__name__)
app.config['SECRET_KEY'] = 'change me'
app.register_blueprint(unauthenticated)
app.register_blueprint(authenticated)
app.register_blueprint(webhook)
app.register_blueprint(ajax)
app.register_blueprint(api)
# JINJA2 : Decodes base64
def decode_base64(string):
if isinstance(string, str):
string = string.decode('utf-8').strip()
return base64.b64decode(string)
def int_to_minhour(minutes):
if isinstance(minutes, int):
return '{:02d}:{:02d}'.format(*divmod(minutes, 60))
else:
return '00:00'
def create_initials(full_name):
if isinstance(full_name, str):
print full_name
names = full_name.split(" ")
return names[0][0].upper()+names[1][0].upper()
def check_late(date):
today = datetime.today().date()
check = datetime.strptime(date, '%d/%m/%Y').date()
return check < today
def format_date(date):
return datetime.strftime(date, '%H:%M %d/%m/%Y')
app.jinja_env.filters['decodeb64'] = decode_base64
app.jinja_env.filters['int_to_minhour'] = int_to_minhour
app.jinja_env.filters['create_initials'] = create_initials
app.jinja_env.filters['check_late'] = check_late
app.jinja_env.filters['format_date'] = format_date
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
if __name__ == '__main__':
app.run()
@app.errorhandler(404)
def page_not_found(e):
return redirect(url_for('unauthenticated.not_found_page'))
@app.errorhandler(403)
def forbidden(e):
return redirect(url_for('unauthenticated.forbidden_page'))
@app.errorhandler(401)
def unauthorised(e):
return redirect(url_for('unauthenticated.login_page'))