diff -r 56217e741939 -r fd943737d630 web/views/calendar.py --- a/web/views/calendar.py Thu Apr 30 14:17:22 2009 +0200 +++ b/web/views/calendar.py Thu Apr 30 14:17:34 2009 +0200 @@ -29,7 +29,7 @@ _('june'), _('july'), _('august'), _('september'), _('october'), _('november'), _('december') ) - + # Calendar views ############################################################## @@ -99,11 +99,11 @@ self.w('
' % self.req._('from %(date)s' % {'date': self.format_date(task.start)})) self.w('
' % self.req._('to %(date)s' % {'date': self.format_date(task.stop)})) self.w('
to %s'%self.format_date(task.stop)) - + class CalendarLargeItemView(CalendarItemView): id = 'calendarlargeitem' - + class _TaskEntry(object): def __init__(self, task, color, index=0): self.task = task @@ -116,11 +116,12 @@ if self.task.start.hour > 7 and self.task.stop.hour < 20: return True return False - + def is_one_day_task(self): task = self.task return task.start and task.stop and task.start.isocalendar() == task.stop.isocalendar() - + + class OneMonthCal(EntityView): """At some point, this view will probably replace ampm calendars""" id = 'onemonthcal' @@ -179,7 +180,7 @@ min(tstop, lastday)) if not the_dates: continue - + for d in the_dates: d_tasks = dates.setdefault((d.year, d.month, d.day), {}) t_users = d_tasks.setdefault(task, set()) @@ -242,7 +243,7 @@ # output header self.w(u'%s%s%s%s%s%s%s' % tuple(self.req._(day) for day in WEEKDAYS)) - + # build calendar for mdate, task_rows in zip(month_dates, days): if mdate.weekday() == 0: @@ -272,7 +273,7 @@ self.w(u'' % classes) self.w(u'
' % classes) self.w(u'
%s
' % celldate.day) - + if len(self.rset.column_types(0)) == 1: etype = list(self.rset.column_types(0))[0] url = self.build_url(vid='creation', etype=etype, @@ -314,7 +315,7 @@ __select__ = implements(ICalendarable) need_navigation = False title = _('one week') - + def call(self): self.req.add_js( ('cubicweb.ajax.js', 'cubicweb.calendar.js') ) self.req.add_css('cubicweb.calendar.css') @@ -327,7 +328,7 @@ if 'week' in self.req.form: week = int(self.req.form['week']) else: - week = _today.isocalendar()[1] + week = _today.isocalendar()[1] # week - 1 since we get week number > 0 while we want it to start from 0 first_day_of_week = todate(strptime('%s-%s-1' % (year, week - 1), '%Y-%U-%w')) lastday = first_day_of_week + timedelta(6) @@ -359,16 +360,16 @@ min(tstop, lastday)) if not the_dates: continue - + if task not in task_colors: task_colors[task] = colors[next_color_index] next_color_index = (next_color_index+1) % len(colors) - + for d in the_dates: day = d.weekday() - task_descr = _TaskEntry(task, task_colors[task]) + task_descr = _TaskEntry(task, task_colors[task]) dates[day].append(task_descr) - + self.w(u'
') # build schedule self.w(u'') @@ -391,7 +392,7 @@ else: self.w(u'' % (self.req._(day), self.format_date(wdate))) self.w(u'') - + # build week calendar self.w(u'') self.w(u'') - + for i, day in enumerate(WEEKDAYS): wdate = first_day_of_week + timedelta(i) classes = "" @@ -423,7 +424,7 @@ self.w(u'
'% extra) for h in range(8, 20): self.w(u'
'%((h-7)*8)) - self.w(u'
') + self.w(u'
') if dates[i]: self._build_calendar_cell(wdate, dates[i]) self.w(u'') @@ -432,7 +433,7 @@ self.w(u'
%s
%s
') # column for hours @@ -399,9 +400,9 @@ for h in range(8, 20): self.w(u'
'%extra) self.w(u'%02d:00'%h) - self.w(u'
') + self.w(u'') self.w(u'
') self.w(u'
') self.w(u'
 
') - + def _build_calendar_cell(self, date, task_descrs): inday_tasks = [t for t in task_descrs if t.is_one_day_task() and t.in_working_hours()] wholeday_tasks = [t for t in task_descrs if not t.is_one_day_task()] @@ -474,7 +475,7 @@ stop_hour = min(20, task.stop.hour) if stop_hour < 20: stop_min = task.stop.minute - + height = 100.0*(stop_hour+stop_min/60.0-start_hour-start_min/60.0)/(20-8) top = 100.0*(start_hour+start_min/60.0-8)/(20-8) left = width*task_desc.index @@ -504,7 +505,7 @@ self.w(u'
') self.w(u'') - + def _prevnext_links(self, curdate): prevdate = curdate - timedelta(7) nextdate = curdate + timedelta(7)