Update checkpoint status in checkpoint page

When watching the checkpoint page, update (poll?) the checkpoint
status. If a checkpoint is protecting, user shouldn't refresh
the page to see it is available.

Change-Id: I4dd046a3314219586b83837593ebb16fb1217077
Closes-Bug: #1622594
This commit is contained in:
zhangshuai 2017-01-22 09:25:28 +08:00
parent 8374be577c
commit d2105f78c0
2 changed files with 49 additions and 1 deletions

View File

@ -13,6 +13,7 @@
# under the License.
from django.core.urlresolvers import reverse
from django.utils.translation import pgettext_lazy
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
@ -74,7 +75,42 @@ def get_plan_name(obj):
return name
class UpdateRow(tables.Row):
ajax = True
def __init__(self, table, datum=None):
super(UpdateRow, self).__init__(table, datum)
self.provider_id = getattr(table, 'provider_id')
def get_data(self, request, obj_id):
provider = karborclient.provider_get(request, self.provider_id)
checkpoint = karborclient.checkpoint_get(request,
self.provider_id,
obj_id)
setattr(checkpoint, "provider_name", provider.name)
setattr(checkpoint, "provider_id", provider.id)
return checkpoint
TASK_DISPLAY_CHOICES = (
("error", pgettext_lazy("Task status of an Checkpoint", u"Error")),
("protecting", pgettext_lazy("Task status of an Checkpoint",
u"Protecting")),
("available", pgettext_lazy("Task status of an Checkpoint", u"Available")),
("deleting", pgettext_lazy("Task status of an Checkpoint", u"Deleting")),
("deleted", pgettext_lazy("Task status of an Checkpoint", u"Deleted")),
("error-deleting", pgettext_lazy("Task status of an Checkpoint",
u"Error Deleting")),
)
class CheckpointsTable(tables.DataTable):
TASK_STATUS_CHOICES = (
("error", True),
("available", True),
("deleted", True),
("error-deleting", True),
)
checkpointId = tables.Column(
"id",
link=get_provider_link,
@ -87,11 +123,16 @@ class CheckpointsTable(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)
class Meta(object):
name = 'checkpoints'
verbose_name = _('Checkpoints')
status_columns = ["status", ]
row_class = UpdateRow
row_actions = (RestoreCheckpointLink, DeleteCheckpointsAction)

View File

@ -85,6 +85,7 @@ class IndexView(horizon_tables.DataTableView):
context = dict(context, **self.get_filter_list())
return context
@memoized.memoized_method
def get_search_opts(self):
def _total_days(year, month, num_months):
days = 0
@ -171,6 +172,12 @@ class IndexView(horizon_tables.DataTableView):
_('Unable to retrieve checkpoints list.'))
return checkpoints
def get_table(self):
super(IndexView, self).get_table()
provider_id, _ = self.get_search_opts()
setattr(self.table, 'provider_id', provider_id)
return self.table
class CheckpointsRestoreView(horizon_forms.ModalFormView):
template_name = 'checkpoints/restore.html'