34
34
git_commit_ref = {'master' :'' }
35
35
branch = 'master'
36
36
37
+
37
38
def load_schemas_from_github (branch = "master" ):
38
39
schemas = {}
39
40
response = requests .get ("https://github.com/org-id/register/archive/" + branch + ".zip" )
@@ -115,8 +116,6 @@ def augment_quality(schemas, org_id_lists):
115
116
listtype_score = {item ['code' ]: item ['quality_score' ] for item in schemas ['codelist-listType' ]['listType' ]}
116
117
listtype_names = {item ['code' ]: item ['title' ]['en' ] for item in schemas ['codelist-listType' ]['listType' ]}
117
118
118
-
119
-
120
119
for prefix in org_id_lists :
121
120
quality = 0
122
121
quality_explained = {}
@@ -140,7 +139,6 @@ def augment_quality(schemas, org_id_lists):
140
139
else :
141
140
print ('No licenseStatus for {}. Found in code {}' .format (prefix ['listType' ], prefix ['code' ]))
142
141
143
-
144
142
prefix ['quality_explained' ] = quality_explained
145
143
prefix ['quality' ] = min (quality , 100 )
146
144
@@ -249,8 +247,6 @@ def filter_and_score_results(query,use_branch="master"):
249
247
prefix ['relevance' ] += RELEVANCE ["MATCH_DROPDOWN" ]
250
248
prefix ['relevance_debug' ].append ("Primary list +" + str (RELEVANCE ["MATCH_DROPDOWN_ONLY_VALUE" ]))
251
249
252
-
253
-
254
250
if coverage :
255
251
if prefix .get ('coverage' ):
256
252
if coverage in prefix ['coverage' ]:
@@ -338,7 +334,7 @@ def filter_and_score_results(query,use_branch="master"):
338
334
return all_results
339
335
340
336
341
- def get_lookups (query_dict ):
337
+ def get_lookups (query_dict , use_branch = 'master' ):
342
338
''' Get only those lookup combinations returning some result'''
343
339
valid_lookups = {
344
340
'coverage' : None ,
@@ -374,9 +370,8 @@ def get_lookups(query_dict):
374
370
# Run the queries popping those lists that won't be returned
375
371
# from a dict (list_code:list_data) of id lists.
376
372
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 ()}
378
374
for org_list in list (indexed .values ()):
379
-
380
375
for key , value in q .items ():
381
376
if key == 'lookups' :
382
377
continue
@@ -448,6 +443,7 @@ def get_lookups(query_dict):
448
443
def update_lists (request ):
449
444
return HttpResponse (refresh_data ())
450
445
446
+
451
447
def preview_branch (request ,branch_name ):
452
448
print ("Loading branch " + branch_name )
453
449
refresh_data (branch_name )
@@ -467,15 +463,14 @@ def home(request):
467
463
}
468
464
}
469
465
if query :
470
- context ['lookups' ] = get_lookups (query )
466
+ context ['lookups' ] = get_lookups (query , use_branch )
471
467
context ['all_results' ] = filter_and_score_results (query ,use_branch )
472
468
context ['query' ] = query
473
469
else :
474
470
query = {'coverage' : '' , 'structure' : '' , 'sector' : '' }
475
471
context ['query' ] = False
476
472
context ['all_results' ] = {}
477
473
478
-
479
474
context ['local' ] = settings .LOCAL_DATA
480
475
context ['branch' ] = use_branch
481
476
@@ -493,6 +488,7 @@ def list_details(request, prefix):
493
488
raise Http404 ('Organisation list {} does not exist' .format (prefix ))
494
489
return render (request , 'list.html' , context = {'org_list' : org_list , 'branch' :use_branch })
495
490
491
+
496
492
def _get_filename (use_branch = 'master' ):
497
493
if git_commit_ref [use_branch ]:
498
494
return git_commit_ref [use_branch ][:10 ]
@@ -568,7 +564,6 @@ def make_xml_codelist(use_branch="master"):
568
564
else :
569
565
status = 'draft'
570
566
571
-
572
567
item = ET .SubElement (items , "codelist-item" ,** {'public-database' :publicdb ,'status' :status })
573
568
ET .SubElement (item , "code" ).text = entry ['code' ]
574
569
@@ -591,4 +586,3 @@ def xml_download(request):
591
586
response = HttpResponse (make_xml_codelist (use_branch ), content_type = 'text/xml' )
592
587
response ['Content-Disposition' ] = 'attachment; filename="org-id-{0}.xml"' .format (_get_filename ())
593
588
return response
594
-
0 commit comments