From f3e0a58b63db77d110ac953d9d56f74e7ec0a9b8 Mon Sep 17 00:00:00 2001 From: Tomasz Knapik <hi@tmkn.org> Date: Thu, 31 Jan 2019 11:46:48 +0000 Subject: [PATCH] Add rounds and labs list API view --- opentech/apply/funds/api_views.py | 14 ++++++++++ opentech/apply/funds/serializers.py | 14 ++++++++++ opentech/apply/funds/urls.py | 2 ++ package-lock.json | 41 ++++++++--------------------- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/opentech/apply/funds/api_views.py b/opentech/apply/funds/api_views.py index a0978a8bd..ff78e3f48 100644 --- a/opentech/apply/funds/api_views.py +++ b/opentech/apply/funds/api_views.py @@ -97,6 +97,20 @@ class RoundLabDetail(generics.RetrieveAPIView): def get_object(self): return super().get_object().specific + def get_serializer(self, *args, **kwargs): + serializer_class = self.get_serializer_class() + kwargs['context'] = self.get_serializer_context() + kwargs['show_workflow'] = True + return serializer_class(*args, **kwargs) + + +class RoundLabList(generics.ListAPIView): + queryset = RoundsAndLabs.objects.specific() + serializer_class = RoundLabSerializer + permission_classes = ( + permissions.IsAuthenticated, IsApplyStaffUser, + ) + class CommentFilter(filters.FilterSet): since = filters.DateTimeFilter(field_name="timestamp", lookup_expr='gte') diff --git a/opentech/apply/funds/serializers.py b/opentech/apply/funds/serializers.py index e96dda318..58fc8d4d4 100644 --- a/opentech/apply/funds/serializers.py +++ b/opentech/apply/funds/serializers.py @@ -25,11 +25,18 @@ class ReviewSummarySerializer(serializers.Field): class SubmissionListSerializer(serializers.ModelSerializer): url = serializers.HyperlinkedIdentityField(view_name='funds:api:submissions:detail') + round = serializers.SerializerMethodField() class Meta: model = ApplicationSubmission fields = ('id', 'title', 'status', 'url', 'round') + def get_round(self, obj): + """ + This gets round or lab ID. + """ + return obj.round_id or obj.page_id + class SubmissionDetailSerializer(serializers.ModelSerializer): questions = serializers.SerializerMethodField() @@ -84,6 +91,13 @@ class RoundLabSerializer(serializers.ModelSerializer): model = Page fields = ('id', 'title', 'workflow') + def __init__(self, *args, **kwargs): + show_workflow = kwargs.pop('show_workflow', False) + if not show_workflow: + del self.fields['workflow'] + super().__init__(*args, **kwargs) + + def get_workflow(self, obj): return [ { diff --git a/opentech/apply/funds/urls.py b/opentech/apply/funds/urls.py index 1339981cb..4a8712ba9 100644 --- a/opentech/apply/funds/urls.py +++ b/opentech/apply/funds/urls.py @@ -16,6 +16,7 @@ from .api_views import ( CommentList, CommentListCreate, RoundLabDetail, + RoundLabList, SubmissionAction, SubmissionList, SubmissionDetail, @@ -54,6 +55,7 @@ api_urls = ([ path('<int:pk>/comments/', CommentListCreate.as_view(), name='comments'), ], 'submissions'))), path('rounds/', include(([ + path('', RoundLabList.as_view(), name='list'), path('<int:pk>/', RoundLabDetail.as_view(), name='detail'), ], 'rounds'))), path('comments/', include(([ diff --git a/package-lock.json b/package-lock.json index f386d671c..6553c6995 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4389,8 +4389,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -4408,13 +4407,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4427,18 +4424,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -4541,8 +4535,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -4552,7 +4545,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4565,20 +4557,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4595,7 +4584,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -4668,8 +4656,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -4679,7 +4666,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4755,8 +4741,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -4786,7 +4771,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4804,7 +4788,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4843,13 +4826,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, -- GitLab