Skip to content

Commit

Permalink
Add media_all_received as a data filter parameter
Browse files Browse the repository at this point in the history
Fix: #1105
  • Loading branch information
moshthepitt committed Aug 28, 2017
1 parent 6f65cc7 commit bdbb9f1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 63 deletions.
110 changes: 61 additions & 49 deletions docs/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,21 +384,21 @@ All Filters Options
============================= ===================================
Filter Description
============================= ===================================
**$date_created__year** Exact year e.g. 2017
**$date_created__year__lt** year Less than
**$date_created__year__lte** year Less than or Equal to
**$date_created__year__gt** year Greater than
**$date_created__year__gte** year Greater than or Equal to
**$date_created__month** Exact month e.g. 11
**$date_created__month__lt** Month Less than
**$date_created__month__lte** Month Less than or Equal to
**$date_created__month__gt** Month Greater than
**$date_created__month__gte** Month Greater than or Equal to
**$date_created__day** Exact day e.g. 13
**$date_created__day__lt** Day Less than
**$date_created__day__lte** Day Less than or Equal to
**$date_created__day__gt** Day Greater than
**$date_created__day__gte** Day Greater than or Equal to
**date_created__year** Exact year e.g. 2017
**date_created__year__lt** Year Less than
**date_created__year__lte** Year Less than or Equal to
**date_created__year__gt** Year Greater than
**date_created__year__gte** Year Greater than or Equal to
**date_created__month** Exact month e.g. 11
**date_created__month__lt** Month Less than
**date_created__month__lte** Month Less than or Equal to
**date_created__month__gt** Month Greater than
**date_created__month__gte** Month Greater than or Equal to
**date_created__day** Exact day e.g. 13
**date_created__day__lt** Day Less than
**date_created__day__lte** Day Less than or Equal to
**date_created__day__gt** Day Greater than
**date_created__day__gte** Day Greater than or Equal to
============================= ===================================

Filter options can be chained to narrow results even further.
Expand All @@ -420,21 +420,21 @@ All Filters Options
============================= ===================================
Filter Description
============================= ===================================
**$date_modified__year** Exact year e.g. 2017
**$date_modified__year__lt** year Less than
**$date_modified__year__lte** year Less than or Equal to
**$date_modified__year__gt** year Greater than
**$date_modified__year__gte** year Greater than or Equal to
**$date_modified__month** Exact month e.g. 11
**$date_modified__month__lt** Month Less than
**$date_modified__month__lte** Month Less than or Equal to
**$date_modified__month__gt** Month Greater than
**$date_modified__month__gte** Month Greater than or Equal to
**$date_modified__day** Exact day e.g. 13
**$date_modified__day__lt** Day Less than
**$date_modified__day__lte** Day Less than or Equal to
**$date_modified__day__gt** Day Greater than
**$date_modified__day__gte** Day Greater than or Equal to
**date_modified__year** Exact year e.g. 2017
**date_modified__year__lt** Year Less than
**date_modified__year__lte** Year Less than or Equal to
**date_modified__year__gt** Year Greater than
**date_modified__year__gte** Year Greater than or Equal to
**date_modified__month** Exact month e.g. 11
**date_modified__month__lt** Month Less than
**date_modified__month__lte** Month Less than or Equal to
**date_modified__month__gt** Month Greater than
**date_modified__month__gte** Month Greater than or Equal to
**date_modified__day** Exact day e.g. 13
**date_modified__day__lt** Day Less than
**date_modified__day__lte** Day Less than or Equal to
**date_modified__day__gt** Day Greater than
**date_modified__day__gte** Day Greater than or Equal to
============================= ===================================

Filter options can be chained to narrow results even further.
Expand All @@ -456,21 +456,21 @@ All Filters Options
============================= ===================================
Filter Description
============================= ===================================
**$last_edited__year** Exact year e.g. 2017
**$last_edited__year__lt** year Less than
**$last_edited__year__lte** year Less than or Equal to
**$last_edited__year__gt** year Greater than
**$last_edited__year__gte** year Greater than or Equal to
**$last_edited__month** Exact month e.g. 11
**$last_edited__month__lt** Month Less than
**$last_edited__month__lte** Month Less than or Equal to
**$last_edited__month__gt** Month Greater than
**$last_edited__month__gte** Month Greater than or Equal to
**$last_edited__day** Exact day e.g. 13
**$last_edited__day__lt** Day Less than
**$last_edited__day__lte** Day Less than or Equal to
**$last_edited__day__gt** Day Greater than
**$last_edited__day__gte** Day Greater than or Equal to
**last_edited__year** Exact year e.g. 2017
**last_edited__year__lt** Year Less than
**last_edited__year__lte** Year Less than or Equal to
**last_edited__year__gt** Year Greater than
**last_edited__year__gte** Year Greater than or Equal to
**last_edited__month** Exact month e.g. 11
**last_edited__month__lt** Month Less than
**last_edited__month__lte** Month Less than or Equal to
**last_edited__month__gt** Month Greater than
**last_edited__month__gte** Month Greater than or Equal to
**last_edited__day** Exact day e.g. 13
**last_edited__day__lt** Day Less than
**last_edited__day__lte** Day Less than or Equal to
**last_edited__day__gt** Day Greater than
**last_edited__day__gte** Day Greater than or Equal to
============================= ===================================

Filter options can be chained to narrow results even further.
Expand Down Expand Up @@ -528,8 +528,8 @@ All Filters Options
=================== ===================================
Filter Description
=================== ===================================
**$user__id** user's id
**$user__username** user's username
**user__id** user's id
**user__username** user's username
=================== ===================================


Expand All @@ -549,8 +549,8 @@ All Filters Options
=========================== ===================================
Filter Description
=========================== ===================================
**$submitted_by__id** submitted_by user's id
**$submitted_by__username** submitted_by user's username
**submitted_by__id** submitted_by user's id
**submitted_by__username** submitted_by user's username
=========================== ===================================


Expand All @@ -566,6 +566,18 @@ Example
curl -X GET https://api.ona.io/api/v1/data/22845?survey_type__slug=fortytwo


Query submitted data of a specific form using media_all_received
----------------------------------------------------------------

Filter submissions using the media_all_received field

Example
^^^^^^^^^
::

curl -X GET https://api.ona.io/api/v1/data/22845?media_all_received=true


Query submitted data of a specific form using Tags
--------------------------------------------------
Provides a list of json submitted data for a specific data/form matching specific
Expand Down
38 changes: 24 additions & 14 deletions onadata/apps/api/tests/viewsets/test_data_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,8 +2011,7 @@ def test_filterset(self):
response = view(request, pk=formid, format='json')
self.assertEqual(
len(response.data),
Instance.objects.filter(
uuid=instance.uuid).count()
Instance.objects.filter(uuid=instance.uuid).count()
)
# ## Test user
# all the forms are owned by a user named bob
Expand All @@ -2024,10 +2023,7 @@ def test_filterset(self):
**self.extra)
view = DataViewSet.as_view({'get': 'list'})
response = view(request, pk=formid, format='json')
self.assertEqual(
len(response.data),
0
)
self.assertEqual(len(response.data), 0)
# we make one instance belong to user_alice and then filter for that
instance.user = user_alice
instance.save()
Expand All @@ -2038,8 +2034,7 @@ def test_filterset(self):
response = view(request, pk=formid, format='json')
self.assertEqual(
len(response.data),
Instance.objects.filter(
user__username=user_alice.username).count()
Instance.objects.filter(user__username=user_alice.username).count()
)
# ## Test submitted_by
# submitted_by is mapped to the user field
Expand All @@ -2050,10 +2045,7 @@ def test_filterset(self):
**self.extra)
view = DataViewSet.as_view({'get': 'list'})
response = view(request, pk=formid, format='json')
self.assertEqual(
len(response.data),
0
)
self.assertEqual(len(response.data), 0)
# we make one instance belong to user_mosh and then filter for that
instance.user = user_mosh
instance.save()
Expand All @@ -2065,8 +2057,7 @@ def test_filterset(self):
response = view(request, pk=formid, format='json')
self.assertEqual(
len(response.data),
Instance.objects.filter(
user__username=user_mosh.username).count()
Instance.objects.filter(user__username=user_mosh.username).count()
)
# ## Test survey_type
# all the instances created have the same survey_type
Expand All @@ -2084,6 +2075,25 @@ def test_filterset(self):
Instance.objects.filter(
survey_type__slug=new_survey_type.slug).count()
)
# ## Test all_media_received
# all the instances have media_all_received == True
request = self.factory.get('/',
{'media_all_received': 'true'},
**self.extra)
view = DataViewSet.as_view({'get': 'list'})
response = view(request, pk=formid, format='json')
self.assertEqual(
len(response.data),
Instance.objects.filter(media_all_received=True).count())
# we set one to False and filter for it
instance.media_all_received = False
instance.save()
request = self.factory.get('/',
{'media_all_received': 'false'},
**self.extra)
view = DataViewSet.as_view({'get': 'list'})
response = view(request, pk=formid, format='json')
self.assertEqual(len(response.data), 1)


class TestOSM(TestAbstractViewSet):
Expand Down
1 change: 1 addition & 0 deletions onadata/libs/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Meta:
fields = {'date_created': date_field_lookups,
'date_modified': date_field_lookups,
'last_edited': date_field_lookups,
'media_all_received': ['exact'],
'status': ['exact'],
'submitted_by__id': ['exact'],
'submitted_by__username': ['exact'],
Expand Down

0 comments on commit bdbb9f1

Please sign in to comment.