Show errors in last week

This commit is contained in:
George Lacey 2022-04-06 13:39:37 +01:00
parent a4cae2ee2c
commit 5952578754
2 changed files with 6 additions and 3 deletions

View File

@ -74,10 +74,13 @@ class Repo(models.Model):
size = self.size() size = self.size()
return bytes_to_string(size) return bytes_to_string(size)
def recent_errors(self, days: int = 7, limit: int = 3): def recent_errors(self, days: int = 7, limit: int = None):
days_ago = (datetime.utcnow() - timedelta(days=days)) days_ago = (datetime.utcnow() - timedelta(days=days))
errors = self.label.errors.all().filter(time__gt=days_ago) errors = self.label.errors.all().filter(time__gt=days_ago)
return errors[:limit] if limit is None:
return errors
else:
return errors[:limit]
def get_archive_days(self, count: int = 31): def get_archive_days(self, count: int = 31):
current_day = datetime.utcnow().day current_day = datetime.utcnow().day

View File

@ -11,7 +11,7 @@ def repo_json(request, repo_label):
repo_dict = {'location': repo.location, repo_dict = {'location': repo.location,
'latest_backup': repo.last_backup(), 'latest_backup': repo.last_backup(),
'size': repo.size_string(), 'size': repo.size_string(),
'recent_errors': "not implemented", 'recent_errors': len(repo.recent_errors()),
'warning': repo.warning(), 'warning': repo.warning(),
'error': repo.error()} 'error': repo.error()}
return JsonResponse(repo_dict) return JsonResponse(repo_dict)