Only sort on sortable columns.
Also some generic cleanup. Change-Id: I7b4f27a5d25204f2356bb1189dc252a65f83332e
This commit is contained in:
parent
59e862e422
commit
4570fff7a6
@ -413,8 +413,8 @@ class InstanceViewTests(test.TestCase):
|
||||
res = self.client.post(url, formData)
|
||||
self.assertRedirects(res, redir_url)
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertContains(res, "<td class=\"status_unknown\">"
|
||||
"Snapshotting</td>", 1)
|
||||
self.assertContains(res, '<td class="status_unknown sortable">'
|
||||
'Snapshotting</td>', 1)
|
||||
|
||||
def test_instance_update_get(self):
|
||||
server = self.servers.first()
|
||||
|
@ -55,10 +55,13 @@ class UsageViewTests(test.BaseAdminViewTests):
|
||||
res = self.client.get(reverse('horizon:syspanel:overview:index'))
|
||||
self.assertTemplateUsed(res, 'syspanel/overview/usage.html')
|
||||
self.assertTrue(isinstance(res.context['usage'], usage.GlobalUsage))
|
||||
self.assertContains(res, '<td class="">test_tenant</td>'
|
||||
'<td class="">%s</td><td class="">%s</td>'
|
||||
'<td class="">%s</td><td class="">%.2f</td>'
|
||||
'<td class="">%.2f</td>' %
|
||||
self.assertContains(res,
|
||||
'<td class="sortable">test_tenant</td>'
|
||||
'<td class="sortable">%s</td>'
|
||||
'<td class="sortable">%s</td>'
|
||||
'<td class="sortable">%s</td>'
|
||||
'<td class="sortable">%.2f</td>'
|
||||
'<td class="sortable">%.2f</td>' %
|
||||
(usage_obj.vcpus,
|
||||
usage_obj.disk_gb_hours,
|
||||
mbformat(usage_obj.memory_mb),
|
||||
|
@ -1,3 +1,19 @@
|
||||
horizon.datatables.init_sorting = function () {
|
||||
// Function to initialize the tablesorter plugin strictly on sortable columns.
|
||||
$("table.table").each(function () {
|
||||
var $this = $(this),
|
||||
options = {};
|
||||
$this.find("thead th").each(function (i, val) {
|
||||
if (!$(this).hasClass('sortable')) {
|
||||
options[i] = {sorter: false};
|
||||
}
|
||||
});
|
||||
$this.tablesorter({
|
||||
headers: options
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
horizon.addInitFunction(function() {
|
||||
$('.table_search input').quicksearch('tbody tr', {
|
||||
'delay': 300,
|
||||
@ -37,5 +53,5 @@ horizon.addInitFunction(function() {
|
||||
});
|
||||
|
||||
horizon.datatables.update();
|
||||
$("table.table").tablesorter();
|
||||
horizon.datatables.init_sorting();
|
||||
});
|
||||
|
@ -65,7 +65,7 @@ class Column(html.HTMLElement):
|
||||
.. attribute:: sortable
|
||||
|
||||
Boolean to determine whether this column should be sortable or not.
|
||||
Defaults to False.
|
||||
Defaults to ``True``.
|
||||
|
||||
.. attribute:: hidden
|
||||
|
||||
@ -149,8 +149,6 @@ class Column(html.HTMLElement):
|
||||
}
|
||||
# Used to retain order when instantiating columns on a table
|
||||
creation_counter = 0
|
||||
# Used for special auto-generated columns
|
||||
auto = None
|
||||
|
||||
transform = None
|
||||
name = None
|
||||
@ -171,14 +169,16 @@ class Column(html.HTMLElement):
|
||||
('off', False),
|
||||
)
|
||||
|
||||
def __init__(self, transform, verbose_name=None, sortable=False,
|
||||
def __init__(self, transform, verbose_name=None, sortable=True,
|
||||
link=None, hidden=False, attrs=None, status=False,
|
||||
status_choices=None, display_choices=None, empty_value=None,
|
||||
filters=None, classes=None, summation=None):
|
||||
self.classes = classes or getattr(self, "classes", [])
|
||||
filters=None, classes=None, summation=None, auto=None):
|
||||
self.classes = list(classes or getattr(self, "classes", []))
|
||||
super(Column, self).__init__()
|
||||
self.attrs.update(attrs or {})
|
||||
|
||||
self.auto = auto
|
||||
|
||||
if callable(transform):
|
||||
self.transform = transform
|
||||
self.name = transform.__name__
|
||||
@ -210,7 +210,7 @@ class Column(html.HTMLElement):
|
||||
self.creation_counter = Column.creation_counter
|
||||
Column.creation_counter += 1
|
||||
|
||||
if self.sortable:
|
||||
if self.sortable and not self.auto:
|
||||
self.classes.append("sortable")
|
||||
if self.hidden:
|
||||
self.classes.append("hide")
|
||||
@ -709,15 +709,15 @@ class DataTableMetaclass(type):
|
||||
# Add in our auto-generated columns
|
||||
if opts.multi_select:
|
||||
multi_select = opts.column_class("multi_select",
|
||||
verbose_name="")
|
||||
verbose_name="",
|
||||
auto="multi_select")
|
||||
multi_select.classes.append('multi_select_column')
|
||||
multi_select.auto = "multi_select"
|
||||
columns.insert(0, ("multi_select", multi_select))
|
||||
if opts.actions_column:
|
||||
actions_column = opts.column_class("actions",
|
||||
verbose_name=_("Actions"))
|
||||
verbose_name=_("Actions"),
|
||||
auto="actions")
|
||||
actions_column.classes.append('actions_column')
|
||||
actions_column.auto = "actions"
|
||||
columns.append(("actions", actions_column))
|
||||
# Store this set of columns internally so we can copy them per-instance
|
||||
attrs['_columns'] = SortedDict(columns)
|
||||
|
@ -1,3 +1,3 @@
|
||||
<tr {{ row.attr_string|safe }}>
|
||||
{% for cell in row %}<td {{ cell.attr_string|safe }}>{{ cell.value }}</td>{% endfor %}
|
||||
<tr{{ row.attr_string|safe }}>
|
||||
{% for cell in row %}<td{{ cell.attr_string|safe }}>{{ cell.value }}</td>{% endfor %}
|
||||
</tr>
|
||||
|
@ -147,7 +147,7 @@ def get_link(obj):
|
||||
|
||||
|
||||
class MyTable(tables.DataTable):
|
||||
id = tables.Column('id', hidden=True)
|
||||
id = tables.Column('id', hidden=True, sortable=False)
|
||||
name = tables.Column(get_name, verbose_name="Verbose Name", sortable=True)
|
||||
value = tables.Column('value',
|
||||
sortable=True,
|
||||
|
Loading…
x
Reference in New Issue
Block a user