diff --git a/onadata/apps/api/tests/viewsets/test_data_viewset.py b/onadata/apps/api/tests/viewsets/test_data_viewset.py index 57c80ea009..9af305a68f 100644 --- a/onadata/apps/api/tests/viewsets/test_data_viewset.py +++ b/onadata/apps/api/tests/viewsets/test_data_viewset.py @@ -441,31 +441,23 @@ def test_data_pagination(self): request = self.factory.get('/', **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) - self.assertTrue(response.has_header('X-total')) - self.assertEqual(int(response.get('X-total')), 4) self.assertEqual(len(response.data), 4) request = self.factory.get('/', data={"page": "1", "page_size": 2}, **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) - self.assertTrue(response.has_header('X-total')) - self.assertEqual(int(response.get('X-total')), 4) self.assertEqual(len(response.data), 2) request = self.factory.get('/', data={"page_size": "3"}, **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) - self.assertTrue(response.has_header('X-total')) - self.assertEqual(int(response.get('X-total')), 4) self.assertEqual(len(response.data), 3) request = self.factory.get( '/', data={"page": "1", "page_size": "2"}, **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) - self.assertTrue(response.has_header('X-total')) - self.assertEqual(int(response.get('X-total')), 4) self.assertEqual(len(response.data), 2) # invalid page returns a 404 @@ -722,8 +714,6 @@ def test_data_public(self): request = self.factory.get('/', **self.extra) response = view(request, pk='public') self.assertEqual(response.status_code, 200) - self.assertTrue(response.has_header('X-total')) - self.assertEqual(int(response.get('X-total')), 0) self.assertEqual(response.data, []) self.xform.shared_data = True self.xform.save() @@ -731,8 +721,6 @@ def test_data_public(self): data = _data_list(formid) response = view(request, pk='public') self.assertEqual(response.status_code, 200) - self.assertTrue(response.has_header('X-total')) - self.assertEqual(int(response.get('X-total')), 1) self.assertEqual(response.data, data) def test_data_public_anon_user(self): @@ -870,8 +858,6 @@ def test_data_with_query_parameter(self): request = self.factory.get('/?query=%s' % query_str, **self.extra) response = view(request, pk=formid) self.assertEqual(response.status_code, 200) - self.assertTrue(response.has_header('X-total')) - self.assertEqual(int(response.get('X-total')), 1) self.assertEqual(len(response.data), 1) submission_time = instance.date_created.strftime(MONGO_STRFTIME) diff --git a/onadata/apps/api/viewsets/data_viewset.py b/onadata/apps/api/viewsets/data_viewset.py index e74bf68650..9219df8728 100644 --- a/onadata/apps/api/viewsets/data_viewset.py +++ b/onadata/apps/api/viewsets/data_viewset.py @@ -38,7 +38,6 @@ AuthenticateHeaderMixin from onadata.libs.mixins.cache_control_mixin import CacheControlMixin from onadata.libs.mixins.etags_mixin import ETagsMixin -from onadata.libs.mixins.total_header_mixin import TotalHeaderMixin from onadata.libs.pagination import StandardPageNumberPagination from onadata.libs.serializers.data_serializer import DataSerializer from onadata.libs.serializers.data_serializer import ( @@ -87,7 +86,6 @@ def delete_instance(instance): class DataViewSet(AnonymousUserPublicFormsMixin, AuthenticateHeaderMixin, ETagsMixin, CacheControlMixin, - TotalHeaderMixin, BaseViewset, ModelViewSet): """ diff --git a/onadata/apps/api/viewsets/open_data_viewset.py b/onadata/apps/api/viewsets/open_data_viewset.py index 57df1decf5..5db82901c5 100644 --- a/onadata/apps/api/viewsets/open_data_viewset.py +++ b/onadata/apps/api/viewsets/open_data_viewset.py @@ -18,7 +18,6 @@ from onadata.libs.data import parse_int from onadata.libs.mixins.cache_control_mixin import CacheControlMixin from onadata.libs.mixins.etags_mixin import ETagsMixin -from onadata.libs.mixins.total_header_mixin import TotalHeaderMixin from onadata.libs.pagination import StandardPageNumberPagination from onadata.libs.serializers.data_serializer import DataInstanceSerializer from onadata.libs.serializers.open_data_serializer import OpenDataSerializer @@ -33,7 +32,7 @@ def replace_special_characters_with_underscores(data): return [re.sub(r"\W", r"_", a) for a in data] -class OpenDataViewSet(ETagsMixin, CacheControlMixin, TotalHeaderMixin, +class OpenDataViewSet(ETagsMixin, CacheControlMixin, BaseViewset, ModelViewSet): permission_classes = (OpenDataViewSetPermissions, ) queryset = OpenData.objects.filter() diff --git a/onadata/apps/main/views.py b/onadata/apps/main/views.py index edb7a89780..374e462694 100644 --- a/onadata/apps/main/views.py +++ b/onadata/apps/main/views.py @@ -532,7 +532,6 @@ def api(request, username=None, id_string=None): response_text = ("%s(%s)" % (callback, response_text)) response = HttpResponse(response_text, content_type='application/json') - response['X-total'] = total_records add_cors_headers(response) return response diff --git a/onadata/apps/viewer/static/js/data_view.js b/onadata/apps/viewer/static/js/data_view.js index 37db7e34ea..2af7754261 100644 --- a/onadata/apps/viewer/static/js/data_view.js +++ b/onadata/apps/viewer/static/js/data_view.js @@ -31,7 +31,9 @@ pageSize: "limit" }, parseState: function (resp, queryParams, state, options) { - return {totalRecords: parseInt(options.xhr.getResponseHeader("X-total"))}; + // Removing X-total + // {totalRecords: parseInt(options.xhr.getResponseHeader("X-total"))}; + return 0; }, initialize: function (models, options) { // set the url diff --git a/onadata/libs/mixins/total_header_mixin.py b/onadata/libs/mixins/total_header_mixin.py deleted file mode 100644 index e730d6cfc9..0000000000 --- a/onadata/libs/mixins/total_header_mixin.py +++ /dev/null @@ -1,9 +0,0 @@ -class TotalHeaderMixin(object): - total_count = None - - def finalize_response(self, request, response, *args, **kwargs): - if self.total_count is not None: - self.headers.update({'X-total': self.total_count}) - - return super(TotalHeaderMixin, self).finalize_response( - request, response, *args, **kwargs)