Commit 52d87ab0 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Implement last_fetch for site

parent bab920d0
......@@ -11,14 +11,5 @@ class DeploymentsView(generics.RetrieveAPIView):
def get_object(self):
d = models.Deployments()
d.services = {}
for service in self.request.user.site.services.all():
# deployments with ssh keys
d.services[service.name] = (
service.deployments
.filter(user__user_type='oidcuser')
.exclude(ssh_keys=None)
)
d.services = self.request.user.site.clientapi_get_deployments()
return d
......@@ -4,6 +4,7 @@ from django.conf import settings
from django.dispatch import receiver
from rest_framework.authtoken.models import Token
from django.db.models.signals import post_save
from datetime import datetime
class User(AbstractUser):
......@@ -47,10 +48,25 @@ class Site(models.Model):
null=True)
name = models.CharField(max_length=150, unique=True)
description = models.TextField(max_length=300, blank=True)
last_fetch = models.DateTimeField(default=datetime.utcfromtimestamp(0))
def __str__(self):
return self.name
def clientapi_get_deployments(self):
services = {}
for service in self.services.all():
# deployments with ssh keys
services[service.name] = (
service.deployments
.filter(user__user_type='oidcuser')
.exclude(ssh_keys=None)
)
self.last_fetch = datetime.now()
self.save()
return services
class Service(models.Model):
name = models.CharField(max_length=150, unique=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment