From e9db07bfd3e37f73a05bfef7981a8a610aae78af Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 3 Oct 2018 03:32:56 -0400 Subject: [PATCH] Encapsulate in_trash field into is_in_trash symetric Document property Signed-off-by: Roberto Rosario --- mayan/apps/documents/models.py | 12 ++++++++++++ mayan/apps/documents/widgets.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index 0805aef88c..3db0fe854d 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -281,6 +281,10 @@ class Document(models.Model): for document_version in self.versions.all(): document_version.invalidate_cache() + @property + def is_in_trash(self): + return self.in_trash + def natural_key(self): return (self.uuid,) natural_key.dependencies = ['documents.DocumentType'] @@ -566,6 +570,10 @@ class DocumentVersion(models.Model): for page in self.pages.all(): page.invalidate_cache() + @property + def is_in_trash(self): + return self.document.is_in_trash + def open(self, raw=False): """ Return a file descriptor to a document version's file irrespective of @@ -974,6 +982,10 @@ class DocumentPage(models.Model): for cached_image in self.cached_images.all(): cached_image.delete() + @property + def is_in_trash(self): + return self.document.is_in_trash + def natural_key(self): return (self.page_number, self.document_version.natural_key()) natural_key.dependencies = ['documents.DocumentVersion'] diff --git a/mayan/apps/documents/widgets.py b/mayan/apps/documents/widgets.py index 700faa98a7..3e49e8e361 100644 --- a/mayan/apps/documents/widgets.py +++ b/mayan/apps/documents/widgets.py @@ -60,7 +60,7 @@ class DocumentPageThumbnailWidget(object): template_name='documents/widgets/document_thumbnail.html', context={ # Disable the clickable link if the document is in the trash - 'disable_title_link': instance.in_trash, + 'disable_title_link': instance.is_in_trash, 'gallery_name': 'document_list', 'instance': instance, 'size_preview_width': setting_preview_width.value,