
import time
import calendar
calendar.setfirstweekday(calendar.SUNDAY)

from nevow import tags as T
from nevow import rend


class ScheduleRoot(rend.Page):
    docFactory = rend.htmlfile('ScheduleRoot.html')

    def data_currentMonth(self, context, data):
        curtime = time.localtime()
        year, month = curtime[0], curtime[1]
        label = "%s/%s" % (month, year)
        return label, calendar.monthcalendar(year, month)

    def render_month(self, context, data):
        label, month = data
        calendarBody = context.onePattern('calendarBody')
        weekPattern = context.patterns('calendarWeek')
        dayPattern = context.patterns('calendarDay')
        for week in month:
            currentWeek = weekPattern()
            calendarBody.children.append(currentWeek)
            for day in week:
                currentDay = dayPattern()
                if day != 0:
                    currentDay.children.append(str(day))
                currentWeek.children.append(currentDay)

        context.fillSlot('label', label)
        context.fillSlot('calendarBody', calendarBody)
        return context.tag

s('label', label)
        context.fillSlots('calendarBody', calendarBody)
        return context.tag

    def render_delete(self, context, data):
        return ''


