Use timesinceSorter instead of the uptimeSorter.
timesinceSorter is provided by horizon as the default sorter of the datetime fields in a table. We don't have to create a uptimeSorter for host inventory panel. The reason that we failed to use timesinceSorter before is the datetime returned by host.boottime is calculated by datetime.now() but not timezone.now(). With this change, timesinceSorter can work well with host inventory panel. Test done for the change: 1. Build iso with this patch. 2. Deploy with 1 controller and 2 compute nodes. 3. Open starlingx dashboard, Admin -> Platform -> Host Inventory, press on the column head of "Uptime" of the table for compute nodes, the timesinceSorter works well to sort the compute nodes. 4. Check the page source, the Uptime column is marked as "data-type="timesince"", and the data for this column is marked with data-seconds (added by the timesince_sortable filter), format as below: <span data-seconds="4361">1 hour, 12 minutes</span> Closes-Bug: 1809861 Change-Id: I5f9e896ccb0e4bb0e7d801402f9139e191cf9e08 Signed-off-by: Yan Chen <yan.chen@intel.com>
This commit is contained in:
parent
39abb81c3c
commit
d230601b8e
|
@ -23,6 +23,7 @@ from cgtsclient.v1 import client as cgts_client
|
||||||
from cgtsclient.v1 import icpu as icpu_utils
|
from cgtsclient.v1 import icpu as icpu_utils
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils import timezone
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from openstack_dashboard.api import base
|
from openstack_dashboard.api import base
|
||||||
|
@ -949,7 +950,7 @@ class Host(base.APIResourceWrapper):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def boottime(self):
|
def boottime(self):
|
||||||
return datetime.datetime.now() - datetime.timedelta(
|
return timezone.now() - datetime.timedelta(
|
||||||
seconds=self.uptime)
|
seconds=self.uptime)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -11,13 +11,14 @@ import logging
|
||||||
from django.core.urlresolvers import reverse # noqa
|
from django.core.urlresolvers import reverse # noqa
|
||||||
from django import shortcuts
|
from django import shortcuts
|
||||||
from django import template
|
from django import template
|
||||||
from django.template.defaultfilters import safe, timesince # noqa
|
from django.template.defaultfilters import safe # noqa
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.translation import ungettext_lazy
|
from django.utils.translation import ungettext_lazy
|
||||||
|
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
from horizon import messages
|
from horizon import messages
|
||||||
from horizon import tables
|
from horizon import tables
|
||||||
|
from horizon.utils import filters
|
||||||
from horizon.utils import functions
|
from horizon.utils import functions
|
||||||
|
|
||||||
from starlingx_dashboard import api as stx_api
|
from starlingx_dashboard import api as stx_api
|
||||||
|
@ -731,9 +732,9 @@ class Hosts(tables.DataTable):
|
||||||
display_choices=stx_api.sysinv.
|
display_choices=stx_api.sysinv.
|
||||||
Host.AVAIL_DISPLAY_CHOICES)
|
Host.AVAIL_DISPLAY_CHOICES)
|
||||||
uptime = tables.Column('boottime',
|
uptime = tables.Column('boottime',
|
||||||
verbose_name=_('Uptime'),
|
verbose_name=_("Uptime"),
|
||||||
filters=(timesince,),
|
filters=(filters.timesince_sortable,),
|
||||||
attrs={'data-type': "uptime"})
|
attrs={'data-type': 'timesince'})
|
||||||
|
|
||||||
task = tables.Column(get_task_or_status,
|
task = tables.Column(get_task_or_status,
|
||||||
cell_attributes_getter=get_install_percent,
|
cell_attributes_getter=get_install_percent,
|
||||||
|
|
Loading…
Reference in New Issue