From f1a124c6751b8e0fef1b41012e93ca2e53f8038c Mon Sep 17 00:00:00 2001 From: jgw4sq <~jgw4sq@virginia.edu> Date: Wed, 9 Mar 2016 16:28:14 -0500 Subject: [PATCH 1/8] Created filter so non-normalized documents are no longer displayed with test case --- api/webview/views.py | 7 +++---- tests/test_api_views.py | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/api/webview/views.py b/api/webview/views.py index bc077f54..4d561932 100644 --- a/api/webview/views.py +++ b/api/webview/views.py @@ -28,9 +28,8 @@ def perform_create(self, serializer): def get_queryset(self): """ Return all documents """ - return Document.objects.all() - - + queryset= Document.objects.all().exclude(normalized=None) + return queryset class DocumentsFromSource(generics.ListAPIView): """ List all documents from a particular source @@ -44,7 +43,7 @@ def perform_create(self, serializer): def get_queryset(self): """ Return queryset based on source """ - return Document.objects.filter(source=self.kwargs['source']) + return Document.objects.filter(source=self.kwargs['source']).exclude(normalized=None) @api_view(['GET']) diff --git a/tests/test_api_views.py b/tests/test_api_views.py index b903140c..e496f450 100644 --- a/tests/test_api_views.py +++ b/tests/test_api_views.py @@ -6,6 +6,7 @@ from rest_framework.test import APIRequestFactory from api.webview.views import DocumentList, status, institutions +from api.webview.models import Document django.setup() @@ -60,4 +61,24 @@ def test_institutions(self): ) response = view(request) self.assertEqual(response.status_code, 200) + def test_exclude_non_normalized_documents(self): + view = DocumentList.as_view() + create_document(source="bad",normalized=None) + create_document(source="good",normalized="This is Normalized") + request = self.factory.get( + '/documents/' + ) + response = view(request) + self.assertNotContains(response, "bad", + status_code=200) + + +def create_document(source,normalized): + return Document.objects.create(source= source,normalized= normalized) + + + + + + From ff288b29ac11dbadcf51aab49012a2080c0cdc2c Mon Sep 17 00:00:00 2001 From: jgw4sq <~jgw4sq@virginia.edu> Date: Wed, 9 Mar 2016 16:43:09 -0500 Subject: [PATCH 2/8] Fixed python formatting errors in previous push of filter for non normalized data --- api/webview/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/webview/views.py b/api/webview/views.py index 4d561932..e8197b1d 100644 --- a/api/webview/views.py +++ b/api/webview/views.py @@ -28,8 +28,10 @@ def perform_create(self, serializer): def get_queryset(self): """ Return all documents """ - queryset= Document.objects.all().exclude(normalized=None) + queryset = Document.objects.all().exclude(normalized=None) return queryset + + class DocumentsFromSource(generics.ListAPIView): """ List all documents from a particular source From 7570a2f5b6747b08aad7c83d7edba5e9c6a161c9 Mon Sep 17 00:00:00 2001 From: jgw4sq <~jgw4sq@virginia.edu> Date: Wed, 9 Mar 2016 16:48:27 -0500 Subject: [PATCH 3/8] fixed more python formatting errors for non normalized filter --- api/webview/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/webview/views.py b/api/webview/views.py index e8197b1d..37a70688 100644 --- a/api/webview/views.py +++ b/api/webview/views.py @@ -31,7 +31,7 @@ def get_queryset(self): queryset = Document.objects.all().exclude(normalized=None) return queryset - + class DocumentsFromSource(generics.ListAPIView): """ List all documents from a particular source From 0306d4a76dccb482d3c00cf30010f1a2cca9224c Mon Sep 17 00:00:00 2001 From: L33t Hax04 Date: Thu, 10 Mar 2016 10:29:48 -0500 Subject: [PATCH 4/8] documents now ordered by providerUpdatedDateTime --- api/webview/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/webview/views.py b/api/webview/views.py index bc077f54..f3d9f56d 100644 --- a/api/webview/views.py +++ b/api/webview/views.py @@ -28,7 +28,7 @@ def perform_create(self, serializer): def get_queryset(self): """ Return all documents """ - return Document.objects.all() + return Document.objects.all().order_by('providerUpdatedDateTime') class DocumentsFromSource(generics.ListAPIView): From 0a4afaa330319ebc165298aa334e945002cff6c3 Mon Sep 17 00:00:00 2001 From: erinspace Date: Fri, 11 Mar 2016 10:52:00 -0500 Subject: [PATCH 5/8] remove some extra spaces --- tests/test_api_views.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test_api_views.py b/tests/test_api_views.py index e496f450..5fca5518 100644 --- a/tests/test_api_views.py +++ b/tests/test_api_views.py @@ -76,9 +76,3 @@ def test_exclude_non_normalized_documents(self): def create_document(source,normalized): return Document.objects.create(source= source,normalized= normalized) - - - - - - From 654d6f722a68079140aea92e77b56f5d6e8f70f5 Mon Sep 17 00:00:00 2001 From: erinspace Date: Fri, 11 Mar 2016 10:52:24 -0500 Subject: [PATCH 6/8] And add an extra space --- tests/test_api_views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_api_views.py b/tests/test_api_views.py index 5fca5518..353543e6 100644 --- a/tests/test_api_views.py +++ b/tests/test_api_views.py @@ -61,6 +61,7 @@ def test_institutions(self): ) response = view(request) self.assertEqual(response.status_code, 200) + def test_exclude_non_normalized_documents(self): view = DocumentList.as_view() create_document(source="bad",normalized=None) From 6fbf51548c8ec46ec2536e68e68766d78c11bdac Mon Sep 17 00:00:00 2001 From: erinspace Date: Fri, 11 Mar 2016 10:53:02 -0500 Subject: [PATCH 7/8] And a bit more spacing --- tests/test_api_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_api_views.py b/tests/test_api_views.py index 353543e6..f541dc81 100644 --- a/tests/test_api_views.py +++ b/tests/test_api_views.py @@ -75,5 +75,5 @@ def test_exclude_non_normalized_documents(self): def create_document(source,normalized): - return Document.objects.create(source= source,normalized= normalized) + return Document.objects.create(source=source, normalized=normalized) From 115240bfa0ddab372c4ebcee0babdb573abe6eab Mon Sep 17 00:00:00 2001 From: erinspace Date: Fri, 11 Mar 2016 10:59:53 -0500 Subject: [PATCH 8/8] Also include providerUpdatedDateTime on docs from source --- api/webview/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/webview/views.py b/api/webview/views.py index 2e1a85fb..e55d4f4f 100644 --- a/api/webview/views.py +++ b/api/webview/views.py @@ -44,7 +44,7 @@ def perform_create(self, serializer): def get_queryset(self): """ Return queryset based on source """ - return Document.objects.filter(source=self.kwargs['source']).exclude(normalized=None) + return Document.objects.filter(source=self.kwargs['source']).order_by('providerUpdatedDateTime').exclude(normalized=None) @api_view(['GET'])