Commit b9327e39 by Guba Sándor

activity: ActivityInProgressError is HumanReadable

parent c49bac70
...@@ -30,7 +30,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext_noop ...@@ -30,7 +30,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext_noop
from common.models import ( from common.models import (
ActivityModel, activitycontextimpl, create_readable, join_activity_code, ActivityModel, activitycontextimpl, create_readable, join_activity_code,
HumanReadableObject, HumanReadableObject, HumanReadableException,
) )
from manager.mancelery import celery from manager.mancelery import celery
...@@ -39,17 +39,17 @@ from manager.mancelery import celery ...@@ -39,17 +39,17 @@ from manager.mancelery import celery
logger = getLogger(__name__) logger = getLogger(__name__)
class ActivityInProgressError(Exception): class ActivityInProgressError(HumanReadableException):
def __init__(self, activity, message=None): @classmethod
if message is None: def create(cls, activity):
message = ("Another activity is currently in progress: '%s' " obj = super(ActivityInProgressError, cls).create(
"(%s)." ugettext_noop("%(activity)s activity is currently in progress."),
% (activity.activity_code, activity.pk)) ugettext_noop("%(activity)s (%(pk)s) activity is currently "
"in progress."),
Exception.__init__(self, message) activity=activity.readable_name, pk=activity.pk)
obj.activity = activity
self.activity = activity return obj
def _normalize_readable_name(name, default=None): def _normalize_readable_name(name, default=None):
...@@ -96,7 +96,7 @@ class InstanceActivity(ActivityModel): ...@@ -96,7 +96,7 @@ class InstanceActivity(ActivityModel):
# Check for concurrent activities # Check for concurrent activities
active_activities = instance.activity_log.filter(finished__isnull=True) active_activities = instance.activity_log.filter(finished__isnull=True)
if concurrency_check and active_activities.exists(): if concurrency_check and active_activities.exists():
raise ActivityInProgressError(active_activities[0]) raise ActivityInProgressError.create(active_activities[0])
activity_code = join_activity_code(cls.ACTIVITY_CODE_BASE, code_suffix) activity_code = join_activity_code(cls.ACTIVITY_CODE_BASE, code_suffix)
act = cls(activity_code=activity_code, instance=instance, parent=None, act = cls(activity_code=activity_code, instance=instance, parent=None,
...@@ -113,7 +113,7 @@ class InstanceActivity(ActivityModel): ...@@ -113,7 +113,7 @@ class InstanceActivity(ActivityModel):
# Check for concurrent activities # Check for concurrent activities
active_children = self.children.filter(finished__isnull=True) active_children = self.children.filter(finished__isnull=True)
if concurrency_check and active_children.exists(): if concurrency_check and active_children.exists():
raise ActivityInProgressError(active_children[0]) raise ActivityInProgressError.create(active_children[0])
act = InstanceActivity( act = InstanceActivity(
activity_code=join_activity_code(self.activity_code, code_suffix), activity_code=join_activity_code(self.activity_code, code_suffix),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment