mirror of https://github.com/snachodog/mybuddy.git
Verify necessary fields before running model validation tests.
This commit is contained in:
parent
490e07c381
commit
1c5278cebf
|
@ -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')
|
||||
|
|
|
@ -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.')
|
||||
|
|
Loading…
Reference in New Issue