Commit 93218515 by Dudás Ádám

common: add (human-)readable name field and property to activites

parent 08ed0023
...@@ -110,6 +110,10 @@ def split_activity_code(activity_code): ...@@ -110,6 +110,10 @@ def split_activity_code(activity_code):
class ActivityModel(TimeStampedModel): class ActivityModel(TimeStampedModel):
activity_code = CharField(max_length=100, verbose_name=_('activity code')) activity_code = CharField(max_length=100, verbose_name=_('activity code'))
readable_name_data = JSONField(blank=True, null=True,
verbose_name=_('human readable name'),
help_text=_('Human readable name of '
'activity.'))
parent = ForeignKey('self', blank=True, null=True, related_name='children') parent = ForeignKey('self', blank=True, null=True, related_name='children')
task_uuid = CharField(blank=True, max_length=50, null=True, unique=True, task_uuid = CharField(blank=True, max_length=50, null=True, unique=True,
help_text=_('Celery task unique identifier.'), help_text=_('Celery task unique identifier.'),
...@@ -156,6 +160,14 @@ class ActivityModel(TimeStampedModel): ...@@ -156,6 +160,14 @@ class ActivityModel(TimeStampedModel):
return self.finished and not self.succeeded return self.finished and not self.succeeded
@property @property
def readable_name(self):
return HumanReadableObject.from_dict(self.readable_name_data)
@readable_name.setter
def set_readable_name(self, value):
self.readable_name_data = None if value is None else value.to_dict()
@property
def result(self): def result(self):
return HumanReadableObject.from_dict(self.result_data) return HumanReadableObject.from_dict(self.result_data)
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<div class="body-content"> <div class="body-content">
<div class="page-header"> <div class="page-header">
<h1> <h1>
{{ object.instance.name }}: {{ object.get_readable_name }} {{ object.instance.name }}: {{ object.readable_name.get_user_text }}
</h1> </h1>
</div> </div>
<div class="row"> <div class="row">
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
<span class="timeline-icon{% if a.has_failed %} timeline-icon-failed{% endif %}"> <span class="timeline-icon{% if a.has_failed %} timeline-icon-failed{% endif %}">
<i class="{% if not a.finished %} icon-refresh icon-spin {% else %}icon-plus{% endif %}"></i> <i class="{% if not a.finished %} icon-refresh icon-spin {% else %}icon-plus{% endif %}"></i>
</span> </span>
<strong>{{ a.get_readable_name }}</strong> <strong>{{ a.readable_name.get_user_text }}</strong>
{{ a.started|date:"Y-m-d H:i" }}, {{ a.user }} {{ a.started|date:"Y-m-d H:i" }}, {{ a.user }}
{% if a.children.count > 0 %} {% if a.children.count > 0 %}
<div class="sub-timeline"> <div class="sub-timeline">
{% for s in a.children.all %} {% for s in a.children.all %}
<div data-activity-id="{{ s.pk }}" class="sub-activity{% if s.has_failed %} sub-activity-failed{% endif %}"> <div data-activity-id="{{ s.pk }}" class="sub-activity{% if s.has_failed %} sub-activity-failed{% endif %}">
{{ s.get_readable_name }} - {{ s.readable_name.get_user_text }} -
{% if s.finished %} {% if s.finished %}
{{ s.finished|time:"H:i:s" }} {{ s.finished|time:"H:i:s" }}
{% else %} {% else %}
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<strong{% if user.is_superuser and a.result %} title="{{ a.result.get_admin_text }}"{% endif %}> <strong{% if user.is_superuser and a.result %} title="{{ a.result.get_admin_text }}"{% endif %}>
{% if user.is_superuser %}<a href="{{ a.get_absolute_url }}">{% endif %} {% if user.is_superuser %}<a href="{{ a.get_absolute_url }}">{% endif %}
{% if a.times > 1 %}({{ a.times }}x){% endif %} {% if a.times > 1 %}({{ a.times }}x){% endif %}
{{ a.get_readable_name }}{% if user.is_superuser %}</a>{% endif %} {{ a.readable_name.get_user_text }}{% if user.is_superuser %}</a>{% endif %}
{% if a.has_percent %} {% if a.has_percent %}
- {{ a.percentage }}% - {{ a.percentage }}%
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<div data-activity-id="{{ s.pk }}" class="sub-activity{% if s.has_failed %} sub-activity-failed{% endif %}{% if s.pk == active.pk %} sub-activity-active{% endif %}"> <div data-activity-id="{{ s.pk }}" class="sub-activity{% if s.has_failed %} sub-activity-failed{% endif %}{% if s.pk == active.pk %} sub-activity-active{% endif %}">
<span{% if user.is_superuser and s.result %} title="{{ s.result.get_admin_text }}"{% endif %}> <span{% if user.is_superuser and s.result %} title="{{ s.result.get_admin_text }}"{% endif %}>
{% if user.is_superuser %}<a href="{{ s.get_absolute_url }}">{% endif %} {% if user.is_superuser %}<a href="{{ s.get_absolute_url }}">{% endif %}
{{ s.get_readable_name }}{% if user.is_superuser %}</a>{% endif %}</span> &ndash; {{ s.readable_name.get_user_text }}{% if user.is_superuser %}</a>{% endif %}</span> &ndash;
{% if s.finished %} {% if s.finished %}
{{ s.finished|time:"H:i:s" }} {{ s.finished|time:"H:i:s" }}
{% else %} {% else %}
......
...@@ -105,10 +105,6 @@ class InstanceActivity(ActivityModel): ...@@ -105,10 +105,6 @@ class InstanceActivity(ActivityModel):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('dashboard.views.vm-activity', args=[self.pk]) return reverse('dashboard.views.vm-activity', args=[self.pk])
def get_readable_name(self):
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:
return 'wait' return 'wait'
...@@ -199,9 +195,6 @@ class NodeActivity(ActivityModel): ...@@ -199,9 +195,6 @@ class NodeActivity(ActivityModel):
return '{}({})'.format(self.activity_code, return '{}({})'.format(self.activity_code,
self.node) self.node)
def get_readable_name(self):
return self.activity_code.split('.')[-1].replace('_', ' ').capitalize()
@classmethod @classmethod
def create(cls, code_suffix, node, task_uuid=None, user=None): def create(cls, code_suffix, node, task_uuid=None, user=None):
activity_code = join_activity_code(cls.ACTIVITY_CODE_BASE, code_suffix) activity_code = join_activity_code(cls.ACTIVITY_CODE_BASE, 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