def htmlCode(self): examnr = self.examnr if examnr < 0: return '<em>Error: Invalid exam number</em>' table = [] table.append([ '', 'Matr.-Nr.', 'Name', 'Punkte', 'Punkte in den einzelnen Aufgaben' ]) l = Utils.SortNumerAlpha(Data.people.keys()) maxscore = 0 counter = 0 for k in l: p = Data.people[k] if (examnr < len(p.exams) and p.exams[examnr] != None): exam = p.exams[examnr] if (exam.maxscore != 0): maxscore = exam.maxscore if (exam.registration == 1 and exam.totalscore != -1): counter += 1 table.append([ str(counter), k, Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname), locale.str(exam.totalscore), Utils.CleanWeb(exam.scores) ]) s = ('<p>Maximal erreichbare Punktzahl: ' + locale.str(maxscore) + '</p>\n') s += createHTMLTable(table) return s
def htmlCode(self): s = '<h3>Liste der Teilnehmer an Klausur ' + str( self.examnr) + '</h3>\n' table = [] table.append(['', 'Matr.-Nr.', 'Name']) l = Utils.SortNumerAlpha(Data.people.keys()) i = 0 for k in l: p = Data.people[k] if self.examnr < len( p.exams ) and \ p.exams[self.examnr] != None and \ p.exams[self.examnr].registration: i += 1 table.append([ str(i), k, Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname) ]) s += createHTMLTable(table) return s
def createExamRegistrationMask(self): examnr = self.examnr s = '<h3>An-/Abmeldung von Klausur ' + str(examnr) + '</h3>\n' s += ('<form action="/AdminExtension" method="post">\n' '<div><input type="hidden" name="extension" value="' + self.name() + '" />\n' '<input type="hidden" name="state" value="1" />\n' '<input type="hidden" name="examnr" value="' + str(examnr) + '" /></div>\n') table = [] table.append(['', 'Matr.-Nr.', 'Name', 'Klausurteilnahme']) l = Utils.SortNumerAlpha(Data.people.keys()) counter = 0 for k in l: counter += 1 p = Data.people[k] checked = '' if (examnr < len(p.exams) and p.exams[examnr] != None and p.exams[examnr].registration == 1): checked = 'checked="checked" ' table.append([ str(counter), k, Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname), '<input type="checkbox" name="T' + k + '" ' 'value="true" ' + checked + ' />' ]) s += createHTMLTable(table) s += ( '<p><input type="submit" name="Action" value="Send" />\n' # Not sure how I can make of the AdminPasswdField() method. OTOH, this method # only uses a global variable, so there's no reason for it to be a method of # a class. # '' + handler.AdminPasswdField() + '\n' '<input type="password" size="16" maxlength="16" ' 'name="passwd" value="" /></p>\n' '</form>\n') return s
def createSuccessMessage(self): examnr = self.examnr # evaluate the changes registrations = {} l = Utils.SortNumerAlpha(Data.people.keys()) for k in l: p = Data.people[k] wasRegistered = (examnr < len(p.exams) and p.exams[examnr] != None and p.exams[examnr].registration == 1) shouldBeRegistered = self.options.has_key('T' + k) if wasRegistered != shouldBeRegistered: registrations[k] = int(shouldBeRegistered) # put the changes into the database registered = [] unregistered = [] Data.Lock.acquire() timestamp = int(time.time()) for k in Utils.SortNumerAlpha(registrations.keys()): v = registrations[k] line = AsciiData.LineTuple( (k, str(examnr), str(v), str(timestamp))) try: Data.examregdesc.AppendLine(line) except: Data.Lock.release() Utils.Error('[' + Utils.LocalTimeString() + '] Failed to register person for exam:\n' + line) return '<emph>Error: The changes could not be saved.</emph>' p = Data.people[k] while len(p.exams) < examnr + 1: p.exams.append(None) if p.exams[examnr] == None: p.exams[examnr] = Data.Exam() p.exams[examnr].timestamp = timestamp p.exams[examnr].registration = v if Data.Exam.maxexamnumber < examnr + 1: Data.Exam.maxexamnumber = examnr + 1 line = (Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname) + ' (' + k + ')') if v == 1: registered.append(line) else: unregistered.append(line) Data.Lock.release() Utils.Error('[' + Utils.LocalTimeString() + '] Changed registrations ' 'for exam ' + str(examnr), prefix='BulkExamRegistration: ') s = '<h3>An-/Abmeldung von Klausur ' + str(examnr) + '</h3>\n' if len(registered) > 0: s += ('<div>Die folgenden Personen wurden zur Klausur angemeldet:' '</div>\n' '<ul>\n<li>' + str('</li>\n<li>').join(registered) + '</li>\n</ul>\n') if len(unregistered) > 0: s += ('<div>Die folgenden Personen wurden von der Klausur ' ' abgemeldet:</div>\n' '<ul>\n<li>' + str('</li>\n<li>').join(unregistered) + '</li>\n</ul>\n') return s
def htmlCode(self): lecturer = Config.conf['Lecturer'] semester = Config.conf['Semester'] s = ('<hr />\n' '<form action="/AdminExtension" method="post">\n' '<div><input type="hidden" name="extension" value="' + self.name() + '" />\n' '<input type="hidden" name="state" value="1" /></div>\n' '<p>' 'Dozent: <input size="30" maxlength="40" name="lecturer" ' 'value="' + lecturer + '" /><br />\n' 'Semester: <input size="30" maxlength="40" name="semester" ' 'value="' + semester + '" /><br />\n' 'Scheine: <input type="radio" name="benotet" ' 'value="ja" />benotet / ' '<input type="radio" name="benotet" ' 'value="nein" />unbenotet<br />\n' 'Datum: <input size="20" maxlength="20" name="date" ' 'value="" /> (falls leer wird heutiges Datum genommen)' '</p>\n' '<p>Waehlen Sie diejenigen Kursteilnehmer aus, fuer die ein ' 'Schein generiert werden soll.</p>\n') table = [] titleRow = ['', 'Schein', 'Matr.-Nr.', 'Name', 'Uebungspunkte'] for i in range(Data.Exam.maxexamnumber): titleRow.append('Klausur ' + str(i)) titleRow.append('Bemerkung') table.append(titleRow) nurScheinbedErf = (self.getString('nurScheinbedErf') == 'true') l = Utils.SortNumerAlpha(Data.people.keys()) counter = 0 for k in l: p = Data.people[k] if nurScheinbedErf and not self.ScheinbedingungErfuellt(p): continue counter += 1 row = [str(counter)] if self.ScheinbedingungErfuellt(p): row.append('<input type="checkbox" name="Schein' + k + '" ' 'value="true" />') else: row.append('-') row += [ k, Utils.CleanWeb(p.lname + ', ' + p.fname), locale.str(p.TotalScore()) ] for i in range(Data.Exam.maxexamnumber): if (len(p.exams) <= i or p.exams[i] == None or p.exams[i].totalscore < 0): row.append('-') else: row.append(locale.str(p.exams[i].totalscore)) if self.ScheinbedingungErfuellt(p): row.append('Scheinbedingung ist erfuellt') else: row.append('Scheinbedingung ist nicht erfuellt') table.append(row) s += createHTMLTable(table) s += ( '<p><input type="submit" name="Action" value="Send" />\n' # Not sure how I can make use of the AdminPasswdField() method. OTOH, this # method only uses a global variable, so there's no reason for it to be a # method of a class. # '' + handler.AdminPasswdField() + '\n' '<input type="password" size="16" maxlength="16" ' 'name="passwd" value="" /></p>\n' '</form>\n') return s
def createSummary(self): examnr = self.examnr maxscore = self.maxscore scores = self.scores oldscores = self.oldscores # put the changes into the database table = [] table.append([ '', 'Matr.-Nr.', 'Name', 'Punkte', 'Punkte in den einzelnen Aufgaben' ]) unchanged = [] unchanged.append([ '', 'Matr.-Nr.', 'Name', 'Punkte (alt)', 'Punkte (aktuell)', 'Punkte (Ihre Angabe)', 'Details (alt)', 'Details (aktuell)', 'Details (Ihre Angabe)' ]) counter = 0 unchangedcount = 0 Data.Lock.acquire() for k in Utils.SortNumerAlpha(scores.keys()): p = Data.people[k] while len(p.exams) < examnr + 1: p.exams.append(None) exam = p.exams[examnr] newOrChanged = False # we only have to save non-default values for not yet existing # entries or changed values for existing entries newtotalscore = scores[k][0] newdetails = scores[k][1] oldtotalscore = oldscores[k][0] olddetails = oldscores[k][1] # if ( exam == None ): # only needed for the following print # curtotalscore = -1 # curdetails = '<None>' # else: # curtotalscore = exam.totalscore # curdetails = exam.scores # print ( k + ': totalscore (old/cur/new): ' + str(oldtotalscore) + # '/' + str(curtotalscore) + '/' + str(newtotalscore) + # ' -- details (old/cur/new): "' + olddetails + '"/"' + # curdetails + '"/"' + newdetails + '"' ) if (exam == None): # do we have non-default values? if (newtotalscore != -1 or newdetails != ''): exam = Data.Exam() newOrChanged = True else: # has the user made changes? valuesChanged = ((newtotalscore != oldtotalscore) or (newdetails != olddetails)) # are there changes with respect to the currently stored values # (because of changes by another user while the first user editted # the values) needsSaving = ((newtotalscore != exam.totalscore) or (newdetails != exam.scores)) # have there been changes behind our back changedBehindBack = ((oldtotalscore != exam.totalscore) or (olddetails != exam.scores)) if (valuesChanged and needsSaving and changedBehindBack): # the user has changed a value and additionally this value has # been changed by another user while the first user editted # the values; in this case we don't save our values unchangedcount += 1 if newtotalscore == -1: newtotalscorestr = '-' else: newtotalscorestr = locale.str(newtotalscore) if oldtotalscore == -1: oldtotalscorestr = '-' else: oldtotalscorestr = locale.str(oldtotalscore) if exam.totalscore == -1: curtotalscorestr = '-' else: curtotalscorestr = locale.str(exam.totalscore) unchanged.append([ str(unchangedcount), k, Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname), oldtotalscorestr, curtotalscorestr, newtotalscorestr, olddetails, exam.scores, newdetails ]) elif (valuesChanged): newOrChanged = True elif (exam.maxscore != maxscore and (oldtotalscore != -1 or olddetails != '')): newOrChanged = True if newOrChanged: exam.totalscore = newtotalscore exam.scores = newdetails exam.maxscore = maxscore line = AsciiData.LineTuple((k, str(examnr), str(newtotalscore), str(maxscore), newdetails)) try: Data.examdesc.AppendLine(line) except: Data.Lock.release() Utils.Error('[' + Utils.LocalTimeString() + '] Failed to store exam result:\n' + line) return '<em>Error: The results could not be saved.</em>' p.exams[examnr] = exam counter += 1 if newtotalscore == -1: newtotalscorestr = '-' else: newtotalscorestr = locale.str(newtotalscore) table.append([ str(counter), k, Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname), newtotalscorestr, newdetails ]) Data.Lock.release() Utils.Error('[' + Utils.LocalTimeString() + '] Changed results ' 'for exam ' + str(examnr), prefix=self.name() + ': ') s = '<h3>Ergebnisse von Klausur ' + str(examnr) + '</h3>\n' if len(unchanged) > 1: s += ( '<p>Einige Werte wurden geändert, während Sie die Werte editiert ' 'haben. Daher wurden die folgenden Änderungen <strong>nicht</strong> ' 'gespeichert.') s += createHTMLTable(unchanged) s += '<p>Die folgenden Änderungen wurden gespeichert.</p>' s += createHTMLTable(table) return s
def createExamResultInputMask(self): examnr = self.examnr s = '<h3>Eingabe der Ergebnisse von Klausur ' + str(examnr) + '</h3>\n' s += ('<p><em>Hinweis:</em> Es werden nur diejenigen ' 'Kursteilnehmer angezeigt, die zu dieser Klausur angemeldet ' 'sind.</p>') s += ('<form action="/AdminExtension" method="post">\n' '<div><input type="hidden" name="extension" value="' + self.name() + '" />\n' '<input type="hidden" name="state" value="1" />\n' '<input type="hidden" name="examnr" value="' + str(examnr) + '" /></div>\n') table = [] table.append([ '', 'Matr.-Nr.', 'Name', 'Punkte', 'Punkte in den einzelnen Aufgaben' ]) l = Utils.SortNumerAlpha(Data.people.keys()) counter = 0 oldmaxscore = '' for k in l: p = Data.people[k] checked = '' if (examnr < len(p.exams) and p.exams[examnr] != None): exam = p.exams[examnr] if (exam.maxscore != 0): oldmaxscore = locale.str(exam.maxscore) if (exam.registration == 1): counter += 1 oldtotalscore = '' if (exam.totalscore != -1): oldtotalscore = locale.str(exam.totalscore) table.append([ str(counter), k, Utils.CleanWeb(p.lname) + ', ' + Utils.CleanWeb(p.fname), '<input type="hidden" ' 'name="Pold' + str(examnr) + '_' + k + '" ' 'value="' + oldtotalscore + '" />' '<input size="6" maxlength="6" ' 'name="P' + str(examnr) + '_' + k + '" ' 'value="' + oldtotalscore + '" />', '<input type="hidden" ' 'name="Sold' + str(examnr) + '_' + k + '" ' 'value="' + Utils.CleanWeb(exam.scores) + '" />' '<input size="40" maxlength="100" ' 'name="S' + str(examnr) + '_' + k + '" ' 'value="' + Utils.CleanWeb(exam.scores) + '" />' ]) s += ('<p>Maximal erreichbare Punktzahl: ' '<input name="maxscore" value="' + oldmaxscore + '" ' 'size="4" maxlength="4" /></p>\n') s += createHTMLTable(table) s += ( '<p><input type="submit" name="Action" value="Send" />\n' # Not sure how I can make use of the AdminPasswdField() method. OTOH, this # method only uses a global variable, so there's no reason for it to be a # method of a class. # '' + handler.AdminPasswdField() + '\n' '<input type="password" size="16" maxlength="16" ' 'name="passwd" value="" /></p>\n' '</form>\n') return s