コード例 #1
0
    def test_week(self):
        """
        week should return first and last day of the week the given day belongs to.
        """
        correct_mon = date(year=2015, month=6, day=29)
        correct_sun = date(year=2015, month=7, day=5)

        # check week boundary - monday
        test = date(year=2015, month=6, day=29)
        (res_mon, res_sun) = helpers.week(test)
        self.assertTrue(res_mon == correct_mon and res_sun == correct_sun)

        # check week boundary - sunday
        test = date(year=2015, month=7, day=5)
        (res_mon, res_sun) = helpers.week(test)
        self.assertTrue(res_mon == correct_mon and res_sun == correct_sun)

        # check middle of the week
        test = date(year=2015, month=7, day=1)
        (res_mon, res_sun) = helpers.week(test)
        self.assertTrue(res_mon == correct_mon and res_sun == correct_sun)
コード例 #2
0
 def get(self, request, **kwargs):
     self.week_form = self.form_class(self.request.GET)
     # get the day and compute the week - if there is a valid non-empty input
     if self.week_form.is_valid() \
         and 'day' in request.GET \
         and request.GET['day'] != '':
         self.chosen_week = h.week(
             datetime.datetime.strptime(
                 request.GET['day'],
                 '%d.%m.%Y').date()
         )
     return super(WeekListView, self).get(self, request, **kwargs)