Commit c13f128d by Dudás Ádám

common, vm: refactor activity code manipulating code

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