Set repo background colour based on backup status
This commit is contained in:
		
							parent
							
								
									395e03803f
								
							
						
					
					
						commit
						cb5ab6fdb8
					
				| 
						 | 
				
			
			@ -11,6 +11,26 @@ class Repo(models.Model):
 | 
			
		|||
    last_modified = models.DateTimeField()
 | 
			
		||||
    label = models.OneToOneField(Label, on_delete=models.CASCADE, unique=True)
 | 
			
		||||
 | 
			
		||||
    def warning(self):
 | 
			
		||||
        if self.error():
 | 
			
		||||
            return True
 | 
			
		||||
        else:
 | 
			
		||||
            latest_archive = self.latest_archive()
 | 
			
		||||
            if latest_archive.start > datetime.utcnow() - timedelta(hours=2):
 | 
			
		||||
                return False
 | 
			
		||||
            else:
 | 
			
		||||
                return True
 | 
			
		||||
 | 
			
		||||
    def error(self):
 | 
			
		||||
        latest_archive = self.latest_archive()
 | 
			
		||||
        if latest_archive is None or not self.archive_after_latest_error():
 | 
			
		||||
            return True
 | 
			
		||||
 | 
			
		||||
        if latest_archive.start > datetime.utcnow() - timedelta(hours=4):
 | 
			
		||||
            return False
 | 
			
		||||
        else:
 | 
			
		||||
            return True
 | 
			
		||||
 | 
			
		||||
    def archive_after_latest_error(self):
 | 
			
		||||
        latest_archive = self.latest_archive()
 | 
			
		||||
        latest_error = self.latest_error()
 | 
			
		||||
| 
						 | 
				
			
			@ -100,7 +120,7 @@ class Repo(models.Model):
 | 
			
		|||
        return ''.join(['H' if archive is not None else '-' for archive in archives])
 | 
			
		||||
 | 
			
		||||
    def hourly_archive_string(self):
 | 
			
		||||
        return ''.join(['H' if archive is not None else '-' for archive in self.hourly_archives(24)])
 | 
			
		||||
        return ''.join(['H' if archive is not None else '-' for archive in self.hourly_archives(48)])
 | 
			
		||||
 | 
			
		||||
    def monthly_archives(self, n_months: int = 12):
 | 
			
		||||
        archives = []
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,8 +26,8 @@
 | 
			
		|||
{% if repo_list %}
 | 
			
		||||
<div class="grid mx-auto d-flex justify-content-center flex-wrap">
 | 
			
		||||
    {% for repo in repo_list %}
 | 
			
		||||
    <div style="width: 600px;" class="repo-container shadow rounded bg-primary overflow-hidden
 | 
			
		||||
                {% if not repo.archive_after_latest_error %}bg-danger{% endif %}">
 | 
			
		||||
    <div style="width: 600px;" class="repo-container shadow rounded overflow-hidden
 | 
			
		||||
                {% if repo.error %}bg-danger{% elif repo.warning %}bg-warning{% else %}bg-primary{% endif %}">
 | 
			
		||||
        <div class="row me-1 overflow-hidden text-truncate">
 | 
			
		||||
            <h2 class="h2">{{ repo.label }}
 | 
			
		||||
                <small class="text-muted"> {{ repo.location }}</small>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user