Merge "Use include_rules option for listing library policies"

This commit is contained in:
Zuul 2017-12-05 07:56:30 +00:00 committed by Gerrit Code Review
commit f580326ff5
2 changed files with 14 additions and 10 deletions

View File

@ -361,10 +361,10 @@ def delete_datasource(request, datasource_name):
raise raise
def list_policies_from_library(request): def list_policies_from_library(request, include_rules=True):
client = congressclient(request) client = congressclient(request)
try: try:
results = client.list_library_policy()['results'] results = client.list_library_policy(include_rules)['results']
policies = [] policies = []
for p in results: for p in results:
policy = PolicyAPIDictWrapper(p) policy = PolicyAPIDictWrapper(p)
@ -375,12 +375,14 @@ def list_policies_from_library(request):
raise raise
def show_library_policy(request, name): def show_library_policy(request, name, include_rules=True):
client = congressclient(request) client = congressclient(request)
try: try:
policy = client.show_library_policy(name) policy = client.show_library_policy(name, include_rules=include_rules)
if include_rules:
rules = [PolicyRule(r) for r in policy['rules']] rules = [PolicyRule(r) for r in policy['rules']]
return policy, rules policy['rules'] = rules
return policy
except Exception: except Exception:
LOG.exception("unable to get library policy '%s' details", name) LOG.exception("unable to get library policy '%s' details", name)
raise raise

View File

@ -31,7 +31,8 @@ class IndexView(tables.DataTableView):
def get_data(self): def get_data(self):
try: try:
policies = congress.list_policies_from_library(self.request) policies = congress.list_policies_from_library(self.request,
include_rules=False)
return policies return policies
except Exception as e: except Exception as e:
msg = _('Unable to list library policies: %s') % str(e) msg = _('Unable to list library policies: %s') % str(e)
@ -48,8 +49,8 @@ class DetailView(tables.DataTableView):
def get_data(self): def get_data(self):
try: try:
policy_id = self.kwargs['policy_name'] policy_id = self.kwargs['policy_name']
policy, rules = congress.show_library_policy(self.request, rules = congress.show_library_policy(self.request,
policy_id) policy_id)['rules']
for r in rules: for r in rules:
head = r['rule'].split(congress.RULE_SEPARATOR)[0] head = r['rule'].split(congress.RULE_SEPARATOR)[0]
name = (head.split('(')[0]).replace('_', ' ').title() name = (head.split('(')[0]).replace('_', ' ').title()
@ -67,7 +68,8 @@ class DetailView(tables.DataTableView):
context = super(DetailView, self).get_context_data(**kwargs) context = super(DetailView, self).get_context_data(**kwargs)
try: try:
policy_id = self.kwargs['policy_name'] 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 context['policy'] = policy
return context return context
except Exception as e: except Exception as e: