Add support to the ObjectActionMixin to report on instance action failures. Add also an error_message class property and the new ActionError exception.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -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)
|
||||
==================
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user