Fix time values of cluster provision steps

This patch fixes time values of cluster provision steps according to
timezone in dashboard settings.

Change-Id: Ibe5574b5577f4d792dd2829662881c4d90c44436
closes-bug: 1563419
This commit is contained in:
Michael Ionkin 2016-04-05 14:30:49 +03:00
parent 9d6e353c5a
commit 244c580c20
4 changed files with 38 additions and 4 deletions

View File

@ -14,3 +14,4 @@ python-manilaclient>=1.3.0 # Apache-2.0
python-neutronclient!=4.1.0,>=2.6.0 # Apache-2.0
python-novaclient!=2.33.0,>=2.29.0 # Apache-2.0
python-saharaclient>=0.13.0 # Apache-2.0
pytz>=2013.6 # MIT

View File

@ -144,7 +144,8 @@ class ClusterEventsView(django_base.View):
step["duration"] = time_helpers.get_duration(
step["created_at"],
step["updated_at"])
step['started_at'] = time_helpers.to_time_zone(
step["created_at"], localize=True)
result = _("In progress")
step["completed"] = successful_events_count

View File

@ -44,7 +44,7 @@ horizon.event_log = {
"</tr>";
var started_at = new Date(step.created_at).toString();
var started_at = step.started_at;
var progress = "" + step.completed + " / " + step.total;
var description = step.step_type + "<br />" + step.step_name;

View File

@ -11,9 +11,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from pytz import timezone as ptz
import six
from django.template import defaultfilters as filters
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from oslo_utils import timeutils
import six
import sahara_dashboard.content.data_processing. \
utils.workflow_helpers as work_helpers
@ -130,7 +134,7 @@ class Helpers(object):
The end time may be skipped. In this case datetime.now() will be used.
:param start_time: Start timestamp.
:param end_time: End timestamp. Optional.
:param end_time: (optional) End timestamp.
:return: The delta between timestamps.
"""
@ -144,6 +148,34 @@ class Helpers(object):
return six.text_type(end_datetime - start_datetime)
def to_time_zone(self, datetime, tzone=None,
input_fmt=None, localize=False):
"""Changes given datetime string into given timezone
:param datetime: datetime string
:param tzone: (optional) timezone as a string (e.g. "Europe/Paris"),
by default it's the current django timezone
:param input_fmt: (optional) format of datetime param, if None then
the default Sahara API format (%Y-%m-%dT%H:%M:%S) will be used
:param localize: (optional) if True then format of datetime will be
localized according to current timezone else it will be in
the default Sahara API format (%Y-%m-%dT%H:%M:%S)
:return datetime string in the current django timezone
"""
default_fmt = '%Y-%m-%dT%H:%M:%S'
if tzone is None:
tzone = self.request.session.get('django_timezone', 'UTC')
if input_fmt is None:
input_fmt = default_fmt
dt_in_utc = timezone.utc.localize(
timeutils.parse_strtime(datetime, input_fmt))
dt_in_zone = dt_in_utc.astimezone(ptz(tzone))
if localize:
return filters.date(dt_in_zone, "DATETIME_FORMAT")
else:
return dt_in_zone.strftime(default_fmt)
# Map needed because switchable fields need lower case
# and our server is expecting upper case. We will be