From a0c9c5247546066678e86301fc7868d83942baf4 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 16 Apr 2021 01:14:01 +0000 Subject: [PATCH] Fix usages bug when member's not a Spaceport user --- apiserver/apiserver/api/models.py | 6 ++++-- apiserver/apiserver/api/serializers.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apiserver/apiserver/api/models.py b/apiserver/apiserver/api/models.py index e503a64..0a9517b 100644 --- a/apiserver/apiserver/api/models.py +++ b/apiserver/apiserver/api/models.py @@ -157,9 +157,11 @@ class StatsSpaceActivity(models.Model): class UsageTrack(models.Model): user = models.ForeignKey(User, related_name='usages', blank=True, null=True, on_delete=models.SET_NULL) - username = models.CharField(max_length=64) - devicename = models.CharField(max_length=64) + # member_id = models.IntegerField(blank=True, null=True) # restrict to current users for now + username = models.CharField(max_length=64) # allows us to match non-Spaceport users later + + devicename = models.CharField(max_length=64) start_time = models.DateTimeField(auto_now_add=True) num_seconds = models.IntegerField() diff --git a/apiserver/apiserver/api/serializers.py b/apiserver/apiserver/api/serializers.py index 1f5cec6..19cf018 100644 --- a/apiserver/apiserver/api/serializers.py +++ b/apiserver/apiserver/api/serializers.py @@ -303,7 +303,10 @@ class AdminSearchSerializer(serializers.Serializer): return serializer.data def get_usages(self, obj): - queryset = obj.user.usages.order_by('-start_time') + if obj.user: + queryset = obj.user.usages.order_by('-start_time') + else: + queryset = [] serializer = UsageSerializer(data=queryset, many=True) serializer.is_valid() return serializer.data