[Protection Providers] Submit index view function

Change-Id: I7e271fd41e0303e188bb615ca61d4520d3fc9759
Closes-Bug: #1568745
This commit is contained in:
xiangxinyong
2016-04-11 16:52:21 +08:00
parent 56c39a2547
commit a5aad71c73
3 changed files with 103 additions and 11 deletions

View File

@@ -0,0 +1,56 @@
# 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.core.urlresolvers import reverse
from django import http
from django.utils.translation import ugettext_lazy as _
from horizon import tables
class ShowCheckpointsAction(tables.Action):
name = "checkpoints"
verbose_name = _("Show Checkpoints")
def allowed(self, request, provider):
return True
def single(self, table, request, obj_id):
redirect = reverse("horizon:smaug:checkpoints:index",
args=(obj_id,))
return http.HttpResponseRedirect(redirect)
class ProtectionProviderFilterAction(tables.FilterAction):
def filter(self, table, protectionproviders, filter_string):
"""Naive case-insensitive search."""
query = filter_string.lower()
return [protectionprovider
for protectionprovider in protectionproviders
if query in protectionprovider.name.lower()]
class ProtectionProvidersTable(tables.DataTable):
name = tables.Column('name',
link="horizon:smaug:protectionproviders:detail",
verbose_name=_('Name'))
description = tables.Column('description',
verbose_name=_('Description'))
class Meta(object):
name = 'protectionproviders'
verbose_name = _('Protection Providers')
row_actions = (ShowCheckpointsAction,)
table_actions = (ProtectionProviderFilterAction,)
multi_select = False

View File

@@ -12,9 +12,51 @@
# 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.protectionproviders import tables
class IndexView(views.APIView):
# A very simple class-based view...
class IndexView(horizon_tables.DataTableView):
table_class = tables.ProtectionProvidersTable
template_name = 'protectionproviders/index.html'
page_title = _("Protection Providers")
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.ProtectionProvidersTable._meta.prev_pagination_param, None)
if prev_marker is not None:
marker = prev_marker
else:
marker = request.GET.get(
tables.ProtectionProvidersTable._meta.pagination_param, None)
reversed_order = prev_marker is not None
providers = []
try:
providers, self._more, self._prev = \
smaugclient.provider_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 providers list.'))
return providers

View File

@@ -1,14 +1,8 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}
{% trans "Protection Providers" %}
{% endblock %}
{% block page_header %}
<hz-page-header header="{$ 'Protection Providers' | translate $}"/>
{% endblock page_header %}
{% block title %}{% trans "Protection Providers" %}{% endblock %}
{% block main %}
<div ng-view></div>
{{ table.render }}
{% endblock %}