示例#1
0
 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
示例#2
0
 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': '&gt;',
         'greaterequal': '&gt;=',
         'less': '&lt;',
         'lessequal': '&lt;=',
         'notequal': 'not equal to',
         'begins': 'begins with',
         'contains': 'contains',
         'ends': 'ends with'
     }
     masklist = [('&', '&amp;'), ('<', '&lt;'), ('>', '&gt;')]
     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