Skip to content

Commit be36862

Browse files
committed
Including source/collection summaries in user/org pins listing
1 parent 94c08d5 commit be36862

4 files changed

Lines changed: 20 additions & 10 deletions

File tree

core/collections/serializers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ class Meta:
225225

226226
def __init__(self, *args, **kwargs):
227227
params = get(kwargs, 'context.request.query_params')
228-
self.query_params = params.dict() if params else dict()
228+
229+
self.query_params = dict()
230+
if params:
231+
self.query_params = params if isinstance(params, dict) else params.dict()
229232
self.include_summary = self.query_params.get(INCLUDE_SUMMARY) in ['true', True]
230233
self.include_client_configs = self.query_params.get(INCLUDE_CLIENT_CONFIGS) in ['true', True]
231234

core/pins/serializers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from rest_framework import serializers
44
from rest_framework.fields import SerializerMethodField
55

6+
from core.common.constants import INCLUDE_SUMMARY
67
from core.pins.models import Pin
78

89

@@ -13,10 +14,12 @@ def build_resource_data(obj):
1314
resource_type = resource.resource_type.lower()
1415
if resource_type == 'source':
1516
from core.sources.serializers import SourceDetailSerializer
16-
return SourceDetailSerializer(resource).data
17+
return SourceDetailSerializer(
18+
resource, context=dict(request=dict(query_params={INCLUDE_SUMMARY: True}))).data
1719
if resource_type == 'collection':
1820
from core.collections.serializers import CollectionDetailSerializer
19-
return CollectionDetailSerializer(resource).data
21+
return CollectionDetailSerializer(
22+
resource, context=dict(request=dict(query_params={INCLUDE_SUMMARY: True}))).data
2023
if resource_type == 'organization':
2124
from core.orgs.serializers import OrganizationDetailSerializer
2225
return OrganizationDetailSerializer(resource).data

core/pins/views.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.shortcuts import get_object_or_404
22
from rest_framework import status
3-
from rest_framework.generics import RetrieveAPIView, DestroyAPIView, UpdateAPIView
3+
from rest_framework.generics import ListAPIView, \
4+
RetrieveUpdateDestroyAPIView
45
from rest_framework.permissions import IsAuthenticatedOrReadOnly
56
from rest_framework.response import Response
67

@@ -16,6 +17,9 @@ class PinBaseView(BaseAPIView):
1617
serializer_class = PinSerializer
1718
permission_classes = (IsAuthenticatedOrReadOnly,)
1819

20+
def filter_queryset(self, queryset):
21+
return queryset
22+
1923
def get_parent_type(self):
2024
if self.kwargs.get('user_is_self') or 'user' in self.kwargs:
2125
return 'user'
@@ -47,10 +51,7 @@ def get_queryset(self):
4751
).select_related('organization', 'user').prefetch_related('resource')
4852

4953

50-
class PinListView(PinBaseView):
51-
def get(self, request, *args, **kwargs): # pylint: disable=unused-argument
52-
return Response(self.get_serializer(self.get_queryset(), many=True).data)
53-
54+
class PinListView(PinBaseView, ListAPIView):
5455
def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
5556
parent = self.get_parent()
5657
if not parent:
@@ -69,7 +70,7 @@ def post(self, request, *args, **kwargs): # pylint: disable=unused-argument
6970
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
7071

7172

72-
class PinRetrieveUpdateDestroyView(PinBaseView, UpdateAPIView, RetrieveAPIView, DestroyAPIView):
73+
class PinRetrieveUpdateDestroyView(PinBaseView, RetrieveUpdateDestroyAPIView):
7374
def get_serializer_class(self):
7475
if self.request.method == 'PUT':
7576
return PinUpdateSerializer

core/sources/serializers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,10 @@ class Meta:
234234

235235
def __init__(self, *args, **kwargs):
236236
params = get(kwargs, 'context.request.query_params')
237-
self.query_params = params.dict() if params else dict()
237+
238+
self.query_params = dict()
239+
if params:
240+
self.query_params = params if isinstance(params, dict) else params.dict()
238241
self.include_summary = self.query_params.get(INCLUDE_SUMMARY) in ['true', True]
239242
self.include_client_configs = self.query_params.get(INCLUDE_CLIENT_CONFIGS) in ['true', True]
240243
self.include_hierarchy_root = self.query_params.get(INCLUDE_HIERARCHY_ROOT) in ['true', True]

0 commit comments

Comments
 (0)