8ea84225c3
Also moves most of the logic to a Service wrapper class to make it reusable. Adds tests for the new service class as well as the syspanel services view. Fixes bug 956552. Change-Id: I9407578bb27f3fe0765397793f2de03ed084637b
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
import logging
|
|
|
|
from django import template
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from horizon import tables
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class ServiceFilterAction(tables.FilterAction):
|
|
def filter(self, table, services, filter_string):
|
|
q = filter_string.lower()
|
|
|
|
def comp(service):
|
|
if q in service.type.lower():
|
|
return True
|
|
return False
|
|
|
|
return filter(comp, services)
|
|
|
|
|
|
def get_stats(service):
|
|
return template.loader.render_to_string('syspanel/services/_stats.html',
|
|
{'service': service})
|
|
|
|
|
|
def get_enabled(service, reverse=False):
|
|
options = ["Enabled", "Disabled"]
|
|
if reverse:
|
|
options.reverse()
|
|
return options[0] if not service.disabled else options[1]
|
|
|
|
|
|
class ServicesTable(tables.DataTable):
|
|
id = tables.Column('id', verbose_name=_('Id'), hidden=True)
|
|
name = tables.Column("name", verbose_name=_('Name'))
|
|
service_type = tables.Column('__unicode__', verbose_name=_('Service'))
|
|
host = tables.Column('host', verbose_name=_('Host'))
|
|
enabled = tables.Column(get_enabled,
|
|
verbose_name=_('Enabled'),
|
|
status=True)
|
|
|
|
class Meta:
|
|
name = "services"
|
|
verbose_name = _("Services")
|
|
table_actions = (ServiceFilterAction,)
|
|
multi_select = False
|
|
status_columns = ["enabled"]
|