From aec32d550800040cc658d241f7cfd22e4c5604fe Mon Sep 17 00:00:00 2001 From: chenying Date: Mon, 13 Feb 2017 13:43:07 +0800 Subject: [PATCH] Update restore status in restore page When watching the restore page, update (poll?) the restore status. If a restore is in_progress, user shouldn't refresh the page to see it is success. Change-Id: Idca8860f726eaf5a450e8335b112b9d845b26377 Co-authored-by: xiangxinyong --- karbor_dashboard/restores/tables.py | 37 ++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/karbor_dashboard/restores/tables.py b/karbor_dashboard/restores/tables.py index 55355ed..48c86b3 100644 --- a/karbor_dashboard/restores/tables.py +++ b/karbor_dashboard/restores/tables.py @@ -12,12 +12,42 @@ # License for the specific language governing permissions and limitations # under the License. +from django.utils.translation import pgettext_lazy from django.utils.translation import ugettext_lazy as _ from horizon import tables +from karbor_dashboard.api import karbor as karborclient + + +TASK_DISPLAY_CHOICES = ( + ("fail", pgettext_lazy("Task status of an Restore", u"Fail")), + ("in_progress", pgettext_lazy("Task status of an Restore", + u"In Progress")), + ("success", pgettext_lazy("Task status of an Restore", u"Success")), +) + + +class UpdateRow(tables.Row): + ajax = True + + def get_data(self, request, obj_id): + restore = karborclient.restore_get(request, obj_id) + checkpoint = karborclient.checkpoint_get(request, + restore.provider_id, + restore.checkpoint_id) + provider = karborclient.provider_get(request, + restore.provider_id) + setattr(restore, "name", checkpoint.protection_plan["name"]) + setattr(restore, "provider_name", provider.name) + return restore + class RestoresTable(tables.DataTable): + TASK_STATUS_CHOICES = ( + ("fail", False), + ("success", True), + ) id = tables.Column( 'id', verbose_name=_('ID')) @@ -26,7 +56,10 @@ class RestoresTable(tables.DataTable): verbose_name=_('Protection Plan')) status = tables.Column( 'status', - verbose_name=_('Status')) + verbose_name=_('Status'), + status=True, + status_choices=TASK_STATUS_CHOICES, + display_choices=TASK_DISPLAY_CHOICES) restore_from_checkpoint = tables.Column( 'checkpoint_id', verbose_name=_('Restore From Checkpoint')) @@ -40,3 +73,5 @@ class RestoresTable(tables.DataTable): class Meta(object): name = 'restores' verbose_name = _('Restores') + status_columns = ["status", ] + row_class = UpdateRow