-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
97 lines (85 loc) · 4.03 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from flask import Flask, url_for, render_template, jsonify, request, json
from testCalendar import *
from pytz import timezone
import datetime
app = Flask(__name__)
#Dummy DB that I've been testing on. Replace it with the real one!
emptydb = []
#Dummy DB That I've been using so far.
dbs = []
#Just a testing route for in case you want to print out something for testing
@app.route('/testing')
def test():
return str(emptydb);
#Our main route. You can connect the db here using parameters
@app.route('/')
def index():
return render_template("index.html", dbs = dbs)
#This Method is just a helper function so that you can take
#a string of Date in MM/DD/YYYY/HH/MM format and convert it into
#an array with arr[0]=day, arr[1]=Month (got lazy we're only doing one week)
#and arr[4]=Hour, arr[5]=Month, so you can access the array elsewhere
def deserializedate(date):
quickdate = [int(date[3,5]), "March", int(date[11,13]), int(date[14,16])]
return quickdate
#This is a post URL where the magic happens, AKA when we process the AJAX call
#This is the way we can send frontend information (the event form) to the backend
#so you can add to the existing Database.
@app.route('/addevent', methods=['POST'])
def addevent():
name = request.form.get('name')
start = request.form.get('start')
end = request.form.get('end')
#You will need to do python magic here to insert the necessary data
#by first searching for the appropriate 2nd DB layer based on the month and day
#then inserting the day, Month, Week, and the Data into the db
#A lot of searching/inserting is taking place, use the deserializedate() helper
#function to your advantage.
#Collin you know this python stuff better than i do
#Declaring an index variable may be helpful
#this is where you insert it into the db. Remember it is incomplete because its automatically
#inserting into the FIRST LAYER OF DB! Which is NOT what we want.
est = timezone("US/Eastern")
tempEvent = Event(name,
est.localize(datetime.datetime(int(start[6:10]), int(start[:2]), int(start[3:5]), int(start[11:13]),int(start[14:16]))),
est.localize(datetime.datetime(int(end[6:10]), int(end[:2]), int(end[3:5]), int(end[11:13]), int(end[14:16]))),
True)
tempEvent.start_time -= tempEvent.start_time.utcoffset()
tempEvent.end_time -= tempEvent.start_time.utcoffset()
eventList.append(tempEvent)
updateAll()
del dbs[:]
for a in finalDB:
dbs.append(a)
index()
print finalDB
#leave this line to be as it is
return json.dumps({'status':'OK','name':name})
#This is the post URL for Adding Assignments -> Same shit as before
@app.route('/addassign', methods=['POST'])
def addassign():
name = request.form.get('name')
end = request.form.get('end')
hours = request.form.get('hours')
priority = request.form.get('priority')
#Same thing here as the comments above
#this is where you insert it into the db. Remember it is incomplete because its automatically
#inserting into the FIRST LAYER OF DB! Which is NOT what we want.
est = timezone("US/Eastern")
tempTask = Tasks(name,
float(hours),
est.localize(datetime.datetime(int(end[6:10]), int(end[:2]), int(end[3:5]), int(end[11:13]),int(end[14:16]))),
int(priority))
tempTask.dueDate -= tempTask.dueDate.utcoffset()
taskList.append(tempTask)
updateAll()
del dbs[:]
for a in finalDB:
dbs.append(a)
index()
print finalDB
#leave this line to be as it is
return json.dumps({'status':'OK','name':name})
#Friendly reminder that your db will erase if there is a change in the
#system because debug is on-> during the demo it shouldn't happen.
app.run(debug=True, port=8000, host='0.0.0.0')