def createTextFile(self): s = '# All participants of exam number ' + str(self.examnr) + ':\n' s += '# ID:angemeldet?:name:fname\n' s += '# Time and date of export: ' + Utils.LocalTimeString() + '\n' l = Utils.SortNumerAlpha(Data.people.keys()) 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: s += (k + ':1:' + Utils.Protect(p.lname) + ':' + Utils.Protect(p.fname) + '\n') else: s += (k + ':0:' + Utils.Protect(p.lname) + ':' + Utils.Protect(p.fname) + '\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 __filteroutput(self, type="html"): tablerowbeforefirst = '<tr>\n' tablerowinbetween = '\n</tr>\n<tr>\n' tablerowafterlast = '\n</tr>\n' tablecellbeforefirst = '<td>' tablecellinbetween = '</td><td>' tablecellafterlast = '</td>' tableheadinbetween = '</th><th>' reltext = { 'equal': '=', 'greater': '>', 'greaterequal': '>=', 'less': '<', 'lessequal': '<=', 'notequal': 'not equal to', 'begins': 'begins with', 'contains': 'contains', 'ends': 'ends with' } masklist = [('&', '&'), ('<', '<'), ('>', '>')] if type == "text": tablerowbeforefirst = '' tablerowinbetween = '\n' tablerowafterlast = '\n' tablecellbeforefirst = '' tablecellinbetween = ':' tablecellafterlast = '' tableheadinbetween = ':' reltext = { 'equal': '=', 'greater': '>', 'greaterequal': '>=', 'less': '<', 'lessequal': '<=', 'notequal': 'not equal to', 'begins': 'begins with', 'contains': 'contains', 'ends': 'ends with' } masklist = [] if type == "csv": tablerowbeforefirst = '' tablerowinbetween = '\n' tablerowafterlast = '\n' tablecellbeforefirst = '"' tablecellinbetween = '";"' tablecellafterlast = '"' tableheadinbetween = '";"' reltext = { 'equal': '=', 'greater': '>', 'greaterequal': '>=', 'less': '<', 'lessequal': '<=', 'notequal': 'not equal to', 'begins': 'begins with', 'contains': 'contains', 'ends': 'ends with' } masklist = [] if type == "latex": tablerowbeforefirst = '' tablerowinbetween = ' \\\\\n' tablerowafterlast = '\n' tablecellbeforefirst = '' tablecellinbetween = ' & ' tablecellafterlast = '' tableheadinbetween = '} & \\textbf{' reltext = { 'equal': '$=$', 'greater': '$>$', 'greaterequal': '$\\geq$', 'less': '$<$', 'lessequal': '$\\leq$', 'notequal': '$\\neq$', 'begins': 'begins with', 'contains': 'contains', 'ends': 'ends with' } masklist = [('\\', '\\textbackslash '), ('{', '\\{'), ('}', '\\}'), ('\\textbackslash ', '\\textbackslash{}'), ('"', '\\textquotedbl{}'), ('#', '\\#'), ('$', '\\$'), ('%', '\\%'), ('&', '\\&'), ('<', '\\textless{}'), ('>', '\\textgreater{}'), ('[', '\\relax['), (']', '\\relax]'), ('^', '\\^{}'), ('_', '\\_'), ('|', '\\textbar{}'), ('~', '\\~{}')] totalcount = 0 filtercount = 0 resultlist = [] for k in Utils.SortNumerAlpha(Data.people.keys()): p = Data.people[k] vardict = {} vardict["i"] = k vardict["n"] = p.lname vardict["f"] = p.fname vardict["s"] = p.sem vardict["g"] = p.group vardict["a"] = p.stud vardict["m"] = p.email totalintscore = 0.0 for sheetnr, sheetname, sheet in Exercises.SheetList(): if not sheet.IsClosed(): continue if not sheet.counts: continue vardict[str(sheetnr) + "c"] = -1 if p.mcresults.has_key(sheetname): vardict[str(sheetnr) + "c"] = p.mcresults[sheetname].score totalintscore += p.mcresults[sheetname].score vardict["C"] = totalintscore totalhomescore = 0.0 for sheetnr, sheetname, sheet in Exercises.SheetList(): if not sheet.IsClosed(): continue if not sheet.counts: continue vardict[str(sheetnr) + "h"] = -1 if p.homework.has_key(sheetname) and \ p.homework[sheetname].totalscore <> -1: vardict[str(sheetnr) + "h"] = p.homework[sheetname].totalscore totalhomescore += p.homework[sheetname].totalscore vardict["H"] = totalhomescore vardict["T"] = totalintscore + totalhomescore totalexamscore = 0.0 for i in range(Data.Exam.maxexamnumber): if i >= len(p.exams) or p.exams[i] == None or \ p.exams[i].totalscore < 0: vardict[str(i) + "e"] = -1 else: vardict[str(i) + "e"] = p.exams[i].totalscore totalexamscore += p.exams[i].totalscore vardict[str(i) + "r"] = "no" if i < len(p.exams) and p.exams[i] <> None: if p.exams[i].registration == 1: vardict[str(i) + "r"] = "yes" vardict["E"] = totalexamscore for i in range(len(self.__persondatakeys)): try: vardict["%dd" % i] = p.persondata[self.__persondatakeys[i]] except: vardict["%dd" % i] = "" filter = True for i in range(5): if self.__fieldlist[i] <> None: val1 = vardict[self.__fieldlist[i]] val2 = self.__vallist[i] if len(val2) >= 2 and val2[0] == '"' and val2[-1] == '"': val2 = val2[1:-1] val1 = str(val1) else: try: val1 = int(val1) val2 = int(val2) except: try: val1 = float(val1) val2 = float(val2) except: pass if self.__rellist[i] == "equal": if not val1 == val2: filter = False if self.__rellist[i] == "greater": if not val1 > val2: filter = False if self.__rellist[i] == "greaterequal": if not val1 >= val2: filter = False if self.__rellist[i] == "less": if not val1 < val2: filter = False if self.__rellist[i] == "lessequal": if not val1 <= val2: filter = False if self.__rellist[i] == "notequal": if not val1 <> val2: filter = False if self.__rellist[i] == "begins": if not str(val1)[:len(str(val2))] == str(val2): filter = False if self.__rellist[i] == "contains": if not str(val2) in str(val1): filter = False if self.__rellist[i] == "ends": if not str(val1)[-len(str(val2)):] == str(val2): filter = False totalcount += 1 if filter: filtercount += 1 sortkey = self.__sortkey.replace("%%", "_!_/_") for var in vardict.keys(): sortkey = sortkey.replace("%%%s" % var, str(vardict[var])) sortkey = sortkey.replace("_!_/_", "%") sortkey = stringtosortkey(sortkey) msg = self.__msg.replace("%%", "_!_/_") for var in vardict.keys(): if var[-1:] in ["i", "n", "f", "a", "m", "r", "d"]: msg = msg.replace('%%%s' % var, Utils.Protect(str(vardict[var]))) elif var[-1:] in ["s", "g"]: msg = msg.replace("%%%s" % var, str(vardict[var])) else: msg = msg.replace("%%%s" % var, locale.str(vardict[var])) msg = outputstring(msg, masklist, deletecolon=False) msg = msg.replace(":", tablecellinbetween) msg = msg.replace("_!_/_", "%") resultlist.append([sortkey, (k, p.lname, p.fname, msg)]) resultlist.sort() filteroutput = tablerowbeforefirst isfirst = True for sortkey, (k, ln, fn, msg) in resultlist: if not isfirst: filteroutput += tablerowinbetween isfirst = False filteroutput += tablecellbeforefirst #filteroutput += outputstring(k, masklist) #filteroutput += tablecellinbetween #filteroutput += outputstring(ln, masklist) #filteroutput += tablecellinbetween #filteroutput += outputstring(fn, masklist) if self.__msg <> "": #filteroutput += tablecellinbetween filteroutput += msg filteroutput += tablecellafterlast filteroutput += tablerowafterlast filterinfo = ["", "", "", "", filtercount, totalcount] #filterinfo[0] = '%i:%n:%f' #if self.__msg <> "": filterinfo[0] += ":" + self.__msg filterinfo[0] = self.__msg if not self.__shortcolhead: for var, fieldtitle in self.__vartofieldtitle.iteritems(): filterinfo[0] = filterinfo[0].replace( "%%%s" % var, Utils.Protect(fieldtitle)) filterinfo[0] = outputstring(filterinfo[0], masklist, deletecolon=False) filterinfo[0] = filterinfo[0].replace(":", tableheadinbetween) filtercriteria = [] for i in range(5): if self.__fieldlist[i] <> None and self.__rellist[i] <> None: filtercriteria.append \ (outputstring(self.__vartofieldtitle[self.__fieldlist[i]], masklist)) filtercriteria[-1] += " " + reltext[self.__rellist[i]] filtercriteria[-1] += " " + outputstring( self.__vallist[i], masklist) if filtercriteria <> []: filterinfo[1] = " and ".join(filtercriteria) filterinfo[2] = self.__sortkey.replace(" ", ", ") for var, fieldtitle in self.__vartofieldtitle.iteritems(): filterinfo[2] = filterinfo[2].replace( "%%%s" % var, outputstring(fieldtitle, masklist)) filterinfo[3] = Utils.LocalTimeString() return filterinfo, filteroutput
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