Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add count parameter to media endpoint #1665

Merged
merged 9 commits into from
Aug 13, 2019

Conversation

RayceeM
Copy link
Contributor

@RayceeM RayceeM commented Jul 26, 2019

Fixes issue #1664

@RayceeM RayceeM requested review from ukanga and lincmba July 26, 2019 14:28
Signed-off-by: Racheal Mwatela <[email protected]>
Copy link
Member

@ukanga ukanga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the appropriate way to add non standard headers would be a header that starts with X-. Seeing the need to have a total count makes me think we probably should implement pagination properly as there are different ways this information could have been exposed. See https://www.django-rest-framework.org/api-guide/pagination/ for more information. We also have the StandardPageNumberPagination class in https://github.com/onaio/onadata/blob/master/onadata/libs/pagination.py#L4.

Signed-off-by: Racheal Mwatela <[email protected]>
Signed-off-by: Racheal Mwatela <[email protected]>
- Get total count of attachments per form

Signed-off-by: Racheal Mwatela <[email protected]>
@RayceeM RayceeM requested a review from ukanga July 31, 2019 14:49
@onaio onaio deleted a comment Aug 1, 2019
def count(self, request, *args, **kwargs):
response = {}
xform = request.query_params.get('xform')
total_count = Attachment.objects.filter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is best we rely on using self.filter_queryset(self.get_queryset()) so that we maintain the queryset and filters to applied to it by the viewset. Hence

data = {
  "count":  self.filter_queryset(self.get_queryset()).count()
}

return Response(data=data)

Signed-off-by: Racheal Mwatela <[email protected]>
@RayceeM RayceeM requested a review from ukanga August 1, 2019 08:02
@RayceeM RayceeM changed the title Add total attachment records on header Add count parameter on media endpoint Aug 5, 2019
@RayceeM RayceeM changed the title Add count parameter on media endpoint Add count parameter to media endpoint Aug 5, 2019
@ukanga ukanga merged commit 2fcde60 into master Aug 13, 2019
@ukanga ukanga deleted the Add-total-attachment-records-on-header branch August 13, 2019 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants