web/views/timetable.py
branchtls-sprint
changeset 1132 96752791c2b6
parent 889 609edca88406
child 1133 8a409ea0c9ec
equal deleted inserted replaced
1131:544609e83317 1132:96752791c2b6
    36         users = []
    36         users = []
    37         users_max = {}
    37         users_max = {}
    38 
    38 
    39         # XXX: try refactoring with calendar.py:OneMonthCal
    39         # XXX: try refactoring with calendar.py:OneMonthCal
    40         for row in xrange(self.rset.rowcount):
    40         for row in xrange(self.rset.rowcount):
    41             task = self.rset.get_entity(row,0)
    41             task = self.rset.get_entity(row, 0)
    42             if len(self.rset[row])>1:
    42             if len(self.rset[row])>1:
    43                 user = self.rset.get_entity(row,1)
    43                 user = self.rset.get_entity(row, 1)
    44             else:
    44             else:
    45                 user = u"*"
    45                 user = u"*"
    46             the_dates = []
    46             the_dates = []
    47             if task.start and task.stop:
    47             if task.start and task.stop:
    48                 if task.start.absdate == task.stop.absdate:
    48                 if task.start.absdate == task.stop.absdate:
    53                 the_dates.append(task.start)
    53                 the_dates.append(task.start)
    54             elif task.stop:
    54             elif task.stop:
    55                 the_dates.append(task.stop)
    55                 the_dates.append(task.stop)
    56             for d in the_dates:
    56             for d in the_dates:
    57                 d_users = dates.setdefault(d, {})
    57                 d_users = dates.setdefault(d, {})
    58                 u_tasks = d_users.setdefault(user,set())
    58                 u_tasks = d_users.setdefault(user, set())
    59                 u_tasks.add( task )
    59                 u_tasks.add( task )
    60                 task_max = users_max.setdefault(user,0)
    60                 task_max = users_max.setdefault(user, 0)
    61                 if len(u_tasks)>task_max:
    61                 if len(u_tasks)>task_max:
    62                     users_max[user] = len(u_tasks)
    62                     users_max[user] = len(u_tasks)
    63             if user not in users:
    63             if user not in users:
    64                 # keep original ordering
    64                 # keep original ordering
    65                 users.append(user)
    65                 users.append(user)
    69         date_max = max(dates)
    69         date_max = max(dates)
    70         #users = list(sorted(users, key=lambda u:u.login))
    70         #users = list(sorted(users, key=lambda u:u.login))
    71 
    71 
    72         rows = []
    72         rows = []
    73         # colors here are class names defined in cubicweb.css
    73         # colors here are class names defined in cubicweb.css
    74         colors = [ "col%x"%i for i in range(12) ]
    74         colors = ["col%x" % i for i in xrange(12)]
    75         next_color_index = 0
    75         next_color_index = 0
    76 
    76 
    77         visited_tasks = {} # holds a description of a task for a user
    77         visited_tasks = {} # holds a description of a task for a user
    78         task_colors = {}   # remember a color assigned to a task
    78         task_colors = {}   # remember a color assigned to a task
    79         for date in date_range(date_min, date_max):
    79         for date in date_range(date_min, date_max):
    98                 for key in postpone:
    98                 for key in postpone:
    99                     # to every 'new' task we must affect a color
    99                     # to every 'new' task we must affect a color
   100                     # (which must be the same for every user concerned
   100                     # (which must be the same for every user concerned
   101                     # by the task)
   101                     # by the task)
   102                     task, user = key
   102                     task, user = key
   103                     for i,t in enumerate(user_columns):
   103                     for i, t in enumerate(user_columns):
   104                         if t is None:
   104                         if t is None:
   105                             if task in task_colors:
   105                             if task in task_colors:
   106                                 color = task_colors[task]
   106                                 color = task_colors[task]
   107                             else:
   107                             else:
   108                                 color = colors[next_color_index]
   108                                 color = colors[next_color_index]
   126         self.render_col_headers(users, widths)
   126         self.render_col_headers(users, widths)
   127         self.render_rows(rows)
   127         self.render_rows(rows)
   128         self.w(u'</table>')
   128         self.w(u'</table>')
   129         self.w(u'</div>\n')
   129         self.w(u'</div>\n')
   130 
   130 
   131     def render_col_headers(self,users,widths):
   131     def render_col_headers(self, users, widths):
   132         """ render column headers """
   132         """ render column headers """
   133         self.w(u'<tr class="header">\n')
   133         self.w(u'<tr class="header">\n')
   134 
   134 
   135         self.w(u'<th class="ttdate">&nbsp;</th>\n')
   135         self.w(u'<th class="ttdate">&nbsp;</th>\n')
   136         columns = []
   136         columns = []
   137         for user,width in zip(users,widths):
   137         for user, width in zip(users, widths):
   138             self.w(u'<th colspan="%s">' % max(MIN_COLS,width))
   138             self.w(u'<th colspan="%s">' % max(MIN_COLS, width))
   139             if user!=u"*":
   139             if user != u"*":
   140                 user.view('secondary',w=self.w)
   140                 user.view('secondary', w=self.w)
   141             else:
   141             else:
   142                 self.w(user)
   142                 self.w(user)
   143             self.w(u'</th>')
   143             self.w(u'</th>')
   144         self.w(u'</tr>\n')
   144         self.w(u'</tr>\n')
   145         return columns
   145         return columns
   162             if empty_line and previous_is_empty:
   162             if empty_line and previous_is_empty:
   163                 continue
   163                 continue
   164             previous_is_empty = False
   164             previous_is_empty = False
   165 
   165 
   166             klass = "even"
   166             klass = "even"
   167             if date.day_of_week in (5,6) and not empty_line:
   167             if date.day_of_week in (5, 6) and not empty_line:
   168                 klass = "odd"
   168                 klass = "odd"
   169             self.w(u'<tr class="%s">' % klass)
   169             self.w(u'<tr class="%s">' % klass)
   170             odd = not odd
   170             odd = not odd
   171 
   171 
   172             if not empty_line:
   172             if not empty_line: