/
SignoutPage.py
330 lines (276 loc) · 13 KB
/
SignoutPage.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# -*- coding: utf-8 -*-
import datetime
import db
from utils import *
from auth import *
def generateSignoutDaySlots(weekOf, startTime, type):
daySlots = ""
day = datetime.datetime.combine(weekOf, startTime)
currentUser = authGetID()
for i in range(0, 5):
entries = db.getEntries(day.date(), startTime, type)
quantity = db.getResourceQuantity(type)
currentUserInBox = 0
for entry in entries:
if db.getTeacherName(entry[7]) == currentUser:
currentUserInBox = entry[5]
quantity -= entry[5]
if entries:
if currentUserInBox:
daySlots += "<td class='tFilled tSignout ts' "
else:
daySlots += "<td class='tFilled ts' "
else:
daySlots += "<td class='ts' "
daySlots += " onclick='signout(\"" + currentUser + "\"," + str(currentUserInBox) + "," + str(quantity) + ", \"" + day.strftime("%Y-%m-%d") + "\",\"" + startTime.strftime("%I:%M") + "\")'>"
if not entries:
daySlots += " "
for entry in entries:
if db.getTeacherName(entry[7]) == currentUser:
daySlots += "<div class='signoutEntry'>"
else:
daySlots += "<div class='entry'>"
daySlots += db.getTeacherName(entry[7])
daySlots += " (%(q)d)" % {"q": entry[5]}
daySlots += "</div>"
if entries:
daySlots += "<div class='leftEntryAfter'>%(q)d left</div>" % {"q": quantity}
daySlots += "</td>"
day = day + datetime.timedelta(days=1)
return daySlots
def generateSignoutSchedulePage(weekOf,type):
nextWeek = lastWeek = datetime.datetime.combine(weekOf, datetime.time(0,0))
nextWeek = nextWeek + datetime.timedelta(weeks=1)
nextWeekStr = nextWeek.strftime("%Y-%m-%d")
lastWeek = lastWeek - datetime.timedelta(weeks=1)
lastWeekStr = lastWeek.strftime("%Y-%m-%d")
yield u"""
<div id="schedule">
<div id="scheduleHeader"><div class="smallbutton" onclick="window.location='%(last)s'"><a href="%(last)s">←</a></div> <span id='schedTitle'>Schedule for week of %(week)s</span> <div class="smallbutton" onclick="window.location='%(next)s'"><a href="%(next)s">→</a></div></div>
<br />
<table id="scheduleTable" cellpadding="0px" cellspacing="4px">
<tr>
<td class="tHide"></td>
<td class="tHeader">Monday</td>
<td class="tHeader">Tuesday</td>
<td class="tHeader">Wednesday</td>
<td class="tHeader">Thursday</td>
<td class="tHeader">Friday</td>
</tr>""" % {"week": weekOf.strftime("%B %d, %Y"),
"last": "?date=" + lastWeekStr,
"next": "?date=" + nextWeekStr}
startTime = datetime.datetime.combine(weekOf, datetime.time(8,45))
endTime = startTime + datetime.timedelta(minutes=db.getResourceDuration(type))
for i in range(0,db.getResourceSlotCount(type)):
yield """
<tr>
<td class="tTime">%(startTime)s - %(endTime)s</td>
%(daySlots)s
</tr>
""" % {"startTime": startTime.strftime("%I:%M"),
"endTime": endTime.strftime("%I:%M"),
"daySlots": generateSignoutDaySlots(weekOf, startTime.time(), type)}
startTime = startTime + datetime.timedelta(minutes=db.getResourceDuration(type)+5)
endTime = endTime + datetime.timedelta(minutes=db.getResourceDuration(type)+5)
def generateTeachersDropdown():
yield "<select name='teacher' onchange='changedNameSelection()' id='teacher'>"
yield "<option></option>"
yield "<optgroup label='3rd Grade'>"
for t in db.getTeachersOfGrade(3):
yield "<option name='%(name)s'>%(name)s</option>" % { "name": t }
yield "</optgroup><optgroup label='4th Grade'>"
for t in db.getTeachersOfGrade(4):
yield "<option name='%(name)s'>%(name)s</option>" % { "name": t }
yield "</optgroup><optgroup label='5th Grade'>"
for t in db.getTeachersOfGrade(5):
yield "<option name='%(name)s'>%(name)s</option>" % { "name": t }
yield "</optgroup><optgroup label='Misc.'>"
for t in db.getTeachersOfGrade(0):
yield "<option name='%(name)s'>%(name)s</option>" % { "name": t }
yield "</optgroup></select>"
class signoutPage:
def __init__(self, t):
self.type = t
def index(self, date=None):
date = normalizeDate(date)
src = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>MBS Technology Signout</title>
<link rel="stylesheet" href="/static/style.css" type="text/css" charset="utf-8" />
<style type="text/css">
#header
{
border-bottom: 1px solid #666;
}
#logo
{
padding: 20px 15px 20px 15px;
}
#signinForm
{
text-align: left;
}
td
{
border: 0px;
}
</style>
<script src="/static/jquery.min.js"></script>
<script src="/static/jquery.md5.js"></script>
<script>
function checkSubmit()
{
var signout = $("#signoutButton");
var teacher = $("#teacher")[0].value;
for (var i = 0, l = $("#teacher")[0].length; i < l; ++i)
{
if ((o = $("#teacher")[0].options[i]).selected)
teacher = o.text;
}
if(teacher != "")
document.signinForm.submit();
else
alert("Please specify who you are...");
}
</script>
</head>
<body>
<div id="header">
<img src="/static/signout-logo.png" id="logo"/>
</div>
<form id="signinForm" name="signinForm" action="choose" method="post">
<div class="headerButtonSmall" style="text-align: left;">
<div style="font-size: 1.5em; text-align: center;">
Signing out %(slugN)s
</div>
<br/>
<table border="0px" cellpadding="6px" width="100%%">
<tr>
<td style="text-align: right;" width="45%%"><b>Select your name:</b></td>
<td width="55%%">%(teachers)s</td>
</tr>
</table>
</div>
</form>
<a href="javascript:checkSubmit()"><div id="signoutButton">
<img src="/static/play.png" valign="top"/> Continue to time slot selection
</div></a>
</body>
</html>
""" % {
"id": self.type,
"name": db.getResourceName(self.type),
"slug": db.getResourceSlug(self.type),
"slugN": db.getResourceSlugN(self.type),
"q": db.getResourceQuantity(self.type),
"teachers": "".join(list(generateTeachersDropdown())) }
return src
index.exposed = True
def choose(self, date=None, teacher=None, other=None, time=None, signout=None, day=None, logout=None):
date = normalizeDate(date)
if logout is not None:
authLogout()
print "logout"
return """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script>window.location='/'</script></html>"""
if (teacher == None) and not authGetLoggedIn():
print "not logged in, missing data"
return """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script>window.location='/'</script></html>"""
if (teacher != None) and not authLogin(teacher):
return """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
Wrong password! Go back and try again...</html>"""
if not authGetLoggedIn():
print "still not logged in"
return """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script>window.location='/'</script></html>"""
teacher = authGetID()
if signout is not None:
db.setEntry(day,time,self.type,db.getTeacherId(teacher),signout)
return """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<script>window.location='?'</script></html>"""
src = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>MBS Technology Signout</title>
<link rel="stylesheet" href="/static/style.css" type="text/css" charset="utf-8" />
<script src="/static/jquery.min.js"></script>
<script>
function signout(name, currentQ, leftQ, date, time)
{
var moreStr = "";
if(currentQ != 0)
moreStr = "(" + leftQ + " more) ";
res = prompt("You currently have " + currentQ +
" %(slugN)s signed out for " + time + " on " + date + ".\\n\\n" +
"You can sign out up to " + (currentQ + leftQ) + " %(slugN)s " + moreStr + "in that slot:\\n", currentQ);
if(res == null)
return;
if(isNaN(res))
{
alert("'" + res + "' is not a number between 0 and (currentQ + leftQ). Please try again.");
signout(name, currentQ, leftQ, date, time);
return;
}
if(res > (currentQ + leftQ))
{
alert("You requested " + (res - currentQ) + " additional %(slugN)s. However, there are only " + leftQ + " available. Please try again.");
signout(name, currentQ, leftQ, date, time);
return;
}
window.location = "?signout=" + res + ";day=" + date + ";time=" + time;
}
</script>
</head>
<body id="tab%(id)d">
<div id="header">
<img src="/static/signout-logo.png" id="logo"/>
%(tabs)s
</div>
<div id="headerButton">
<small><small><b>Signing out %(slugN)s as <i>%(name)s</i></b></small></small>
<div id="headerButtonSub">
The number of remaining seats in each time slot is indicated below. Click on a time slot to change the number of seats <em>you</em> need. When you are done, click the button below to continue.
Each slot has <b>%(q)d</b> %(slugN)s available unless otherwise noted.
</div>
</div>
<a href="?logout=1"><div id="signoutButton">
<img src="/static/play.png" valign="top"/> Done
</div></a>
<div id="schedule">""" % {
"id": self.type,
"name": db.getResourceName(self.type),
"slug": db.getResourceSlug(self.type),
"slugN": db.getResourceSlugN(self.type),
"q": db.getResourceQuantity(self.type),
"tabs": generateTabs("/signout/choose"),
"name": teacher }
src += "".join(list(generateSignoutSchedulePage(date,self.type)))
src += """
</div>
</body>
</html>"""
return src
choose.exposed = True