diff --git a/HISTORY.rst b/HISTORY.rst index b476a09ab4..9d4f38355f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -92,6 +92,10 @@ DOCUMENTS_RECENT_ACCESS_COUNT. New setting DOCUMENTS_RECENT_ADDED_COUNT added. - Use platform independant hashing for transformations. +- Add support to the ObjectActionMixin to report on instance action + failures. Add also an error_message class property and the new + ActionError exception. + 3.0.3 (2018-08-17) ================== diff --git a/mayan/apps/common/exceptions.py b/mayan/apps/common/exceptions.py index 66987fcad7..cd205c87b8 100644 --- a/mayan/apps/common/exceptions.py +++ b/mayan/apps/common/exceptions.py @@ -8,6 +8,14 @@ class BaseCommonException(Exception): pass +class ActionError(BaseCommonException): + """ + Raise by the MultiActionConfirmView to announce when the object action + failed for one or more items. This exception doesn't stop the iteration, + it is used to announce that one item in the queryset failed to process. + """ + + class NotLatestVersion(BaseCommonException): """ The installed version is not the latest available version diff --git a/mayan/apps/common/mixins.py b/mayan/apps/common/mixins.py index a9e9422c06..e3541fce2e 100644 --- a/mayan/apps/common/mixins.py +++ b/mayan/apps/common/mixins.py @@ -12,6 +12,7 @@ from permissions import Permission from acls.models import AccessControlList +from .exceptions import ActionError from .forms import DynamicForm __all__ = ( @@ -181,8 +182,9 @@ class ObjectActionMixin(object): """ Mixin that performs an user action to a queryset """ - success_message = 'Operation performed on %(count)d object' - success_message_plural = 'Operation performed on %(count)d objects' + error_message = 'Unable to perform operation on object %(instance)s.' + success_message = 'Operation performed on %(count)d object.' + success_message_plural = 'Operation performed on %(count)d objects.' def get_success_message(self, count): return ungettext( @@ -194,7 +196,8 @@ class ObjectActionMixin(object): } def object_action(self, instance, form=None): - pass + # User supplied method + raise NotImplementedError def view_action(self, form=None): self.action_count = 0 @@ -204,6 +207,10 @@ class ObjectActionMixin(object): self.object_action(form=form, instance=instance) except PermissionDenied: pass + except ActionError: + messages.error( + self.request, self.error_message % {'instance': instance} + ) else: self.action_count += 1