-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
70 lines (57 loc) · 2.42 KB
/
app.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
import os
import datetime
import hashlib
import sys
from friend import Friend
from database import addFriend, getFriend, getFriendFromID, birthdays
from flask import Flask, session, url_for, redirect, render_template, request, abort, flash, jsonify
from werkzeug.utils import secure_filename
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
app.config.from_object('config')
@app.route("/")
def root():
return(redirect(url_for("load_dashboard")))
@app.route("/friend_info,<id>")
def friend_info(id):
i = getFriendFromID()
friend = i.returnOne(id)
return render_template('friend_info.html', friend=friend)
# @app.route("/friend_info")
# def friend_info():
# return render_template('friend_info.html')
@app.route("/add_friend", methods=['GET', 'POST'])
def add_friend():
if request.method == 'POST': #When the add friend button is pressed
r = request.form
birthday = r.get('date')
birthday_s = birthday.split('/') ##[mm,dd,yyyy]
friend = Friend(
name= str(r.get('first_name')) + " " + str(r.get('last_name')),
pronouns = str(r.get('pronouns')),
birthdate=datetime.date(int(birthday_s[2]),int(birthday_s[0]),int(birthday_s[1])), #datetime.date takes (yyyy,mm,dd)
phone=str(r.get('phone_number')),
allergies=str(r.get('allergies')),
optional1={str(r.get('optional1-name')):str(r.get('optional1-text'))},
optional2={str(r.get('optional2-name')):str(r.get('optional2-text'))},
optional3={str(r.get('optional3-name')):str(r.get('optional3-text'))},
optional4={str(r.get('optional4-name')):str(r.get('optional4-text'))}
)
f = addFriend()
f.add(friend)
return redirect(url_for("load_dashboard"), code=303)
if request.method == 'GET':
#load page that has the form to add friend
return render_template('add_friend.html')
@app.route("/dashboard")
def load_dashboard():
current_user = app.config['USER']
f = getFriend()
friends_list = f.getAllFriends()
e = birthdays()
upcoming_events = e.getUpcomingBirthdays()
return render_template('index.html', friends= friends_list, birthdays=upcoming_events)
if __name__ == '__main__':
# Threaded option to enable multiple instances for multiple user access support
app.run(threaded=True, port=5000)