Browse files

Fix _schedule_assignment helper

  • Loading branch information...
1 parent ce418df commit 144146c2d20e1308ad41c7213b5a64e0e81a75cc @matthiask committed Sep 12, 2011
Showing with 27 additions and 13 deletions.
  1. +27 −13 views/scheduling.py
View
40 views/scheduling.py
@@ -84,6 +84,7 @@ def __init__(self, assignments, date_range):
(self.date_range[1] - self.date_from).days // 7 + 1)
self.data_weeks = SortedDict()
+ self.date_list = list(daterange(self.date_from, self.date_until))
def add_waitlist(self, queryset):
self.waitlist = queryset
@@ -120,19 +121,32 @@ def weeks(self):
return ret
def _schedule_assignment(self, date_from, date_until):
- week_from = max(0, (date_from - self.date_from).days // 7)
- week_until = (date_until - self.date_from).days // 7
-
- weeks = [[0, '']] * week_from
- weeks.append([1, date_from.day])
-
- if calendar_week(date_from) != calendar_week(date_until):
- weeks.extend([[1, '']] * (week_until - week_from - 1))
- weeks.append([1, date_until.day])
-
- weeks.extend([[0, '']] * (self.week_count - week_until - 1))
-
- return weeks[self.date_slice]
+ weeks = []
+ cw = None
+ inside = False
+
+ for day in self.date_list:
+ new_cw = calendar_week(day)
+ if new_cw == cw:
+ continue
+ else:
+ cw = new_cw
+
+ if date_from <= day <= date_until:
+ if inside:
+ weeks.append([1, ''])
+ else:
+ inside = True
+ if calendar_week(day) == calendar_week(date_from):
+ weeks.append([1, date_from.day])
+ else:
+ weeks.append([1, '']) # assignment has not started this week
+ else:
+ if inside:
+ inside = False
+ weeks[-1][1] = date_until.day
+ weeks.append([0, ''])
+ return weeks
def assignments(self):
assignments_dict = SortedDict()

0 comments on commit 144146c

Please sign in to comment.