Verify necessary fields before running model validation tests.

This commit is contained in:
Christopher Charbonneau Wells 2017-11-07 07:07:51 -05:00
parent 490e07c381
commit 1c5278cebf
2 changed files with 7 additions and 6 deletions

View File

@ -36,9 +36,10 @@ def validate_unique_period(queryset, model):
"""
if model.id:
queryset = queryset.exclude(id=model.id)
if model.start and model.end:
if queryset.filter(start__lte=model.end, end__gte=model.start):
raise ValidationError(
'Another entry already exists within the specified time period.',
'Another entry intersects the specified time period.',
code='period_intersection')
@ -49,7 +50,7 @@ def validate_time(time, field_name):
:param field_name: the name of the field being checked.
:return:
"""
if time > timezone.localtime():
if time and time > timezone.localtime():
raise ValidationError(
{field_name: 'Date/time can not be in the future.'},
code='time_invalid')

View File

@ -238,4 +238,4 @@ class FormsTestCase(TestCase):
page,
'form',
None,
'Another entry already exists within the specified time period.')
'Another entry intersects the specified time period.')