コード例 #1
0
ファイル: timesheet.py プロジェクト: zoranzaric/prickle
    def month(self, year, month):
        c.date = datetime.date(int(year), int(month), 1)
        c.title = "Timesheet summary for %s" % c.date.strftime("%B, %Y")
        c.timesheets = Timesheet.for_month(year, month)
        c.total_time = sum(t.duration for t in c.timesheets)
        c.total_fee = sum(t.fee for t in c.timesheets)
        c.invoice_column = True
        #FIXME: I'm really tired and suspect this is not the right way to do this
        project_summary = defaultdict(dict) 
        for timesheet in c.timesheets:
            project_summary[timesheet.project]['duration'] = \
                    project_summary[timesheet.project].setdefault(
                            'duration', 0) + timesheet.duration
            project_summary[timesheet.project]['fee'] = \
                    project_summary[timesheet.project].setdefault(
                            'fee', 0) + timesheet.fee

        c.project_summary = project_summary
        return render('/timesheet/month_summary.html')