A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
prevent date suggestion search if disabled
shamoonc6900c5d5127
diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.pyindex 2e8e96207..0a87bd95f 100644--- a/src/documents/tests/test_api.py+++ b/src/documents/tests/test_api.py@@ -1948,6 +1948,29 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):},)+ @mock.patch("documents.parsers.parse_date_generator")+ @override_settings(NUMBER_OF_SUGGESTED_DATES=0)+ def test_get_suggestions_dates_disabled(+ self,+ parse_date_generator,+ ):+ """+ GIVEN:+ - NUMBER_OF_SUGGESTED_DATES = 0 (disables feature)+ WHEN:+ - API reuqest for document suggestions+ THEN:+ - Dont check for suggested dates at all+ """+ doc = Document.objects.create(+ title="test",+ mime_type="application/pdf",+ content="this is an invoice from 12.04.2022!",+ )++ self.client.get(f"/api/documents/{doc.pk}/suggestions/")+ self.assertFalse(parse_date_generator.called)+def test_saved_views(self):u1 = User.objects.create_superuser("user1")u2 = User.objects.create_superuser("user2")diff --git a/src/documents/views.py b/src/documents/views.pyindex 1c80d0bab..db25e6934 100644--- a/src/documents/views.py+++ b/src/documents/views.py@@ -422,10 +422,12 @@ class DocumentViewSet(classifier = load_classifier()- gen = parse_date_generator(doc.filename, doc.content)- dates = sorted(- {i for i in itertools.islice(gen, settings.NUMBER_OF_SUGGESTED_DATES)},- )+ dates = []+ if settings.NUMBER_OF_SUGGESTED_DATES > 0:+ gen = parse_date_generator(doc.filename, doc.content)+ dates = sorted(+ {i for i in itertools.islice(gen, settings.NUMBER_OF_SUGGESTED_DATES)},+ )return Response({