solve a bug of validate
This commit is contained in:
parent
10c756a884
commit
450cef168b
|
@ -213,18 +213,6 @@ class Action(Thing):
|
|||
args[INHERIT_COND] = cls.id == Action.id
|
||||
return args
|
||||
|
||||
@validates('end_time')
|
||||
def validate_end_time(self, _, end_time: datetime):
|
||||
if self.start_time and end_time < self.start_time:
|
||||
raise ValidationError('The action cannot finish before it starts.')
|
||||
return end_time
|
||||
|
||||
@validates('start_time')
|
||||
def validate_start_time(self, _, start_time: datetime):
|
||||
if self.end_time and start_time > self.end_time:
|
||||
raise ValidationError('The action cannot start after it finished.')
|
||||
return start_time
|
||||
|
||||
@property
|
||||
def date_str(self):
|
||||
return '{:%c}'.format(self.end_time)
|
||||
|
|
|
@ -55,6 +55,10 @@ class Action(Thing):
|
|||
if 'start_time' in data and data['start_time'] < unix_time:
|
||||
data['start_time'] = unix_time
|
||||
|
||||
if data.get('end_time') and data.get('start_time'):
|
||||
if data['start_time'] > data['end_time']:
|
||||
raise ValidationError('The action cannot finish before it starts.')
|
||||
|
||||
|
||||
class ActionWithOneDevice(Action):
|
||||
__doc__ = m.ActionWithOneDevice.__doc__
|
||||
|
|
Reference in a new issue