-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwebCertifications.py
More file actions
129 lines (109 loc) · 5.69 KB
/
webCertifications.py
File metadata and controls
129 lines (109 loc) · 5.69 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
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
import cherrypy
from webBase import WebBase
class WebCertifications(WebBase):
# Certifications
def showCertifications(self, message, tools, certifications, show_table_header=True, show_left_names=True, show_right_names=True):
return self.template('certifications.mako',
message=message,
tools=tools,
show_table_header=show_table_header,
show_left_names=show_left_names,
show_right_names=show_right_names,
certifications=certifications)
@cherrypy.expose
def certify(self, all=False):
certifier_id = self.getBarcode("/certifications/certify")
message = ''
with self.dbConnect() as dbConnection:
members = self.engine.members.getActive(
dbConnection) if all else self.engine.visits.getMembersInBuilding(dbConnection)
return self.template('certify.mako', message=message,
certifier=self.engine.members.getName(dbConnection,
certifier_id)[1],
certifier_id=certifier_id,
members_in_building=members,
tools=self.engine.certifications.getListCertifyTools(dbConnection, certifier_id))
@cherrypy.expose
def addCertification(self, member_id, tool_id, level):
certifier_id = self.getBarcode("/certifications/certify")
# We don't check here for valid tool since someone is forging HTML to put an invalid one
# and we'll catch it with the email out...\
with self.dbConnect() as dbConnection:
self.engine.certifications.addNewCertification(dbConnection,
member_id, tool_id, level, certifier_id)
with self.dbConnect() as dbConnection: # separate out committing from getting
memberName = self.engine.members.getName(
dbConnection, member_id)[1]
certifierName = self.engine.members.getName(
dbConnection, certifier_id)[1]
level = self.engine.certifications.getLevelName(level)
tool = self.engine.certifications.getToolName(
dbConnection, tool_id)
self.engine.certifications.emailCertifiers(
memberName, tool, level, certifierName)
return self.template('congrats.mako', message='',
certifier_id=certifier_id,
memberName=memberName,
level=level,
tool=tool)
@cherrypy.expose
def index(self):
message = ''
with self.dbConnect() as dbConnection:
tools = self.engine.certifications.getAllTools(dbConnection)
certifications = self.engine.certifications.getInBuildingUserList(
dbConnection)
return self.showCertifications(message, tools, certifications)
@cherrypy.expose
def team(self, team_id):
message = ''
with self.dbConnect() as dbConnection:
message = 'Certifications for team: ' + \
self.engine.teams.teamNameFromId(dbConnection, team_id)
tools = self.engine.certifications.getAllTools(dbConnection)
certifications = self.engine.certifications.getTeamUserList(
dbConnection, team_id)
return self.showCertifications(message, tools, certifications)
@cherrypy.expose
def user(self, barcode):
message = ''
with self.dbConnect() as dbConnection:
message = 'Certifications for Individual'
tools = self.engine.certifications.getAllTools(dbConnection)
certifications = self.engine.certifications.getUserList(
dbConnection, user_id=barcode)
return self.showCertifications(message, tools, certifications)
def getBoolean(self, term):
if term == '0' or term.upper() == 'FALSE':
return False
return True
@cherrypy.expose
def monitor(self, tools, start_row=0, show_left_names="True", show_right_names="True", show_table_header="True"):
message = ''
with self.dbConnect() as dbConnection:
certifications = self.engine.certifications.getInBuildingUserList(
dbConnection)
start = int(start_row)
if start <= len(certifications):
# This depends on python 3.6 or higher for the dictionary to be ordered by insertion order
listCertKeys = list(certifications.keys())[start:]
subsetCerts = {}
for cert in listCertKeys:
subsetCerts[cert] = certifications[cert]
certifications = subsetCerts
else:
return self.template("blank.mako")
show_table_header = self.getBoolean(show_table_header)
show_left_names = self.getBoolean(show_left_names)
show_right_names = self.getBoolean(show_right_names)
tools = self.engine.certifications.getToolsFromList(
dbConnection, tools)
return self.showCertifications(message, tools, certifications, show_table_header, show_left_names, show_right_names)
@cherrypy.expose
def all(self):
message = ''
with self.dbConnect() as dbConnection:
tools = self.engine.certifications.getAllTools(dbConnection)
certifications = self.engine.certifications.getAllUserList(
dbConnection)
return self.showCertifications(message, tools, certifications)