Several view fixes in bowler:

CollectionView.get() correctly passes username and listname through to activity_get().
This fixes a regression.

CollectionView.get() dereferences the result of activity_get() if it's an ActivityResponse.
This should have been part of commit d02042f2 but I missed it.
This fixes a regression.

CollectionView.get() uses len() to get the length of the result of activity_get(), and
not the result's count() method. This allows the result to be a list as well as a queryset.

CollectionView.activity_get()'s logging is slightly tidier.
status-serialisers
Marnanel Thurman 2020-09-19 15:00:48 +01:00
rodzic 197362b2c3
commit 4b513fb817
1 zmienionych plików z 14 dodań i 11 usunięć

Wyświetl plik

@ -265,9 +265,12 @@ class CollectionView(generics.GenericAPIView):
listname = None,
*args, **kwargs):
items = self.activity_get(username, listname,
items = self.activity_get(request, username, listname,
*args, **kwargs)
if isinstance(items, ActivityResponse):
items = items.activity_value
# XXX assert that items.ordered
our_url = request.build_absolute_uri()
@ -306,7 +309,7 @@ class CollectionView(generics.GenericAPIView):
# Index page.
logger.debug(" -- it's a request for the index")
count = items.count()
count = len(items)
result = {
"@context": ATSIGN_CONTEXT,
@ -330,15 +333,13 @@ class CollectionView(generics.GenericAPIView):
return self._to_httpresponse(result)
def activity_get(self,
request,
def activity_get(self, request,
username,
listname = None,
*args, **kwargs):
from kepi.trilby_api.models import LocalPerson, Status
username = kwargs.get('username', None)
listname = kwargs.get('listname')
logger.debug('Finding user %s\'s %s collection',
username, self.listname)
@ -372,15 +373,17 @@ class CollectionView(generics.GenericAPIView):
if result is None:
if self.default_to_existing:
logger.debug(' -- does not exist; returning empty')
logger.debug(' -- collection does not exist')
return ActivityResponse(Status.objects.none())
result = []
else:
logger.debug(' -- does not exist; 404')
logger.debug(' -- collection does not exist; 404')
raise Http404()
return ActivityResponse(result)
result = ActivityResponse(result)
logger.debug(' -- result: %s', result)
return result
def _to_httpresponse(self, data):