Merge "Use include_rules option for listing library policies"
This commit is contained in:
commit
f580326ff5
@ -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 as e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user