from django import template from datetime import datetime register = template.Library() @register.filter(name='calendar_table') def calendar_table(value, arg): cal = {} dates = value.keys() dates.sort() for date in value: d, m, y = date.day, date.month, date.year if y not in cal: cal[y] = {} if m not in cal[y]: cal[y][m] = [] cal[y][m].append(d) result = '' for y in cal: result += "
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
' for i in range(days_in_month): if i in cal[y][m]: s = arg.replace('[Y]', "%.4d" % y).replace('[m]', "%.2d" % m).replace('[d]', "%.2d" % d) result += " | %d | " % (s, i + 1) else: result += "%d | " % (i + 1) w = (w + 1) % 7 if w == 0 and i + 1 < days_in_month: result += "||||
' result += ' |