Example #1
0
def isWeekCommencingDate(value):
    """
    Validates that a date falls on the first day of the week.
    """
    if not is_week_commencing_date(value):
        raise ValidationError(
            'Enter a date which falls on the first day of the week.')
Example #2
0
 def testIsWeekCommencingDate(self):
     self.assertTrue(is_week_commencing_date(date(2007, 7, 23)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 24)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 25)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 26)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 27)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 28)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 29)))
Example #3
0
 def testIsWeekCommencingDate(self):
     self.assertTrue(is_week_commencing_date(date(2007, 7, 23)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 24)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 25)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 26)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 27)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 28)))
     self.assertFalse(is_week_commencing_date(date(2007, 7, 29)))
Example #4
0
def week_commencing_date_or_404(year, month, day):
    """
    Converts date URL parameters to a date, raising ``Http404`` if the
    date is invalid or does not represent the first day of the week.
    """
    try:
        date = datetime.date(*time.strptime(year+month+day, '%Y%m%d')[:3])
        if not is_week_commencing_date(date):
            raise Http404
    except ValueError:
        raise Http404
    return date
Example #5
0
def isWeekCommencingDate(value):
    """
    Validates that a date falls on the first day of the week.
    """
    if not is_week_commencing_date(value):
        raise ValidationError("Enter a date which falls on the first day of the week.")