-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
316 lines (266 loc) · 11 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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# Package Imports
from flask import Flask, render_template, redirect, url_for, flash, session, g, request
from werkzeug.security import generate_password_hash, check_password_hash
from forms import LoginForm, RegisterForm, ContactUs, ScheduleForm, Availability, RequestForm, ApproveRequest
from db_ops import StoreData, Validation, AddSchedule, ViewSchedule, ViewAllSchedule, changeAvailability, ViewRequests, Viewfdb, ViewAvailable, RequestSwap, ReqStat, ApproveReq
import sqlite3
app = Flask(__name__)
app.config['SECRET_KEY'] = 'mysecretkey148-3tothe3tothe6tothe9'
cur_user = ''
@app.route('/')
@app.route('/home')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact', methods=['GET', 'POST'])
def contact():
form = ContactUs()
if form.validate_on_submit():
email = form.email.data
name = form.name.data
msg = form.message.data
conn = sqlite3.connect('db\\exam.db')
print("connected")
cl = conn.cursor()
cl.execute(f'''
insert into fdbk values('{email}','{name}','{msg}')
''')
conn.commit()
return "FeedBack sent successfully", render_template("contact.html", form=form)
# return "The feedback has been submitted"
return render_template("contact.html", form=form)
@app.route('/login', methods=['GET', 'POST'])
def login():
session.pop('user', None)
form = LoginForm()
if form.validate_on_submit():
email, password = form.email.data, form.password.data
res = Validation(email, password)
if res == "Login success" and email != "admin@gmail.com":
flash(res)
session['user'] = globals()['cur_user'] = email
return render_template("user.html", name=globals()['cur_user'], ddtext='Modules')
elif res == "Login success" and email == "admin@gmail.com":
flash(res)
session['user'], globals()['cur_user'] = email, "admin"
return redirect(url_for("admin"))
# return render_template("admin.html", name=globals()['cur_user'])
elif res == "Wrong Password":
flash(res)
return redirect(url_for("login"))
else:
flash("Email does not exist.\nCreate account")
return redirect(url_for("register"))
return render_template('login.html', form=form, ddtext='Modules')
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegisterForm()
if form.validate_on_submit():
email, fname, lname, pno = form.email.data, form.firstname.data, form.lastname.data, form.phone.data
password = generate_password_hash(form.password.data)
res = StoreData(email, fname, lname, pno, password)
if res == "User Registered Successfully":
flash(res)
return redirect(url_for('login'))
else:
flash("Unable to create User")
return redirect(url_for("register"))
return render_template('register.html', form=form)
# user form functionalities below
@app.route('/user')
def user():
if g.user:
return render_template('user.html', ddtext='Modules')
return redirect(url_for("login"))
@app.route('/user/view_slot')
def view_slot():
email = globals()['cur_user']
if email == '':
flash("Login as user to view schedule.")
return redirect(url_for('login'))
else:
lis = ViewSchedule(email) # list of list containing schedules
return render_template('display_slot.html', lis=lis, email=email, ddtext='View Slot')
@app.route('/user/view_available')
def viewAvailable():
email = globals()['cur_user']
if email == '':
flash("Login as user to view schedule.")
return redirect(url_for('login'))
else:
lis = ViewAvailable(email) # list of list containing schedules
return render_template('view_available.html', lis=lis, ddtext='View Available Faculty')
@app.route('/user/request_swap', methods=['GET', 'POST'])
def RequestSwapp():
email1 = globals()['cur_user']
if email1 == '':
flash("Login as user to view schedule.")
return redirect(url_for('login'))
else:
form = RequestForm()
if form.validate_on_submit():
email, examid, date, time, slot = form.email.data, form.examid.data, form.date.data, form.time.data, form.slot.data
if email != email1:
print(email, examid, date, time, slot)
res = RequestSwap(email1, email, examid, date, time, slot)
flash(res)
return redirect(url_for("RequestSwapp"))
elif email == email1:
flash("you can't enter your own email!")
return redirect(url_for("RequestSwapp"))
return render_template('request_swap.html', form=form, ddtext='Request Swap')
@app.route("/user/view_req_stat")
def viewreqstatus():
email = globals()["cur_user"]
if email == '':
flash("Login to view request status")
return redirect(url_for("login"))
else:
lis = ReqStat(email)
return render_template('reqstat.html', lis=lis, ddtext="View Request Status")
@app.route("/user/availability", methods=['GET', 'POST'])
def availability():
email = globals()['cur_user']
if email == '':
flash("Login as user to change availability.")
return redirect(url_for('login'))
else:
form = Availability()
if form.validate_on_submit():
examid = form.examid.data
slot = form.slot.data
availability = form.availability.data
email = globals()['cur_user']
changeAvailability(email, examid, slot, availability)
flash("updated availability")
return redirect(url_for("availability"))
return render_template('availability.html', form=form, ddtext='Change Availability')
# admin form functionalities below
@app.route('/admin')
def admin():
if g.user:
return render_template('admin.html', ddtext='modules')
return redirect(url_for("login"))
@app.route('/admin/add_slot', methods=["GET", "POST"])
def addSchedule():
if globals()['cur_user'] == "admin":
form = ScheduleForm()
if form.validate_on_submit():
email, date, time, examid, slot = form.email.data, form.date.data, form.time.data, form.examid.data, form.slot.data
res = AddSchedule(email, date, time, examid, slot)
flash(res)
return redirect(url_for("addSchedule"))
return render_template('add_slot.html', form=form, ddtext='Add Slot')
else:
flash("Login as admin to add schedule.")
return redirect(url_for("login"))
@app.route('/admin/view_all_schedule')
def viewAllSchedule():
email = globals()['cur_user']
if email != 'admin':
flash("Login as admin to view schedule.")
return redirect(url_for('login'))
else:
lis = ViewAllSchedule() # list of list containing schedules
return render_template('display_all_schedule.html', lis=lis, ddtext='View All Schedules')
@app.route('/admin/view_request')
def viewRequest():
email = globals()['cur_user']
if email != 'admin':
flash("Login as admin to view schedule.")
return redirect(url_for('login'))
else:
lis = ViewRequests() # list of list containing schedules
return render_template('view_request.html', lis=lis, ddtext='View Request')
@app.route('/admin/view_requests')
def viewRequests():
email = globals()['cur_user']
if email != 'admin':
flash("Login as admin to view requests.")
return redirect(url_for('login'))
else:
lis = Viewfdb() # list of list containing schedules
return render_template('display_requests.html', lis=lis, ddtext='View All Request')
@app.route('/admin/view_fdb')
def viewfdb():
email = globals()['cur_user']
if email != 'admin':
flash("Login as admin to view requests.")
return redirect(url_for('login'))
else:
conn = sqlite3.connect("exam.db")
cursor = conn.execute("SELECT email,name,feedback FROM fdbk")
lis = list()
for row in cursor:
temp = [
row[0], # email
row[1], # name
row[2] # feeback
]
lis.append(temp) # list of list containing schedules
return render_template('display_fdb.html', lis=lis, ddtext='View Feedback')
@app.route('/admin/app_req', methods=["GET", "POST"])
def approve():
email = globals()['cur_user']
if email != 'admin':
flash("Login as admin to view requests.")
return redirect(url_for('login'))
else:
form = ApproveRequest()
if form.validate_on_submit():
emailf, emailt, eid, date, time, slot, approval = form.emailf.data, form.emailt.data, form.examid.data, form.date.data, form.time.data, form.slot.data, form.approval.data
# print(emailf, emailt, eid, time, slot, approval)
res = ApproveReq(emailf, emailt, eid, date, time, slot, approval)
flash(res)
return redirect(url_for("approve"))
return render_template("approve.html", form=form, ddtext='Approve Request')
# @app.route('/guest')
# def guest():
# return render_template('user.html', ddtext='Modules')
#
#
# @app.route('/guest2')
# def guest2():
# email = 'ashwin99@gmail.com'
# lis = ViewSchedule(email) # list of list containing schedules
# return render_template('display_slot.html', lis=lis, email=email, ddtext='View Slot')
#
#
# @app.route('/guest3', methods=['GET', 'POST'])
# def guest3():
# email = 'ashwin99@gmail.com'
# lis = ViewSchedule(email) # list of list containing schedules
# form = Availability()
# if form.validate_on_submit():
# availability = form.availability.data
# changeAvailability(email, availability)
# flash("updated availability")
# return redirect(url_for("guest3"))
# return render_template('availability.html', form=form, ddtext='Availability Status')
#
#
# @app.route('/guest4')
# def viewAvailable1():
# email = 'ashwin99@gmail.com'
# lis = ViewAvailable()
# return render_template('view_available.html', lis=lis, ddtext='View Available')
# other session handling code below
@app.before_request
def before_request():
g.user = None
if 'user' in session:
g.user = session['user']
@app.route('/getsession')
def getsession():
if 'user' in session:
return session['user']
return 'Not logged in!'
@app.route('/dropsession')
def dropsession():
session.pop('user', None)
globals()['cur_user'] = ''
return redirect(url_for("login"))
if __name__ == '__main__':
app.run(debug=True)