From bdd8f849b50048de3bbd9fb569ffdf8bf70eb784 Mon Sep 17 00:00:00 2001 From: Anusha Ramineni Date: Tue, 21 Nov 2017 11:44:45 +0530 Subject: [PATCH] Use include_rules option for listing library policies This commit uses the include_rules option supported in client and server for listing library policies. Partially-Implements blueprint add-policy-library-gui Depends-On: Ib27119ba03d5658ff937f514f6ff3abfe5c390fe I2271579f655481b156ec66382d887b8784b13ad6 Change-Id: I3a9b95a4fd9b23c91658d464b6ba4e4a7ca105c7 --- congress_dashboard/api/congress.py | 14 ++++++++------ congress_dashboard/library/views.py | 10 ++++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/congress_dashboard/api/congress.py b/congress_dashboard/api/congress.py index ad7eb69..8cb5d62 100644 --- a/congress_dashboard/api/congress.py +++ b/congress_dashboard/api/congress.py @@ -361,10 +361,10 @@ def delete_datasource(request, datasource_name): raise -def list_policies_from_library(request): +def list_policies_from_library(request, include_rules=True): client = congressclient(request) try: - results = client.list_library_policy()['results'] + results = client.list_library_policy(include_rules)['results'] policies = [] for p in results: policy = PolicyAPIDictWrapper(p) @@ -375,12 +375,14 @@ def list_policies_from_library(request): raise -def show_library_policy(request, name): +def show_library_policy(request, name, include_rules=True): client = congressclient(request) try: - policy = client.show_library_policy(name) - rules = [PolicyRule(r) for r in policy['rules']] - return policy, rules + policy = client.show_library_policy(name, include_rules=include_rules) + if include_rules: + rules = [PolicyRule(r) for r in policy['rules']] + policy['rules'] = rules + return policy except Exception: LOG.exception("unable to get library policy '%s' details", name) raise diff --git a/congress_dashboard/library/views.py b/congress_dashboard/library/views.py index 3edf4c0..f54618b 100644 --- a/congress_dashboard/library/views.py +++ b/congress_dashboard/library/views.py @@ -31,7 +31,8 @@ class IndexView(tables.DataTableView): def get_data(self): try: - policies = congress.list_policies_from_library(self.request) + policies = congress.list_policies_from_library(self.request, + include_rules=False) return policies except Exception as e: msg = _('Unable to list library policies: %s') % str(e) @@ -48,8 +49,8 @@ class DetailView(tables.DataTableView): def get_data(self): try: policy_id = self.kwargs['policy_name'] - policy, rules = congress.show_library_policy(self.request, - policy_id) + rules = congress.show_library_policy(self.request, + policy_id)['rules'] for r in rules: head = r['rule'].split(congress.RULE_SEPARATOR)[0] name = (head.split('(')[0]).replace('_', ' ').title() @@ -67,7 +68,8 @@ class DetailView(tables.DataTableView): context = super(DetailView, self).get_context_data(**kwargs) try: policy_id = self.kwargs['policy_name'] - policy, _ = congress.show_library_policy(self.request, policy_id) + policy = congress.show_library_policy(self.request, policy_id, + include_rules=False) context['policy'] = policy return context except Exception: