Commits

Nikolaj Sjujskij committed 19ecacf

Move date HTML class logic out of templates, introduce dictionary for that

  • Participants
  • Parent commits 62316fc

Comments (0)

Files changed (2)

 
 import calendar
 import datetime
+import itertools
 import time
 
 from psycopg2.extras import DictCursor
     # create calendars
     calendar.setfirstweekday(calendar.MONDAY)
     month, year = (basedate.month, basedate.year)
+    week_cal = calendar.monthcalendar(year, month)
+    # keep HTML classes for calendar cells
+    day_classes = {}
+    # 5th and 6th elements are holidays, zeroes should be dropped
+    for holiday in filter(None,
+                          itertools.chain(*[week[5:] for week in week_cal])):
+        day_classes[holiday] = ['holiday']
+    # today has its special HTML class
+    if today_day:
+        day_classes.setdefault(today_day, []).append('today')
+
     context = {
                'devs': DEVLIST,
                'devlist': DEVS,
                'next_year': next_year if next_year != today.year else "",
                'prev_month': prev_month,
                'prev_year': prev_year if prev_year != today.year else "",
-               'calendar': calendar.monthcalendar(year, month),
+               'calendar': week_cal,
                'weekhdr': calendar.weekheader(3).split(' '),
                'stylesheet': stylesheet,
                'other_ssheet': other_ssheet,
                'month_name': calendar.month_name[month],
                'month': month,
                'year': year if year != today.year else "",
-               'today': today_day,
+               'day_classes': day_classes,
                'opened': opened,
                'closed': closed,
                }

templates/index.html

         <tr>
             {% for day in week %}
             {% set daystr = daytmpl % day %}
-            <td
-                {%- if today == day %} class="today"
-                {%- elif loop.index > 5 %} class="holiday"{% endif %}>
+            <td class="{{ day_classes[day] | join(' ') }}">
                 <span class="day">{{ day or '' }}</span>
                 {% for trac, tickets in usertckts.pop(daystr, {}).items() %}
                     <span class="project_name">{{ trac }}</span>