diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 02045be9..107be562 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -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) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index bca1d8db..df93b107 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -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__