generated from Code-Institute-Org/gitpod-full-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.py
50 lines (39 loc) · 1.25 KB
/
run.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
import os
from flask import render_template, session
from app import create_app
from app.models.user import User
from app.models.notifications import Notification
app = create_app()
# Frequently asked question page
# https://flask.palletsprojects.com/en/1.1.x/patterns/errorpages/
# https://flask.palletsprojects.com/en/2.0.x/errorhandling/
@app.errorhandler(404)
def page_not_found(e):
"""
Render page 404
"""
return render_template('404.html'), 404
@app.errorhandler(500)
def internal_server_error(e):
"""
Render error page 500
"""
return render_template('500.html'), 500
@app.context_processor
def new_notifications():
"""
Set variable to use across all templates to count new notifications
"""
if "email" in session:
user = User.check_existing_user(session["email"].lower())
notifications = list(Notification.get_notifications_for_user(
user["_id"]))
read = list(Notification.get_read_notification(user["_id"]))
new = len(notifications) - len(read)
return dict(new=str(new))
else:
return dict(new="")
if __name__ == "__main__":
app.run(host=os.environ.get("IP"),
port=int(os.environ.get("PORT")),
debug=False)