[Protection Providers] Submit detail view function
Change-Id: I824b7232bf7c66b34b43b94f7340e257877227a2 Closes-Bug: #1568752
This commit is contained in:
91
smaug_dashboard/protectionproviders/tabs.py
Normal file
91
smaug_dashboard/protectionproviders/tabs.py
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
# 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 horizon import exceptions
|
||||||
|
from horizon import tabs
|
||||||
|
|
||||||
|
import simplejson as json
|
||||||
|
from smaug_dashboard.api import smaug as smaugclient
|
||||||
|
|
||||||
|
|
||||||
|
class OptionsSchemaTab(tabs.Tab):
|
||||||
|
name = _("Options Schema")
|
||||||
|
slug = "optionsschema"
|
||||||
|
template_name = "protectionproviders/_schema_contents.html"
|
||||||
|
|
||||||
|
def get_context_data(self, request):
|
||||||
|
try:
|
||||||
|
provider_id = self.tab_group.kwargs['provider_id']
|
||||||
|
provider = smaugclient.provider_get(request, provider_id)
|
||||||
|
|
||||||
|
schema = {}
|
||||||
|
if provider is not None:
|
||||||
|
if 'options_schema' in provider.extended_info_schema:
|
||||||
|
schema = provider.extended_info_schema['options_schema']
|
||||||
|
|
||||||
|
return {"schema_contents": json.dumps(schema, indent=4)}
|
||||||
|
except Exception:
|
||||||
|
msg = _('Unable to retrieve provider contents.')
|
||||||
|
exceptions.handle(request, msg)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class RestoreSchemaTab(tabs.Tab):
|
||||||
|
name = _("Restore Schema")
|
||||||
|
slug = "restoreschema"
|
||||||
|
template_name = "protectionproviders/_schema_contents.html"
|
||||||
|
|
||||||
|
def get_context_data(self, request):
|
||||||
|
try:
|
||||||
|
provider_id = self.tab_group.kwargs['provider_id']
|
||||||
|
provider = smaugclient.provider_get(request, provider_id)
|
||||||
|
|
||||||
|
schema = {}
|
||||||
|
if provider is not None:
|
||||||
|
if 'restore_schema' in provider.extended_info_schema:
|
||||||
|
schema = provider.extended_info_schema['restore_schema']
|
||||||
|
|
||||||
|
return {"schema_contents": json.dumps(schema, indent=4)}
|
||||||
|
except Exception:
|
||||||
|
msg = _('Unable to retrieve provider contents.')
|
||||||
|
exceptions.handle(request, msg)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class SavedInfoSchemaTab(tabs.Tab):
|
||||||
|
name = _("Saved Info Schema")
|
||||||
|
slug = "savedinfoschema"
|
||||||
|
template_name = "protectionproviders/_schema_contents.html"
|
||||||
|
|
||||||
|
def get_context_data(self, request):
|
||||||
|
try:
|
||||||
|
provider_id = self.tab_group.kwargs['provider_id']
|
||||||
|
provider = smaugclient.provider_get(request, provider_id)
|
||||||
|
schema = {}
|
||||||
|
if provider is not None:
|
||||||
|
if 'saved_info_schema' in provider.extended_info_schema:
|
||||||
|
schema = provider.extended_info_schema['saved_info_schema']
|
||||||
|
|
||||||
|
return {"schema_contents": json.dumps(schema, indent=4)}
|
||||||
|
except Exception:
|
||||||
|
msg = _('Unable to retrieve provider contents.')
|
||||||
|
exceptions.handle(request, msg)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class ProviderDetailTabs(tabs.TabGroup):
|
||||||
|
slug = "provider_details"
|
||||||
|
tabs = (OptionsSchemaTab, RestoreSchemaTab, SavedInfoSchemaTab)
|
||||||
@@ -18,4 +18,6 @@ from smaug_dashboard.protectionproviders import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||||
|
url(r'^(?P<provider_id>[^/]+)/detail/$',
|
||||||
|
views.DetailView.as_view(), name='detail'),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -12,13 +12,17 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from horizon import exceptions
|
from horizon import exceptions
|
||||||
from horizon import tables as horizon_tables
|
from horizon import tables as horizon_tables
|
||||||
|
from horizon import tabs as horizon_tabs
|
||||||
|
from horizon.utils import memoized
|
||||||
|
|
||||||
from smaug_dashboard.api import smaug as smaugclient
|
from smaug_dashboard.api import smaug as smaugclient
|
||||||
from smaug_dashboard.protectionproviders import tables
|
from smaug_dashboard.protectionproviders import tables
|
||||||
|
from smaug_dashboard.protectionproviders import tabs
|
||||||
|
|
||||||
|
|
||||||
class IndexView(horizon_tables.DataTableView):
|
class IndexView(horizon_tables.DataTableView):
|
||||||
@@ -60,3 +64,31 @@ class IndexView(horizon_tables.DataTableView):
|
|||||||
self.request,
|
self.request,
|
||||||
_('Unable to retrieve protection providers list.'))
|
_('Unable to retrieve protection providers list.'))
|
||||||
return providers
|
return providers
|
||||||
|
|
||||||
|
|
||||||
|
class DetailView(horizon_tabs.TabView):
|
||||||
|
redirect_url = "horizon:smaug:protectionproviders:index"
|
||||||
|
tab_group_class = tabs.ProviderDetailTabs
|
||||||
|
template_name = 'protectionproviders/detail.html'
|
||||||
|
page_title = "{{ provider.name }}"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(DetailView, self).get_context_data(**kwargs)
|
||||||
|
context["provider"] = self.get_data()
|
||||||
|
return context
|
||||||
|
|
||||||
|
@memoized.memoized_method
|
||||||
|
def get_data(self):
|
||||||
|
try:
|
||||||
|
provider_id = self.kwargs['provider_id']
|
||||||
|
provider = smaugclient.provider_get(self.request, provider_id)
|
||||||
|
except Exception:
|
||||||
|
exceptions.handle(
|
||||||
|
self.request,
|
||||||
|
_('Unable to retrieve protection provider details.'),
|
||||||
|
redirect=reverse("horizon:smaug:protectionproviders:index"))
|
||||||
|
return provider
|
||||||
|
|
||||||
|
def get_tabs(self, request, *args, **kwargs):
|
||||||
|
provider = self.get_data()
|
||||||
|
return self.tab_group_class(request, provider=provider, **kwargs)
|
||||||
|
|||||||
10
smaug_dashboard/templates/protectionproviders/_detail.html
Normal file
10
smaug_dashboard/templates/protectionproviders/_detail.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
<div class="detail">
|
||||||
|
<dl class="dl-horizontal">
|
||||||
|
<dt>{% trans "Provider Name" %}</dt>
|
||||||
|
<dd>{{ provider.name }}</dd>
|
||||||
|
<dt>{% trans "Provider Description" %}</dt>
|
||||||
|
<dd>{{ provider.description }}</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
<div class="pre_scrollable">
|
||||||
|
<pre class="data">{{ schema_contents }}</pre>
|
||||||
|
</div>
|
||||||
24
smaug_dashboard/templates/protectionproviders/detail.html
Normal file
24
smaug_dashboard/templates/protectionproviders/detail.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load breadcrumb_nav %}
|
||||||
|
|
||||||
|
{% block title %}{% trans "Protection Provider Details" %}{% endblock %}
|
||||||
|
|
||||||
|
{% block page_header %}
|
||||||
|
<div class='page-header'>
|
||||||
|
{% breadcrumb_nav %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
{% include "protectionproviders/_detail.html" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-12">
|
||||||
|
{{ tab_group.render }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user