web/views/calendar.py
branchtls-sprint
changeset 1132 96752791c2b6
parent 1033 f5be65616a31
child 1149 1e19b6ef53a1
equal deleted inserted replaced
1131:544609e83317 1132:96752791c2b6
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 
     7 
     8 from datetime import datetime, date, timedelta
     8 from datetime import datetime, date, timedelta
     9 
     9 
    10 from vobject import iCalendar, icalendar
    10 from vobject import iCalendar
    11 
    11 
    12 from logilab.mtconverter import html_escape
    12 from logilab.mtconverter import html_escape
    13 
    13 
    14 from cubicweb.interfaces import ICalendarable
    14 from cubicweb.interfaces import ICalendarable
    15 from cubicweb.selectors import implements
    15 from cubicweb.selectors import implements
   153         month_dates = list(date_range(firstday, lastday))
   153         month_dates = list(date_range(firstday, lastday))
   154         dates = {}
   154         dates = {}
   155         users = []
   155         users = []
   156         task_max = 0
   156         task_max = 0
   157         for row in xrange(self.rset.rowcount):
   157         for row in xrange(self.rset.rowcount):
   158             task = self.rset.get_entity(row,0)
   158             task = self.rset.get_entity(row, 0)
   159             if len(self.rset[row]) > 1 and self.rset.description[row][1] == 'EUser':
   159             if len(self.rset[row]) > 1 and self.rset.description[row][1] == 'EUser':
   160                 user = self.rset.get_entity(row,1)
   160                 user = self.rset.get_entity(row, 1)
   161             else:
   161             else:
   162                 user = None
   162                 user = None
   163             the_dates = []
   163             the_dates = []
   164             tstart = todate(task.start)
   164             tstart = todate(task.start)
   165             if tstart:
   165             if tstart:
   181             if not the_dates:
   181             if not the_dates:
   182                 continue
   182                 continue
   183             
   183             
   184             for d in the_dates:
   184             for d in the_dates:
   185                 d_tasks = dates.setdefault((d.year, d.month, d.day), {})
   185                 d_tasks = dates.setdefault((d.year, d.month, d.day), {})
   186                 t_users = d_tasks.setdefault(task,set())
   186                 t_users = d_tasks.setdefault(task, set())
   187                 t_users.add( user )
   187                 t_users.add( user )
   188                 if len(d_tasks)>task_max:
   188                 if len(d_tasks) > task_max:
   189                     task_max = len(d_tasks)
   189                     task_max = len(d_tasks)
   190 
   190 
   191         days = []
   191         days = []
   192         nrows = max(3,task_max)
   192         nrows = max(3, task_max)
   193         # colors here are class names defined in cubicweb.css
   193         # colors here are class names defined in cubicweb.css
   194         colors = [ "col%x"%i for i in range(12) ]
   194         colors = [ "col%x" % i for i in range(12) ]
   195         next_color_index = 0
   195         next_color_index = 0
   196 
   196 
   197         visited_tasks = {} # holds a description of a task
   197         visited_tasks = {} # holds a description of a task
   198         task_colors = {}   # remember a color assigned to a task
   198         task_colors = {}   # remember a color assigned to a task
   199         for mdate in month_dates:
   199         for mdate in month_dates:
   211                     postpone.append(task)
   211                     postpone.append(task)
   212             for task in postpone:
   212             for task in postpone:
   213                 # to every 'new' task we must affect a color
   213                 # to every 'new' task we must affect a color
   214                 # (which must be the same for every user concerned
   214                 # (which must be the same for every user concerned
   215                 # by the task)
   215                 # by the task)
   216                 for i,t in enumerate(rows):
   216                 for i, t in enumerate(rows):
   217                     if t is None:
   217                     if t is None:
   218                         if task in task_colors:
   218                         if task in task_colors:
   219                             color = task_colors[task]
   219                             color = task_colors[task]
   220                         else:
   220                         else:
   221                             color = colors[next_color_index]
   221                             color = colors[next_color_index]
   332         # week - 1 since we get week number > 0 while we want it to start from 0
   332         # week - 1 since we get week number > 0 while we want it to start from 0
   333         first_day_of_week = todate(strptime('%s-%s-1' % (year, week - 1), '%Y-%U-%w'))
   333         first_day_of_week = todate(strptime('%s-%s-1' % (year, week - 1), '%Y-%U-%w'))
   334         lastday = first_day_of_week + timedelta(6)
   334         lastday = first_day_of_week + timedelta(6)
   335         firstday = first_day_of_week
   335         firstday = first_day_of_week
   336         dates = [[] for i in range(7)]
   336         dates = [[] for i in range(7)]
   337         task_max = 0
       
   338         task_colors = {}   # remember a color assigned to a task
   337         task_colors = {}   # remember a color assigned to a task
   339         # colors here are class names defined in cubicweb.css
   338         # colors here are class names defined in cubicweb.css
   340         colors = [ "col%x"%i for i in range(12) ]
   339         colors = [ "col%x" % i for i in range(12) ]
   341         next_color_index = 0
   340         next_color_index = 0
   342         done_tasks = []
   341         done_tasks = []
   343         for row in xrange(self.rset.rowcount):
   342         for row in xrange(self.rset.rowcount):
   344             task = self.rset.get_entity(row,0)
   343             task = self.rset.get_entity(row, 0)
   345             if task in done_tasks:
   344             if task in done_tasks:
   346                 continue
   345                 continue
   347             done_tasks.append(task)
   346             done_tasks.append(task)
   348             the_dates = []
   347             the_dates = []
   349             tstart = todate(task.start)
   348             tstart = todate(task.start)