示例#1
0
 def best_template(self):
     gt = GroupTemplate(None,self.term)
     for e in self.elements:
         gt.add_patterns(e.when,e)
     gt.calculate_reduction()
     gt.restrict_to_term(self.term)
     return gt
示例#2
0
 def to_templated_secular_display(self, fp, group, type='lecture'):
     gt = GroupTemplate(None)
     gt.add_patterns(fp)
     gt.calculate_reduction(True)
     out = []
     for (_, _, (pattern, mult)) in gt.get_patterns_raw(False):
         if pattern is None:
             # just multiplier, should be just "x lectures"
             row = "%d %s, %s" % (mult, util.plural(type), gt.template
                                  )  # XXX proper plurals
         elif mult is None:
             # traditional pattern, expand codes sensibly
             row = "%s %s" % (util.plural(type),
                              self.atoms_to_secular(fp.patterns(), True))
         else:
             # start date and multiplier
             pp = copy.deepcopy(gt.template)
             pp.setAllYear()
             row = "%s %s, starting on %s, %s" % (mult, util.plural(type),
                                                  self.atoms_to_secular(
                                                      [pattern], False), pp)
         out.append(row)
     prefix = ''
     if group is not None:
         prefix = "%s term, " % term_names[group.term]
     return prefix + ", ".join(out)
示例#3
0
文件: year.py 项目: ieb/timetables
 def to_templated_secular_display(self,fp,group,type= 'lecture'):
     gt = GroupTemplate(None)
     gt.add_patterns(fp)
     gt.calculate_reduction(True)
     out = []
     for (_,_,(pattern,mult)) in gt.get_patterns_raw(False):
         if pattern is None:
             # just multiplier, should be just "x lectures"
             row = "%d %s, %s" % (mult,util.plural(type),gt.template) # XXX proper plurals
         elif mult is None:
             # traditional pattern, expand codes sensibly
             row = "%s %s" % (util.plural(type),self.atoms_to_secular(fp.patterns(),True))
         else:
             # start date and multiplier
             pp = copy.deepcopy(gt.template)
             pp.setAllYear()
             row = "%s %s, starting on %s, %s" % (mult,util.plural(type),self.atoms_to_secular([pattern],False),pp)
         out.append(row)
     prefix = ''
     if group is not None:
         prefix = "%s term, " % term_names[group.term]
     return prefix+", ".join(out)