Commit 51d0dbc9 by Kálmán Viktor

dashboard: appliance columns for disk list

parent 2faa9566
...@@ -21,10 +21,12 @@ from django.contrib.auth.models import Group, User ...@@ -21,10 +21,12 @@ from django.contrib.auth.models import Group, User
from django_tables2 import Table, A from django_tables2 import Table, A
from django_tables2.columns import (TemplateColumn, Column, LinkColumn, from django_tables2.columns import (TemplateColumn, Column, LinkColumn,
BooleanColumn) BooleanColumn)
from django.utils.safestring import mark_safe
from django.utils.html import escape
from vm.models import Node, InstanceTemplate, Lease from vm.models import Node, InstanceTemplate, Lease
from storage.models import Disk from storage.models import Disk
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _, ugettext
from django_sshkey.models import UserKey from django_sshkey.models import UserKey
from dashboard.models import ConnectCommand from dashboard.models import ConnectCommand
...@@ -37,6 +39,22 @@ class FileSizeColumn(Column): ...@@ -37,6 +39,22 @@ class FileSizeColumn(Column):
return size return size
class ApplianceColumn(TemplateColumn):
def render(self, *args, **kwargs):
value = super(ApplianceColumn, self).render(*args, **kwargs)
abbr = '<abbr title="%s">%s</abbr>'
appliance = kwargs['record'].get_appliance()
if appliance is None:
return value
elif isinstance(appliance, InstanceTemplate):
# Translators: [T] as Template
title, text = ugettext("Template"), ugettext("[T]")
else:
# Translators: [VM] as Virtual Machine
title, text = ugettext("Virtual machine"), ugettext("[VM]")
return mark_safe("%s %s" % (abbr % (title, text), value))
class NodeListTable(Table): class NodeListTable(Table):
pk = Column( pk = Column(
...@@ -306,12 +324,20 @@ class ConnectCommandListTable(Table): ...@@ -306,12 +324,20 @@ class ConnectCommandListTable(Table):
class DiskListTable(Table): class DiskListTable(Table):
size = FileSizeColumn() size = FileSizeColumn()
appliance = ApplianceColumn(
template_name="dashboard/storage/column-appliance.html",
verbose_name=_("Appliance"),
orderable=False,
)
is_ready = BooleanColumn(
verbose_name=_("ready")
)
class Meta: class Meta:
model = Disk model = Disk
attrs = {'class': "table table-bordered table-striped table-hover", attrs = {'class': "table table-bordered table-striped table-hover",
'id': "disk-list-table"} 'id': "disk-list-table"}
fields = ("pk", "name", "filename", "size", "is_ready") fields = ("pk", "appliance", "filename", "size", "is_ready")
prefix = "disk-" prefix = "disk-"
order_by = ("-pk", ) order_by = ("-pk", )
per_page = 65536 per_page = 65536
{% load i18n %}
{% with app=record.get_appliance %}
{% if app %}
<a href="{{ app.get_absolute_url }}">{{ app.name }}</a>
{% else %}
{% endif %}
{% endwith %}
...@@ -27,6 +27,7 @@ import re ...@@ -27,6 +27,7 @@ import re
from celery.contrib.abortable import AbortableAsyncResult from celery.contrib.abortable import AbortableAsyncResult
from django.db.models import (Model, BooleanField, CharField, DateTimeField, from django.db.models import (Model, BooleanField, CharField, DateTimeField,
ForeignKey) ForeignKey)
from django.core.exceptions import ObjectDoesNotExist
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_lazy as _, ugettext_noop from django.utils.translation import ugettext_lazy as _, ugettext_noop
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
...@@ -290,9 +291,10 @@ class Disk(TimeStampedModel): ...@@ -290,9 +291,10 @@ class Disk(TimeStampedModel):
""" """
from vm.models import Instance from vm.models import Instance
try: try:
return self.instance_set.get() app = self.template_set.all() or self.instance_set.all()
except Instance.DoesNotExist: return app.get()
return self.template_set.get() except ObjectDoesNotExist:
return None
def get_exclusive(self): def get_exclusive(self):
"""Get an instance of the disk for exclusive usage. """Get an instance of the disk for exclusive usage.
......
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