11from functools import partial
22import webbrowser
33
4- from PyQt6 import QtCore , QtWidgets
4+ from PyQt6 import QtWidgets
55from PyQt6 .QtCore import Qt
66
77from ...common import is_dc_resource_dict
88
99from ..api import get_ckan_api
10- from ..tools import ShowWaitCursor
1110
1211from . import filter_base
1312
@@ -39,47 +38,18 @@ def __init__(self, *args, **kwargs):
3938 self .checkBox .setVisible (False )
4039 self .label_info .setVisible (False )
4140
42- def download_collection (self , collection_name , condensed = False ):
43- """Emit signals to download all resources of a collection
44-
45- Parameters
46- ----------
47- collection_name: str
48- Name of the collection
49- condensed: bool
50- Whether to download condensed resources instead
51- """
52- with ShowWaitCursor ():
53- api = get_ckan_api ()
54- search_dict = api .get ("package_search" ,
55- fq = f"+groups:{ collection_name } " ,
56- include_private = True ,
57- rows = 1000 )
58- num_datasets = search_dict ["count" ]
59- if num_datasets >= 1000 :
60- raise NotImplementedError (
61- # We have to increase ckan.search.rows_max = 1000
62- # or (better) use the `start` parameter until we
63- # hit a number < 1000.
64- f"There are too many datasets in '{ collection_name } '!" )
65- for ii , ds_dict in enumerate (search_dict ["results" ]):
66- for res_dict in ds_dict .get ("resources" , []):
67- self .download_resource .emit (res_dict ["id" ], condensed )
68- QtWidgets .QApplication .processEvents (
69- QtCore .QEventLoop .ProcessEventsFlag .AllEvents ,
70- 300 )
71-
7241 def get_entry_actions (self , row , entry ):
7342 api = get_ckan_api ()
7443 url = f"{ api .server } /group/{ entry ['name' ]} "
7544 actions = [
7645 {"icon" : "angle-down" ,
7746 "tooltip" : f"download collection { entry ['name' ]} " ,
78- "function" : partial (self .download_collection , entry ["name" ])},
47+ "function" : partial (self .download_item .emit ,
48+ "collection" , entry ["name" ], False )},
7949 {"icon" : "angles-down" ,
8050 "tooltip" : f"download condensed collection { entry ['name' ]} " ,
81- "function" : partial (self .download_collection , entry [ "name" ] ,
82- condensed = True )},
51+ "function" : partial (self .download_item . emit ,
52+ "collection" , entry [ "name" ], True )},
8353 {"icon" : "eye" ,
8454 "tooltip" : f"view collection { entry ['name' ]} online" ,
8555 "function" : partial (webbrowser .open , url )}
@@ -95,35 +65,18 @@ def __init__(self, *args, **kwargs):
9565 self .checkBox .setVisible (False )
9666 self .label_info .setVisible (False )
9767
98- def download_dataset (self , dataset_id , condensed = False ):
99- """Emit signals to download all resources of a dataset
100-
101- Parameters
102- ----------
103- dataset_id: str
104- dataset ID
105- condensed: bool
106- Whether to download condensed resources instead
107- """
108- api = get_ckan_api ()
109- ds_dict = api .get ("package_show" , id = dataset_id )
110- for res_dict in ds_dict .get ("resources" , []):
111- self .download_resource .emit (res_dict ["id" ], condensed )
112- QtWidgets .QApplication .processEvents (
113- QtCore .QEventLoop .ProcessEventsFlag .AllEvents ,
114- 300 )
115-
11668 def get_entry_actions (self , row , entry ):
11769 api = get_ckan_api ()
11870 url = f"{ api .server } /dataset/{ entry ['name' ]} "
11971 actions = [
12072 {"icon" : "angle-down" ,
12173 "tooltip" : f"download dataset { entry ['name' ]} " ,
122- "function" : partial (self .download_dataset , entry ["id" ])},
74+ "function" : partial (self .download_item .emit ,
75+ "dataset" , entry ["id" ], False )},
12376 {"icon" : "angles-down" ,
12477 "tooltip" : f"download condensed dataset { entry ['name' ]} " ,
125- "function" : partial (self .download_dataset , entry [ "id" ] ,
126- condensed = True )},
78+ "function" : partial (self .download_item . emit ,
79+ "dataset" , entry [ "id" ], True )},
12780 {"icon" : "eye" ,
12881 "tooltip" : f"view dataset { entry ['name' ]} online" ,
12982 "function" : partial (webbrowser .open , url )},
@@ -153,8 +106,8 @@ def get_entry_actions(self, row, entry):
153106 actions = [
154107 {"icon" : "angle-down" ,
155108 "tooltip" : f"download resource { entry ['name' ]} " ,
156- "function" : partial (self .download_resource .emit ,
157- entry ["id" ], False )},
109+ "function" : partial (self .download_item .emit ,
110+ "resource" , entry ["id" ], False )},
158111 {"icon" : "eye" ,
159112 "tooltip" : f"view resource { entry ['name' ]} online" ,
160113 "function" : partial (webbrowser .open , url )},
@@ -165,8 +118,9 @@ def get_entry_actions(self, row, entry):
165118 1 ,
166119 {"icon" : "angles-down" ,
167120 "tooltip" : f"download condensed resource { entry ['name' ]} " ,
168- "function" : partial (self .download_resource .emit ,
169- entry ["id" ], True )},)
121+ "function" : partial (self .download_item .emit ,
122+ "resource" , entry ["id" ], True )},
123+ )
170124 return actions
171125
172126 def set_entry_label (self , row , entry ):
0 commit comments