[Protection Plans] Submit index view function
Change-Id: I870b512de20032954a187c48e2d108c29f42b269 Closes-Bug: #1571458
This commit is contained in:
67
smaug_dashboard/protectionplans/tables.py
Normal file
67
smaug_dashboard/protectionplans/tables.py
Normal file
@@ -0,0 +1,67 @@
|
||||
# Copyright (c) 2016 Huawei, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
|
||||
from horizon import tables
|
||||
|
||||
from smaug_dashboard.api import smaug as smaugclient
|
||||
|
||||
|
||||
class DeleteProtectionPlansAction(tables.DeleteAction):
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Delete Protection Plan",
|
||||
u"Delete Protection Plans",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Delete Protection Plan",
|
||||
u"Delete Protection Plans",
|
||||
count
|
||||
)
|
||||
|
||||
def allowed(self, request, protectionplan):
|
||||
return True
|
||||
|
||||
def delete(self, request, obj_id):
|
||||
smaugclient.plan_delete(request, obj_id)
|
||||
|
||||
|
||||
class ProtectionPlanFilterAction(tables.FilterAction):
|
||||
def filter(self, table, protectionplans, filter_string):
|
||||
"""Naive case-insensitive search."""
|
||||
query = filter_string.lower()
|
||||
return [protectionplan for protectionplan in protectionplans
|
||||
if query in protectionplan.name.lower()]
|
||||
|
||||
|
||||
class ProtectionPlansTable(tables.DataTable):
|
||||
name = tables.Column('name',
|
||||
verbose_name=_('Name'))
|
||||
|
||||
status = tables.Column('status',
|
||||
verbose_name=_('Status'))
|
||||
|
||||
class Meta(object):
|
||||
name = 'protectionplans'
|
||||
verbose_name = _('Protection Plans')
|
||||
row_actions = (DeleteProtectionPlansAction,)
|
||||
table_actions = (ProtectionPlanFilterAction,
|
||||
DeleteProtectionPlansAction)
|
||||
@@ -12,9 +12,49 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from horizon import views
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import tables as horizon_tables
|
||||
|
||||
from smaug_dashboard.api import smaug as smaugclient
|
||||
from smaug_dashboard.protectionplans import tables
|
||||
|
||||
|
||||
class IndexView(views.APIView):
|
||||
# A very simple class-based view...
|
||||
class IndexView(horizon_tables.DataTableView):
|
||||
table_class = tables.ProtectionPlansTable
|
||||
template_name = 'protectionplans/index.html'
|
||||
page_title = _("Protection Plans")
|
||||
|
||||
def has_prev_data(self, table):
|
||||
return self._prev
|
||||
|
||||
def has_more_data(self, table):
|
||||
return self._more
|
||||
|
||||
def get_data(self):
|
||||
request = self.request
|
||||
prev_marker = request.GET.get(
|
||||
tables.ProtectionPlansTable._meta.prev_pagination_param, None)
|
||||
|
||||
if prev_marker is not None:
|
||||
marker = prev_marker
|
||||
else:
|
||||
marker = request.GET.get(
|
||||
tables.ProtectionPlansTable._meta.pagination_param, None)
|
||||
reversed_order = prev_marker is not None
|
||||
plans = []
|
||||
try:
|
||||
plans, self._more, self._prev = smaugclient.plan_list_paged(
|
||||
request, None,
|
||||
marker=marker,
|
||||
paginate=True,
|
||||
sort_dir='asc',
|
||||
sort_key='name',
|
||||
reversed_order=reversed_order)
|
||||
except Exception:
|
||||
self._prev = False
|
||||
self._more = False
|
||||
exceptions.handle(self.request,
|
||||
_('Unable to retrieve protection plans list.'))
|
||||
return plans
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
{% trans "Protection Plans" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block page_header %}
|
||||
<hz-page-header header="{$ 'Protection Plans' | translate $}"/>
|
||||
{% endblock page_header %}
|
||||
|
||||
{% block main %}
|
||||
<div ng-view></div>
|
||||
{{ table.render }}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user