diff --git a/mayan/apps/documents/dashboard_widgets.py b/mayan/apps/documents/dashboard_widgets.py index fb42590a96..4994cfc099 100644 --- a/mayan/apps/documents/dashboard_widgets.py +++ b/mayan/apps/documents/dashboard_widgets.py @@ -55,7 +55,7 @@ class DashboardWidgetDocumentsTotal(DashboardWidgetNumeric): ) self.count = AccessControlList.objects.filter_by_access( permission=permission_document_view, user=request.user, - queryset=Document.objects.filter(is_stub=False) + queryset=Document.objects.all() ).count() return super(DashboardWidgetDocumentsTotal, self).render(request) diff --git a/mayan/apps/documents/managers.py b/mayan/apps/documents/managers.py index beccf494a6..974291c21f 100644 --- a/mayan/apps/documents/managers.py +++ b/mayan/apps/documents/managers.py @@ -17,17 +17,13 @@ logger = logging.getLogger(__name__) class DocumentManager(models.Manager): - def delete_stubs(self): - for stale_stub_document in self.filter(is_stub=True, date_added__lt=now() - timedelta(seconds=STUB_EXPIRATION_INTERVAL)): - stale_stub_document.delete(trash=False) - def get_by_natural_key(self, uuid): return self.model.passthrough.get(uuid=force_text(uuid)) def get_queryset(self): return TrashCanQuerySet( self.model, using=self._db - ).filter(in_trash=False) + ).filter(in_trash=False).filter(is_stub=False) def invalidate_cache(self): for document in self.model.objects.all(): @@ -222,7 +218,9 @@ class FavoriteDocumentManager(models.Manager): class PassthroughManager(models.Manager): - pass + def delete_stubs(self): + for stale_stub_document in self.filter(is_stub=True, date_added__lt=now() - timedelta(seconds=STUB_EXPIRATION_INTERVAL)): + stale_stub_document.delete(to_trash=False) class RecentDocumentManager(models.Manager): diff --git a/mayan/apps/documents/tasks.py b/mayan/apps/documents/tasks.py index 0cb371571a..0c12091291 100644 --- a/mayan/apps/documents/tasks.py +++ b/mayan/apps/documents/tasks.py @@ -75,7 +75,7 @@ def task_delete_stubs(): ) logger.info('Executing') - Document.objects.delete_stubs() + Document.passthrough.delete_stubs() logger.info('Finshed') diff --git a/mayan/apps/documents/tests/test_models.py b/mayan/apps/documents/tests/test_models.py index 85d5c9b8c1..26f14d3193 100644 --- a/mayan/apps/documents/tests/test_models.py +++ b/mayan/apps/documents/tests/test_models.py @@ -242,34 +242,34 @@ class DocumentVersionTestCase(GenericDocumentTestCase): @override_settings(OCR_AUTO_OCR=False) -class DocumentManagerTestCase(BaseTestCase): +class DocumentPassthroughManagerTestCase(BaseTestCase): def setUp(self): - super(DocumentManagerTestCase, self).setUp() + super(DocumentPassthroughManagerTestCase, self).setUp() self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE_LABEL ) def tearDown(self): self.document_type.delete() - super(DocumentManagerTestCase, self).tearDown() + super(DocumentPassthroughManagerTestCase, self).tearDown() def test_document_stubs_deletion(self): document_stub = Document.objects.create( document_type=self.document_type ) - Document.objects.delete_stubs() + Document.passthrough.delete_stubs() - self.assertEqual(Document.objects.count(), 1) + self.assertEqual(Document.passthrough.count(), 1) document_stub.date_added = document_stub.date_added - timedelta( seconds=STUB_EXPIRATION_INTERVAL + 1 ) document_stub.save() - Document.objects.delete_stubs() + Document.passthrough.delete_stubs() - self.assertEqual(Document.objects.count(), 0) + self.assertEqual(Document.passthrough.count(), 0) class DuplicatedDocumentsTestCase(GenericDocumentTestCase): diff --git a/mayan/apps/mirroring/filesystems.py b/mayan/apps/mirroring/filesystems.py index 5041bc1363..89bd5f9827 100644 --- a/mayan/apps/mirroring/filesystems.py +++ b/mayan/apps/mirroring/filesystems.py @@ -80,9 +80,7 @@ class IndexFilesystem(Operations): if access_only: return True else: - return Document.objects.get( - is_stub=False, pk=document_pk - ) + return Document.objects.get(pk=document_pk) for count, part in enumerate(parts[1:]): try: