-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
47 lines (32 loc) · 1.36 KB
/
admin.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
from flask import Blueprint, redirect, render_template, request, session
import sqlite3
import config
databaseName = config.databaseName
adminpage = Blueprint('adminpage', __name__, template_folder='templates/admin')
@adminpage.route("/admin")
def adminIndex():
return render_template('admin.html')
@adminpage.route("/admin/users")
def users():
return render_template('users.html')
@adminpage.route("/admin/classes")
def classes():
return render_template('classes.html')
@adminpage.route("/admin/classes/addClass", methods=['GET', 'POST'])
def addClass():
if request.method == 'POST':
try:
database = sqlite3.connect(databaseName)
cur = database.cursor()
server = request.form['server']
school = request.form['school']
classname = request.form['classname']
password = request.form['password']
cur.execute(f'''INSERT INTO schooldata (server, school, school, class, password)
VALUES ("{server}", "{school}", "{classname}", "{password}");''')
database.commit()
cur.close()
return render_template('classes.html', message="Successfully added class")
except Exception as e:
return render_template('addClass.html', message=e)
return render_template('addClass.html', message=None)