Beispiel #1
0
 def allocated_hours_for_week(self, day):
     week, next_week = utils.get_week_window(day)
     allocs = AssignmentAllocation.objects
     allocs = allocs.filter(assignment__user=self.user)
     allocs = allocs.filter(date__gte=week, date__lt=next_week)
     hours = allocs.aggregate(s=Sum('hours'))['s']
     return hours or 0
 def test_week_window(self):
     """ Test generation of weekly window with given date """
     #Tuesday
     day = datetime.date(2011, 2, 1)
     expected_start = datetime.date(2011, 1, 31)
     expected_end = datetime.date(2011, 2, 7)
     start, end = utils.get_week_window(day)
     self.assertEqual(start.toordinal(), expected_start.toordinal())
     self.assertEqual(end.toordinal(), expected_end.toordinal())
 def test_week_window(self):
     """ Test generation of weekly window with given date """
     #Tuesday
     day = datetime.date(2011, 2, 1)
     expected_start = datetime.date(2011, 1, 31)
     expected_end = datetime.date(2011, 2, 7)
     start, end = utils.get_week_window(day)
     self.assertEqual(start.toordinal(), expected_start.toordinal())
     self.assertEqual(end.toordinal(), expected_end.toordinal())
Beispiel #4
0
 def this_weeks_priority_number(self):
     """
     Only works if already filtered to the current week. Otherwise groups
     outside the range will be listed as ongoing instead of befor or after.
     """
     if not hasattr(self, '_priority_type'):
         weeks = utils.get_week_window(datetime.datetime.now())
         if self.end_date < weeks[1].date() \
         and self.end_date >= weeks[0].date():
             self._priority_type = 0
         elif self.start_date < weeks[1].date() \
         and self.start_date >= weeks[0].date():
             self._priority_type = 1
         else:
             self._priority_type = 2
     return self._priority_type
Beispiel #5
0
 def this_weeks_priority_number(self):
     """
     Only works if already filtered to the current week. Otherwise groups
     outside the range will be listed as ongoing instead of befor or after.
     """
     if not hasattr(self, '_priority_type'):
         weeks = utils.get_week_window(timezone.now())
         try:
             end_date = self.end_date.date()
             start_date = self.start_date.date()
         except:
             end_date = self.end_date
             start_date = self.start_date
         if end_date < weeks[1].date() \
         and end_date >= weeks[0].date():
             self._priority_type = 0
         elif start_date < weeks[1].date() \
         and start_date >= weeks[0].date():
             self._priority_type = 1
         else:
             self._priority_type = 2
     return self._priority_type