9
9
################################################################################
10
10
11
11
def select_dataset_ids ():
12
- if ds_id_from_rest_path_value () is not False :
12
+ if ds_id_from_rest_path_value ():
13
13
return
14
- if ds_id_from_accessid () is not False :
14
+ if ds_id_from_accessid ():
15
15
return
16
- if ds_id_from_record_id () is not False :
16
+ if ds_id_from_record_id ():
17
17
return
18
- if ds_ids_from_form () is not False :
18
+ if ds_ids_from_form ():
19
19
return
20
- if ds_id_from_default () is not False :
20
+ if ds_id_from_default ():
21
21
return
22
22
23
23
24
24
################################################################################
25
25
26
26
def ds_id_from_rest_path_value ():
27
- ds_p_id = rest_path_value ("datasets" )
28
- if not ds_p_id :
27
+ if not (ds_p_id := rest_path_value ("datasets" )):
29
28
return False
30
29
31
30
ds_ids = []
@@ -44,7 +43,7 @@ def ds_id_from_rest_path_value():
44
43
45
44
def ds_id_from_record_id ():
46
45
"""
47
- For data retrieval associated with a single record by its path id siuch as
46
+ For data retrieval associated with a single record by its path id such as
48
47
`biosamples/{id}` the default Beacon model does not provide any way to provide
49
48
the associated dataset id with the request. The assumption is that any record
50
49
id is unique across all datasets.
@@ -62,18 +61,15 @@ def ds_id_from_accessid():
62
61
# TODO: This is very verbose. In principle there should be an earlier
63
62
# test of existence...
64
63
65
- accessid = BYC_PARS .get ("accessid" , False )
66
- if any (x is False for x in [accessid ]):
64
+ if not (accessid := BYC_PARS .get ("accessid" )):
67
65
return False
68
66
69
67
ho_client = MongoClient (host = DB_MONGOHOST )
70
68
h_o = ho_client [HOUSEKEEPING_DB ][HOUSEKEEPING_HO_COLL ].find_one ({"id" : accessid })
71
69
if not h_o :
72
70
return False
73
71
ds_id = h_o .get ("source_db" , False )
74
- if ds_id is False :
75
- return False
76
- if ds_id not in BYC ["DATABASE_NAMES" ]:
72
+ if (ds_id := str (h_o .get ("source_db" ))) not in BYC ["DATABASE_NAMES" ]:
77
73
return False
78
74
BYC .update ({"BYC_DATASET_IDS" : [ds_id ]})
79
75
return True
@@ -82,26 +78,21 @@ def ds_id_from_accessid():
82
78
################################################################################
83
79
84
80
def ds_ids_from_form ():
85
- f_ds_ids = BYC_PARS .get ("dataset_ids" , False )
86
- if f_ds_ids is False :
87
- return False
88
- ds_ids = []
89
- for ds_id in f_ds_ids :
90
- if ds_id in BYC ["DATABASE_NAMES" ]:
91
- ds_ids .append (ds_id )
92
-
93
- if len (ds_ids ) < 1 :
81
+
82
+ if not (f_ds_ids := BYC_PARS .get ("dataset_ids" )):
94
83
return False
95
- BYC .update ({"BYC_DATASET_IDS" : ds_ids })
96
- return True
84
+ ds_ids = [ds for ds in f_ds_ids if ds in BYC .get ("DATABASE_NAMES" ,[])]
85
+ if len (ds_ids ) > 0 :
86
+ BYC .update ({"BYC_DATASET_IDS" : ds_ids })
87
+ return True
88
+ return False
97
89
98
90
99
91
################################################################################
100
92
101
93
def ds_id_from_default ():
102
- defaults : object = BYC ["beacon_defaults" ].get ("defaults" , {})
103
- ds_id = defaults .get ("default_dataset_id" , "___undefined___" )
104
- if ds_id not in BYC ["DATABASE_NAMES" ]:
94
+ defaults : object = BYC ["beacon_defaults" ].get ("defaults" , {})
95
+ if (ds_id := str (defaults .get ("default_dataset_id" ))) not in BYC ["DATABASE_NAMES" ]:
105
96
return False
106
97
BYC .update ({"BYC_DATASET_IDS" : [ ds_id ]})
107
98
return True
0 commit comments