-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbnumbers.py
More file actions
executable file
·64 lines (49 loc) · 1.96 KB
/
bnumbers.py
File metadata and controls
executable file
·64 lines (49 loc) · 1.96 KB
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
from api.everything import *
from api.API.projects import getProject
from api.API.collaborators import delete_non_collaborators, add_collaborators
from api.API.faculty import get_faculty_by_bnumbers
@app.route("/bnumbers", methods = ["POST"])
@login_required
def update_collaborators ():
"""This function updates the collaborators table
Args:
username (str): The username of the person accessing the app
numCollab (str): POST number of collaborators project hasattr
cnumber<index> (str): POST the collaborators c number; there maybe one or more of these
Returns:
Redirect: redirects to history_GET
"""
proj = getProject(g.user.username)
submitted_bnumbers = request.form.getlist("cbnumbers[]")
add_collaborators(proj.pID, submitted_bnumbers)
delete_non_collaborators(proj.pID, submitted_bnumbers)
return redirect ( url_for( "history_GET" ))
@app.route("/checkBNumber", methods = ["POST"])
@login_required
def checkBNumber():
"""This function checks to see if a bnumber exists.
It checks the LDAPFaculty table and if finds a User
it marks the bnum as good.
Args:
username (str): the user who is currently accessing the application
bnum (str): POST the number that needs to be checked
Returns:
JSON: response that is either OK or NOTFOUND
"""
bnumber = request.json['bnum']
if bnumber[0] == "b":
bnumber = "B" + bnumber[1:]
print ("Replaced Bnum: " + bnumber)
# We are assuming BNumbers are less than 10 characters
if (len(bnumber) < 12) and (bnumber.find("B") == 0):
facQ = (LDAPFaculty.select()
.where (LDAPFaculty.bnumber == bnumber)
)
if facQ.exists():
if facQ[0].username == g.user.username:
return jsonify({"response" : "USER"})
return jsonify({ "response" : "OK" })
else:
return jsonify({ "response" : "NOTFOUND" })
else:
return jsonify({ "response" : "NOTFOUND" })