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
This commit is contained in:
parent
b2d848640b
commit
bdd8f849b5
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue