-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·194 lines (156 loc) · 6.45 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
from flask import Flask, render_template, redirect, url_for, request
import database as db
app = Flask(__name__)
#--------------------------------------------------------------------------------
# Sign In
#
# Page - Sign In
@app.route("/")
@app.route("/index")
@app.route("/index.html")
def index():
return render_template("index.html")
# Process - Called when SignIn & SignUp
@app.route("/_signin", methods = ["POST"])
def _signin():
if request.method == 'POST':
uid = request.form["userid"]
upw = request.form["userpw"]
stu = request.form["role"]
result = db.signIn(uid, upw, stu)
if not result:
if stu == "student":
return redirect(url_for('student'))
else:
return redirect(url_for('company'))
if stu == "student": # as student
return redirect(url_for('studentmypage', sid=result[0], Fname=result[4]))
else: # as company
return redirect(url_for('companymypage', name=result[3]))
#--------------------------------------------------------------------------------
# Sign In
# Page - Search with query
@app.route("/searchquery/<query>")
def searchquery(query):
student, company, position, course = db.search(query)
return render_template("search.html", students = student, companies = company, positions = position, courses = course)
@app.route("/search")
def search():
return render_template("search.html")
# Process - Search
@app.route("/_search", methods=["POST"])
def _search():
if request.method == "POST":
query = request.form['query']
return redirect(url_for('searchquery', query = query))
#--------------------------------------------------------------------------------
# Student
#
# Page - Student Enroll
@app.route("/student")
def student():
return render_template("student.html")
# Process - Student Enroll
@app.route("/_studentenroll", methods=["POST"])
def _studentenroll():
if request.method == "POST":
db.add(request.form, "student")
return redirect(url_for('studentmypage', sid = request.form["sid"], Fname = request.form["fname"]))
# Page - Student MyPage
@app.route("/studentmypage/<sid>/<Fname>/")
def studentmypage(sid, Fname):
course = db.get("course", sid)
work = db.get("work", sid)
position = db.calculate("position", sid)
message = db.receive(sid, "student")
return render_template("studentmypage.html", sid = sid, Fname = Fname, courses = course, works = work, positions = position, messages = message)
# Page - Add Course
@app.route("/studentmypage/<sid>/<Fname>/addcourse")
def addcourse(sid, Fname):
return render_template("addcourse.html")
# Process - Add Course
@app.route("/studentmypage/<sid>/<Fname>/_addcourse", methods = ["POST"])
def _addcourse(sid, Fname):
if request.method == "POST":
obj = {"sid": sid}
for field in ["code", "name", "credit", "professor", "grade", "year", "semester"]:
obj[field] = request.form[field]
db.add(obj, "course")
return redirect(url_for('studentmypage', sid = sid, Fname = Fname))
# Page - Add Work
@app.route("/studentmypage/<sid>/<Fname>/addwork")
def addwork(sid, Fname):
return render_template("addwork.html")
# Process - Add Work
@app.route("/studentmypage/<sid>/<Fname>/_addwork", methods = ["POST"])
def _addwork(sid, Fname):
if request.method == "POST":
obj = {"sid": sid}
for field in ["name", "description", "category"]:
obj[field] = request.form[field]
db.add(obj, "work")
return redirect(url_for('studentmypage', sid = sid, Fname = Fname))
# Process - Send Message to Company
@app.route("/studentmypage/<sid>/<Fname>/_sendtocompany", methods = ["POST"])
def _sendtocompany(sid, Fname):
if request.method == "POST":
message = request.form['message']
name = request.form['name']
db.send(message, sid, name, "student")
return redirect(url_for("studentmypage", sid = sid, Fname = Fname))
# Process - Send Message to Company
@app.route("/studentmypage/<sid>/<Fname>/_sendtocompany/<name>", methods = ["POST"])
def _sendtothecompany(sid, Fname, name):
if request.method == "POST":
message = request.form['message']
db.send(message, sid, name, "student")
return redirect(url_for("studentmypage", sid = sid, Fname = Fname))
#--------------------------------------------------------------------------------
# Company
#
# Page - Company Enroll
@app.route("/company")
def company():
return render_template("company.html")
# Process - Company Enroll
@app.route("/_companyenroll", methods=["POST"])
def _companyenroll():
if request.method == "POST":
db.add(request.form, "company")
return redirect(url_for('companymypage', name = request.form["name"]))
# Page - Company MyPage
@app.route("/companymypage/<name>/")
def companymypage(name):
position = db.get("position", name)
message = db.receive(name, "company")
return render_template("companymypage.html", name = name, positions = position, messages = message)
# Page - Add Position
@app.route("/companymypage/<name>/addposition")
def addposition(name):
return render_template("addposition.html")
# Process - Add Position
@app.route("/companymypage/<name>/_addposition", methods = ["POST"])
def _addposition(name):
if request.method == "POST":
db.add(request.form, "position")
return redirect(url_for('companymypage', name = name))
# Process - Send Message to Student
@app.route("/companymypage/<name>/_sendtostudent", methods = ["POST"])
def _sendtostudent(name):
if request.method == "POST":
message = request.form['message']
sid = request.form['sid']
db.send(message, name, sid, "company")
return redirect(url_for('companymypage', name = name))
# Process - Send Message to Student
@app.route("/companymypage/<name>/_sendtostudent/<sid>", methods = ["POST"])
def _sendtothestudent(name, sid):
if request.method == "POST":
message = request.form['message']
db.send(message, name, sid, "company")
return redirect(url_for('companymypage', name = name))
#--------------------------------------------------------------------------------
# run
#
if __name__ == "__main__":
app.run('0.0.0.0', port=5000, debug=False)