Porting: Move Policy Table data to policies Tab
This commit ports the dashboard fix to new project. Change-Id: Ibfa239b4a487587ff909eac74230fe2449ae4ba6 Partially-Implements: blueprint enahance-congress-dashboard
This commit is contained in:
parent
88ef2e3d5a
commit
55508b8cbf
@ -47,20 +47,6 @@ def get_policy_table_link(datum):
|
||||
args=(datum['policy_name'], datum['name']))
|
||||
|
||||
|
||||
class PoliciesTablesTable(tables.DataTable):
|
||||
name = tables.Column("name", verbose_name=_("Table Name"),
|
||||
link=get_policy_table_link)
|
||||
policy_name = tables.Column("policy_name", verbose_name=_("Policy"),
|
||||
link=get_policy_link)
|
||||
policy_owner_id = tables.Column("policy_owner_id",
|
||||
verbose_name=_("Owner ID"))
|
||||
|
||||
class Meta(object):
|
||||
name = "policies_tables"
|
||||
verbose_name = _("Policy Data")
|
||||
hidden_title = False
|
||||
|
||||
|
||||
class DataSourceRowsTable(tables.DataTable):
|
||||
class Meta(object):
|
||||
name = "datasource_rows"
|
||||
|
@ -20,8 +20,6 @@ from congress_dashboard.datasources import views
|
||||
|
||||
SERVICES = (
|
||||
r'^services/(?P<datasource_id>[^/]+)/(?P<service_table_name>[^/]+)/%s$')
|
||||
POLICIES = (
|
||||
r'^policies/(?P<datasource_id>[^/]+)/(?P<policy_table_name>[^/]+)/%s$')
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
@ -29,6 +27,4 @@ urlpatterns = patterns(
|
||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
url(SERVICES % 'detail', views.DetailView.as_view(),
|
||||
name='datasource_table_detail'),
|
||||
url(POLICIES % 'detail', views.DetailView.as_view(),
|
||||
name='policy_table_detail'),
|
||||
)
|
||||
|
@ -32,7 +32,6 @@ logger = logging.getLogger(__name__)
|
||||
class IndexView(tables.MultiTableView):
|
||||
"""List service and policy defined data."""
|
||||
table_classes = (datasources_tables.DataSourcesTablesTable,
|
||||
datasources_tables.PoliciesTablesTable,
|
||||
datasources_tables.DataSourceStatusesTable,)
|
||||
template_name = 'admin/datasources/index.html'
|
||||
|
||||
@ -82,39 +81,6 @@ class IndexView(tables.MultiTableView):
|
||||
messages.error(self.request, msg)
|
||||
return ds
|
||||
|
||||
def get_policies_tables_data(self):
|
||||
try:
|
||||
policies = congress.policies_list(self.request)
|
||||
except Exception as e:
|
||||
msg = _('Unable to get policies list: %s') % str(e)
|
||||
messages.error(self.request, msg)
|
||||
return []
|
||||
|
||||
policies_tables = []
|
||||
for policy in policies:
|
||||
policy_name = policy['name']
|
||||
try:
|
||||
policy_tables = congress.policy_tables_list(self.request,
|
||||
policy_name)
|
||||
except Exception as e:
|
||||
msg_args = {'policy_name': policy_name, 'error': str(e)}
|
||||
msg = _('Unable to get tables list for policy '
|
||||
'"%(policy_name)s": %(error)s') % msg_args
|
||||
messages.error(self.request, msg)
|
||||
return []
|
||||
|
||||
for pt in policy_tables:
|
||||
pt.set_id_as_name_if_empty()
|
||||
pt.set_policy_details(policy)
|
||||
# Object ids within a Horizon table must be unique. Otherwise,
|
||||
# Horizon will cache the column values for the object by id and
|
||||
# use the same column values for all rows with the same id.
|
||||
pt.set_value('table_id', pt['id'])
|
||||
pt.set_value('id', '%s-%s' % (policy_name, pt['table_id']))
|
||||
policies_tables.extend(policy_tables)
|
||||
|
||||
return policies_tables
|
||||
|
||||
|
||||
class DetailView(tables.DataTableView):
|
||||
"""List details about and rows from a data source (service or policy)."""
|
||||
|
@ -110,3 +110,18 @@ class PolicyRulesTable(tables.DataTable):
|
||||
table_actions = (CreateRule, DeleteRule,)
|
||||
row_actions = (DeleteRule,)
|
||||
hidden_title = False
|
||||
|
||||
|
||||
def get_policy_table_link(datum):
|
||||
return reverse('horizon:admin:policies:policy_table_detail',
|
||||
args=(datum['policy_name'], datum['name']))
|
||||
|
||||
|
||||
class PoliciesTablesTable(tables.DataTable):
|
||||
name = tables.Column("name", verbose_name=_("Table Name"),
|
||||
link=get_policy_table_link)
|
||||
|
||||
class Meta(object):
|
||||
name = "policies_tables"
|
||||
verbose_name = _("Policy Table Data")
|
||||
hidden_title = False
|
||||
|
@ -4,9 +4,9 @@
|
||||
|
||||
<div class="detail">
|
||||
<dl class="dl-horizontal">
|
||||
<dt>{% trans "Name" %}</dt>
|
||||
<dt>{% trans "Policy Name" %}</dt>
|
||||
<dd>{{ policy.name|default:policy.id }}</dd>
|
||||
<dt>{% trans "ID" %}</dt>
|
||||
<dt>{% trans "Policy ID" %}</dt>
|
||||
<dd>{{ policy.id }}</dd>
|
||||
<dt>{% trans "Description" %}</dt>
|
||||
<dd>{{ policy.description }}</dd>
|
||||
|
@ -12,6 +12,9 @@
|
||||
<div id="policy_rules">
|
||||
{{ policy_rules_table.render }}
|
||||
</div>
|
||||
<div id="policies_tables">
|
||||
{{ policies_tables_table.render }}
|
||||
</div>
|
||||
<span id="ds_tables" class="hidden">{{ tables }}</span>
|
||||
<span id="ds_columns" class="hidden">{{ columns }}</span>
|
||||
{% endblock %}
|
||||
|
@ -15,11 +15,13 @@
|
||||
from django.conf.urls import patterns
|
||||
from django.conf.urls import url
|
||||
|
||||
from congress_dashboard.datasources import views as data_views
|
||||
from congress_dashboard.policies.rules import views as rule_views
|
||||
from congress_dashboard.policies import views
|
||||
|
||||
|
||||
POLICY = r'^(?P<policy_name>[^/]+)/%s$'
|
||||
POLICYTABLE = r'^(?P<datasource_id>[^/]+)/(?P<policy_table_name>[^/]+)/%s$'
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
@ -27,6 +29,8 @@ urlpatterns = patterns(
|
||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
url(r'^create/$', views.CreateView.as_view(), name='create'),
|
||||
url(POLICY % 'detail', views.DetailView.as_view(), name='detail'),
|
||||
url(POLICYTABLE % 'detail', data_views.DetailView.as_view(),
|
||||
name='policy_table_detail'),
|
||||
url(POLICY % 'rules/create',
|
||||
rule_views.CreateView.as_view(), name='create_rule'),
|
||||
)
|
||||
|
@ -56,12 +56,36 @@ class CreateView(forms.ModalFormView):
|
||||
success_url = reverse_lazy('horizon:admin:policies:index')
|
||||
|
||||
|
||||
class DetailView(tables.DataTableView):
|
||||
class DetailView(tables.MultiTableView):
|
||||
"""List details about and rules in a policy."""
|
||||
table_class = rules_tables.PolicyRulesTable
|
||||
table_classes = (rules_tables.PolicyRulesTable,
|
||||
rules_tables.PoliciesTablesTable,)
|
||||
template_name = 'admin/policies/detail.html'
|
||||
|
||||
def get_data(self):
|
||||
def get_policies_tables_data(self):
|
||||
policy_name = self.kwargs['policy_name']
|
||||
try:
|
||||
policy_tables = congress.policy_tables_list(self.request,
|
||||
policy_name)
|
||||
except Exception as e:
|
||||
msg_args = {'policy_name': policy_name, 'error': str(e)}
|
||||
msg = _('Unable to get tables list for policy '
|
||||
'"%(policy_name)s": %(error)s') % msg_args
|
||||
messages.error(self.request, msg)
|
||||
return []
|
||||
|
||||
for pt in policy_tables:
|
||||
pt.set_id_as_name_if_empty()
|
||||
pt.set_value('policy_name', policy_name)
|
||||
# Object ids within a Horizon table must be unique. Otherwise,
|
||||
# Horizon will cache the column values for the object by id and
|
||||
# use the same column values for all rows with the same id.
|
||||
pt.set_value('table_id', pt['id'])
|
||||
pt.set_value('id', '%s-%s' % (policy_name, pt['table_id']))
|
||||
|
||||
return policy_tables
|
||||
|
||||
def get_policy_rules_data(self):
|
||||
policy_name = self.kwargs['policy_name']
|
||||
try:
|
||||
policy_rules = congress.policy_rules_list(self.request,
|
||||
|
Loading…
x
Reference in New Issue
Block a user