我正在使用 django 创建一个 calendar-app。日历必须是垂直的

I`m creating a calendar-app using django. Calendar must be vertical

现在我已经意识到了这一点 django-calendar . But i need vertical calendar(抱歉,没有找到任何英文版本)在左边我们有工作日 headers 和顶部的月份名称。

我开始覆盖 python-calendar HTMLCalendar 方法。我想编写新的 formatweekdayrow 方法,它会生成一排星期一、星期二....星期日。但是我被卡住了,因为我不完全理解这些所有方法是如何工作的。

所以问题是我应该考虑一下我写 formatweekdayrow 的想法,还是不能像那样制作垂直日历?或者可能有一些更简单、更智能的方法来做到这一点?

我重写了几个方法,得到了我需要的

class Vertical(HTMLCalendar):

    def formatweekrow(self, theweeks, daynum):
        """
        Return a complete week as a table row.
        """
        v = []
        s = v.append
        s('<tr>')
        for theweek in theweeks:
            for (d, wd) in theweek:
                if wd == daynum:
                    s(self.formatday(d, wd))
        s('</tr>')
        return ''.join(v)

    def formatmonth(self, theyear, themonth, withyear=True):
        """
        Return a formatted month as a table.
        """
        cnt = 0
        v = []
        theweeks = self.monthdays2calendar(theyear, themonth)
        a = v.append
        a('<table border="0" cellpadding="0" cellspacing="0"     class="">')
        a('\n')
        a(self.formatmonthname(theyear, themonth, withyear=withyear))
        a('\n')
        a(self.formatweekheader())
        a('\n')
        while cnt < 7:
            a(self.formatweekrow(theweeks, cnt))
            a('\n')
            cnt += 1
        a('</table>')
        a('\n')
        return ''.join(v)