Skip to content

Commit 9a4b463

Browse files
authored
Merge pull request #106 from OpenDataServices/102-sub-menus-not-working
102 sub menus not working
2 parents a363c07 + 8f73dca commit 9a4b463

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

prefix_finder/frontend/views.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
git_commit_ref = {'master':''}
3535
branch = 'master'
3636

37+
3738
def load_schemas_from_github(branch="master"):
3839
schemas = {}
3940
response = requests.get("https://github.com/org-id/register/archive/"+branch+".zip")
@@ -115,8 +116,6 @@ def augment_quality(schemas, org_id_lists):
115116
listtype_score = {item['code']: item['quality_score'] for item in schemas['codelist-listType']['listType']}
116117
listtype_names = {item['code']: item['title']['en'] for item in schemas['codelist-listType']['listType']}
117118

118-
119-
120119
for prefix in org_id_lists:
121120
quality = 0
122121
quality_explained = {}
@@ -140,7 +139,6 @@ def augment_quality(schemas, org_id_lists):
140139
else:
141140
print('No licenseStatus for {}. Found in code {}'.format(prefix['listType'], prefix['code']))
142141

143-
144142
prefix['quality_explained'] = quality_explained
145143
prefix['quality'] = min(quality, 100)
146144

@@ -249,8 +247,6 @@ def filter_and_score_results(query,use_branch="master"):
249247
prefix['relevance'] += RELEVANCE["MATCH_DROPDOWN"]
250248
prefix['relevance_debug'].append("Primary list +" + str(RELEVANCE["MATCH_DROPDOWN_ONLY_VALUE"]))
251249

252-
253-
254250
if coverage:
255251
if prefix.get('coverage'):
256252
if coverage in prefix['coverage']:
@@ -338,7 +334,7 @@ def filter_and_score_results(query,use_branch="master"):
338334
return all_results
339335

340336

341-
def get_lookups(query_dict):
337+
def get_lookups(query_dict, use_branch='master'):
342338
''' Get only those lookup combinations returning some result'''
343339
valid_lookups = {
344340
'coverage': None,
@@ -374,9 +370,8 @@ def get_lookups(query_dict):
374370
# Run the queries popping those lists that won't be returned
375371
# from a dict (list_code:list_data) of id lists.
376372
for q in queries:
377-
indexed = {key: value for key, value in org_id_dict.items()}
373+
indexed = {key: value for key, value in org_id_dict[use_branch].items()}
378374
for org_list in list(indexed.values()):
379-
380375
for key, value in q.items():
381376
if key == 'lookups':
382377
continue
@@ -448,6 +443,7 @@ def get_lookups(query_dict):
448443
def update_lists(request):
449444
return HttpResponse(refresh_data())
450445

446+
451447
def preview_branch(request,branch_name):
452448
print("Loading branch "+ branch_name)
453449
refresh_data(branch_name)
@@ -467,15 +463,14 @@ def home(request):
467463
}
468464
}
469465
if query:
470-
context['lookups'] = get_lookups(query)
466+
context['lookups'] = get_lookups(query, use_branch)
471467
context['all_results'] = filter_and_score_results(query,use_branch)
472468
context['query'] = query
473469
else:
474470
query = {'coverage': '', 'structure': '', 'sector': ''}
475471
context['query'] = False
476472
context['all_results'] = {}
477473

478-
479474
context['local'] = settings.LOCAL_DATA
480475
context['branch'] = use_branch
481476

@@ -493,6 +488,7 @@ def list_details(request, prefix):
493488
raise Http404('Organisation list {} does not exist'.format(prefix))
494489
return render(request, 'list.html', context={'org_list': org_list, 'branch':use_branch})
495490

491+
496492
def _get_filename(use_branch='master'):
497493
if git_commit_ref[use_branch]:
498494
return git_commit_ref[use_branch][:10]
@@ -555,20 +551,19 @@ def make_xml_codelist(use_branch="master"):
555551
items = ET.SubElement(root, "codelist-items")
556552

557553
for entry in org_id_dict[use_branch].values():
558-
if entry['access'] and entry['access']['availableOnline']:
554+
if entry.get('access') and entry['access'].get('availableOnline'):
559555
publicdb = str(1)
560556
else:
561557
publicdb = str(0)
562558

563-
if entry['deprecated']:
559+
if entry.get('deprecated'):
564560
status = 'withdrawn'
565561
else:
566-
if entry['confirmed']:
562+
if entry.get('confirmed'):
567563
status = 'active'
568564
else:
569565
status = 'draft'
570566

571-
572567
item = ET.SubElement(items, "codelist-item",**{'public-database':publicdb,'status':status})
573568
ET.SubElement(item, "code").text = entry['code']
574569

@@ -577,7 +572,7 @@ def make_xml_codelist(use_branch="master"):
577572

578573
description = ET.SubElement(item, "description")
579574
ET.SubElement(description, "narrative").text = entry['description']['en']
580-
if entry['coverage']:
575+
if entry.get('coverage'):
581576
ET.SubElement(item, "category").text = entry['coverage'][0]
582577
else:
583578
ET.SubElement(item, "category").text = '-'
@@ -591,4 +586,3 @@ def xml_download(request):
591586
response = HttpResponse(make_xml_codelist(use_branch), content_type='text/xml')
592587
response['Content-Disposition'] = 'attachment; filename="org-id-{0}.xml"'.format(_get_filename())
593588
return response
594-

0 commit comments

Comments
 (0)