abra at Thu Dec 27 13:44:21 +04 2018

This commit is contained in:
2018-12-27 13:44:21 +04:00
parent da6260be34
commit 8109fc7619
9 changed files with 59 additions and 14 deletions

View File

@@ -26,14 +26,17 @@ class ActivityLog(models.Model):
logged_at = models.DateTimeField(auto_now_add=True)
def clean(self):
if self.start_time is None or self.end_time is None:
raise ValidationError(f'Не указано время: {self}')
if self.start_time >= self.end_time:
raise ValidationError(f'Illegal times: {self}')
raise ValidationError(f'Некорректное время: {self}')
for other_activity in ActivityLog.objects.filter(user=self.user).exclude(id=self.id):
l = max(self.start_time, other_activity.start_time)
r = min(self.end_time, other_activity.end_time)
if r > l:
raise ValidationError(f'Intersects with another activity: \n{self}\n{other_activity}\n{l}, {r}')
raise ValidationError(f'Пересекается с другой активностью: \n{self}\n{other_activity}\n{l}, {r}')
def __str__(self):
return f'ActivityLog[{self.user}, {self.activity}] {self.start_time}-{self.end_time} ({self.end_time - self.start_time})'