added week calculations, refactor mocks
This commit is contained in:
@@ -42,6 +42,77 @@ class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||
return returnstr
|
||||
|
||||
|
||||
def oneweek(self,month,week):
|
||||
|
||||
start_day = None
|
||||
end_day = None
|
||||
|
||||
for (d, wd) in week:
|
||||
if d == 0:
|
||||
continue
|
||||
else:
|
||||
start_day = d
|
||||
break
|
||||
|
||||
|
||||
for (d, wd) in reversed(week):
|
||||
if d == 0:
|
||||
continue
|
||||
else:
|
||||
end_day = d
|
||||
break
|
||||
|
||||
|
||||
start = datetime.datetime(2020, month, start_day).replace(hour=0,
|
||||
minute=0,
|
||||
second=0)
|
||||
|
||||
end = datetime.datetime(2020, month, end_day).replace (hour=23,
|
||||
minute=59,
|
||||
second=59)
|
||||
|
||||
rows = get_period_totals( local_date(start),
|
||||
local_date(end))
|
||||
|
||||
returnstr = "<table class='totaltable'>"
|
||||
for row in rows:
|
||||
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(row["ws"],row["total"])
|
||||
|
||||
returnstr += "</table>"
|
||||
return returnstr
|
||||
|
||||
|
||||
# def formatmonthname(self, theyear, themonth, withyear=True):
|
||||
# """
|
||||
# Return a month name as a table row.
|
||||
# """
|
||||
# if withyear:
|
||||
# s = '%s %s' % (month_name[themonth], theyear)
|
||||
# else:
|
||||
# s = '%s' % month_name[themonth]
|
||||
# return '<tr><th colspan="8" class="%s">%s</th></tr>' % (
|
||||
# self.cssclass_month_head, s)
|
||||
|
||||
|
||||
def formatweekheader(self):
|
||||
"""
|
||||
Return a header for a week as a table row.
|
||||
"""
|
||||
s = ''.join(self.formatweekday(i) for i in self.iterweekdays())
|
||||
s += "<td>Week Totals</td>"
|
||||
return '<tr>%s</tr>' % s
|
||||
|
||||
|
||||
|
||||
def formatweek(self, theweek):
|
||||
"""
|
||||
Return a complete week as a table row.
|
||||
"""
|
||||
s = ''.join(self.formatday(d, wd) for (d, wd) in theweek)
|
||||
s += "<td>{}</td>".format(self.oneweek(self.dmmonth, theweek))
|
||||
return '<tr>%s</tr>' % s
|
||||
|
||||
|
||||
def formatday(self, day, weekday):
|
||||
"""
|
||||
Return a day as a table cell.
|
||||
|
||||
Reference in New Issue
Block a user