Commit c13f128d by Dudás Ádám

common, vm: refactor activity code manipulating code

parent b1fe6a20
from inspect import getargspec
from logging import getLogger
from .models import activity_context, activity_code_separator
from .models import activity_context, has_suffix
from django.core.exceptions import PermissionDenied
......@@ -172,11 +172,15 @@ class OperatedMixin(object):
yield op
def get_operation_from_activity_code(self, activity_code):
sep = activity_code_separator
ops = getattr(self, operation_registry_name, {}).values()
for op in ops:
if activity_code.endswith(sep + op.activity_code_suffix):
return op
"""Get an instance of the Operation corresponding to the specified
activity code.
:returns: A bound instance of an operation, or None if no matching
operation could be found.
for op in getattr(self, operation_registry_name, {}).itervalues():
if has_suffix(activity_code, op.activity_code_suffix):
return op(self)
return None
......@@ -10,7 +10,7 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from common.models import (
ActivityModel, activitycontextimpl, join_activity_code,
ActivityModel, activitycontextimpl, join_activity_code, split_activity_code
from manager.mancelery import celery
......@@ -56,7 +56,8 @@ class InstanceActivity(ActivityModel):
return reverse('dashboard.views.vm-activity', args=[])
def get_readable_name(self):
return self.activity_code.split('.')[-1].replace('_', ' ').capitalize()
activity_code_last_suffix = split_activity_code(self.activity_code)[-1]
return activity_code_last_suffix.replace('_', ' ').capitalize()
def get_status_id(self):
if self.succeeded is None:
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