Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add handling of 'past' to formfields

  • Loading branch information...
commit aac260f9c6904e6282cfd409826d8fb564dfc33d 1 parent a6dff8b
@evdb authored
Showing with 9 additions and 1 deletion.
  1. +9 −1 django_date_extensions/fields.py
View
10 django_date_extensions/fields.py
@@ -15,7 +15,7 @@ def __init__(self, year=0, month=0, day=0, future=False, past=False):
elif future or past:
d = None
if year or month or day:
- raise ValueError("Future dates can have no year, month or day")
+ raise ValueError("Future or past dates can have no year, month or day")
elif year and month and day:
d = date(year, month, day)
elif year and month:
@@ -118,6 +118,8 @@ def to_python(self, value):
if value == 'future':
return ApproximateDate(future=True)
+ if value == 'past':
+ return ApproximateDate(past=True)
if not ansi_date_re.search(value):
raise ValidationError('Enter a valid date in YYYY-MM-DD format.')
@@ -139,6 +141,8 @@ def get_db_prep_value(self, value, connection=None, prepared=False):
return dateformat.format(value, "Y-m-d")
if value == 'future':
return 'future'
+ if value == 'past':
+ return 'past'
if not ansi_date_re.search(value):
raise ValidationError('Enter a valid date in YYYY-MM-DD format.')
return value
@@ -183,6 +187,8 @@ def clean(self, value):
return None
if value == 'future':
return ApproximateDate(future=True)
+ if value == 'past':
+ return ApproximateDate(past=True)
if isinstance(value, ApproximateDate):
return value
value = re.sub('(?<=\d)(st|nd|rd|th)', '', value.strip())
@@ -232,6 +238,8 @@ def clean(self, value):
return None
if value == 'future':
return ApproximateDate(future=True)
+ if value == 'past':
+ return ApproximateDate(past=True)
if isinstance(value, datetime.datetime):
return value.date()
if isinstance(value, datetime.date):
Please sign in to comment.
Something went wrong with that request. Please try again.