def hours_by_category(self): hours = list(self.hours) category = attrgetter('getBudgetCategory') hours.sort(key=category) for category, hours in groupby(hours, category): yield dict(category=safe_unicode(category), sum=self.ettool.countHours(hours))
def hours_by_project(self): hours = list(self.hours) project = attrgetter('getProjectTitle') hours.sort(key=project) for project, hours in groupby(hours, project): hours = tuple(hours) sum = self.ettool.countHours(hours) yield dict(project=safe_unicode(project), category=hours[0].getBudgetCategory, sum=sum)
def __iter__(self): def getDeliverableTitle(key): return '' for (prtitle, pritems) in groupby( self.data, itemgetter('getProjectTitle')): # Yield a project, or reconstruct enough info project = pritems.next() next = [] # Used to put iterated item back into flow if project['portal_type'] != 'ExtropyProject': next = [project] project = dict(Title=safe_unicode(prtitle)) project['depth'] = 0 yield project for (phtitle, phitems) in groupby( chain(next, pritems), itemgetter('getPhaseTitle')): # Reconstruct enough info for a phase next = [phitems.next()] title = phtitle and safe_unicode(phtitle) or '' phase = dict(depth=1, Title=title, getURL=_reconstructURL(project, next[0])) yield phase for (dtitle, tasks) in groupby( chain(next, phitems), getDeliverableTitle): # Yield a deliverable, at least the title deliverable = tasks.next() next = [deliverable] if not dtitle: # Activities live in the phase, group together deliverable = dict(Title='Activities', getURL=phase['getURL']) else: deliverable = dict( Title=safe_unicode(dtitle), getURL=_reconstructURL(phase, deliverable)) deliverable['depth'] = 2 yield deliverable for item in chain(next, tasks): item['depth'] = 3 yield item