diff --git a/HISTORY.rst b/HISTORY.rst index ff07d18e8f..ae150bf4cc 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -17,6 +17,8 @@ gunicorn:19.9.0, pyocr:0.5.2, python-dateutil:2.7.3 - Remove use of django-compressor and cssmin now that the project used Whitenoise. +- Display error when attempting to recalculate the page count of an empty + document (document stub that has no document version). 3.0.1 (2018-07-08) ================= diff --git a/mayan/apps/documents/views/document_views.py b/mayan/apps/documents/views/document_views.py index 60313eb94d..f2e7e6cbc9 100644 --- a/mayan/apps/documents/views/document_views.py +++ b/mayan/apps/documents/views/document_views.py @@ -596,9 +596,21 @@ class DocumentUpdatePageCountView(MultipleObjectConfirmActionView): return result def object_action(self, form, instance): - task_update_page_count.apply_async( - kwargs={'version_id': instance.latest_version.pk} - ) + latest_version = instance.latest_version + if latest_version: + task_update_page_count.apply_async( + kwargs={'version_id': latest_version.pk} + ) + else: + messages.error( + self.request, _( + 'Document "%(document)s" is empty. Upload at least one ' + 'document version before attempting to detect the ' + 'page count.' + ) % { + 'document': instance, + } + ) class DocumentTransformationsClearView(MultipleObjectConfirmActionView):