sources/ldap: fix API error when source has not synced yet

This commit is contained in:
Jens Langhammer 2021-02-27 16:29:36 +01:00
parent d2a35eb8de
commit a2e69bd250

View file

@ -1,5 +1,6 @@
"""Source API Views""" """Source API Views"""
from datetime import datetime from datetime import datetime
from time import time
from django.core.cache import cache from django.core.cache import cache
from django.db.models.base import Model from django.db.models.base import Model
@ -68,7 +69,7 @@ class LDAPSourceViewSet(ModelViewSet):
def sync_status(self, request: Request, slug: str) -> Response: def sync_status(self, request: Request, slug: str) -> Response:
"""Get source's sync status""" """Get source's sync status"""
source = self.get_object() source = self.get_object()
last_sync = cache.get(source.state_cache_prefix("last_sync"), None) last_sync = cache.get(source.state_cache_prefix("last_sync"), time())
return Response( return Response(
LDAPSourceSyncStatusSerializer( LDAPSourceSyncStatusSerializer(
{"last_sync": datetime.fromtimestamp(last_sync)} {"last_sync": datetime.fromtimestamp(last_sync)}