Skip to content

Commit 0dbb86b

Browse files
committed
ref: move FilterChainMyData to module panel_my_data
1 parent 77dde9f commit 0dbb86b

4 files changed

Lines changed: 144 additions & 141 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- enh: allow sharing individual datasets instead of collections (#32)
44
- enh: add preview option for dataset description in upload dialog (#52)
55
- enh: introduce write lock for eternal job updates
6+
- ref: move `FilterChainMyData` to module `panel_my_data`
67
0.18.2
78
- ref: make action buttons in filter view hideable
89
0.18.2

dcoraid/gui/dbview/filter_chain.py

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
from ...common import is_dc_resource_dict
88

9-
from ..tools import ShowWaitCursor
10-
from ..api import get_ckan_api
11-
129

1310
class FilterChain(QtWidgets.QWidget):
1411
download_item = QtCore.pyqtSignal(str, str, bool)
@@ -125,138 +122,3 @@ def update_resources(self):
125122
else:
126123
rs_entries.append(rs)
127124
self.fw_resources.set_entries(rs_entries)
128-
129-
130-
class FilterChainUser(FilterChain):
131-
added_datasets_to_collection = QtCore.pyqtSignal(dict, list)
132-
share_item = QtCore.pyqtSignal(str, str)
133-
134-
def __init__(self, *args, **kwargs):
135-
"""Filter chain with user-related features"""
136-
super(FilterChainUser, self).__init__(*args, **kwargs)
137-
138-
# Enable the "add to collection tool box"
139-
self.fw_datasets.pushButton_custom.setText(
140-
"Add selected datasets to a collection...")
141-
self.fw_datasets.pushButton_custom.setVisible(True)
142-
self.fw_datasets.pushButton_custom.clicked.connect(
143-
self.on_add_datasets_to_collection)
144-
145-
# Enable share buttons for collections and datasets
146-
self.fw_datasets.active_actions.append("share")
147-
self.fw_collections.active_actions.append("share")
148-
self.fw_datasets.share_item.connect(self.on_share_dataset)
149-
self.fw_collections.share_item.connect(self.on_share_collections)
150-
151-
def choose_collaborator(self, what_for=None):
152-
"""Let the user choose a collaborator from a dropdown list"""
153-
# Fetch a list of users
154-
with ShowWaitCursor():
155-
api = get_ckan_api()
156-
# TODO: let the user search for collaborators and add them to a
157-
# memoized list.
158-
users = api.get("user_autocomplete", q="", limit=100)
159-
160-
for_what_for = f" for {what_for}"
161-
label = f"Please choose a collaborator{for_what_for}."
162-
ignored_users = ["default", "adminpaul", api.user_name]
163-
user_choices = sorted([
164-
f"{u['fullname'] or u['name'].capitalize()} ({u['name']})"
165-
for u in users if u["name"] not in ignored_users])
166-
item, ok = QtWidgets.QInputDialog.getItem(
167-
self,
168-
"Choose a user",
169-
label,
170-
user_choices,
171-
0, # current index
172-
False, # editable
173-
)
174-
if ok:
175-
username = item.rsplit("(", 1)[1].strip(")")
176-
return username
177-
else:
178-
return None
179-
180-
@QtCore.pyqtSlot()
181-
def on_add_datasets_to_collection(self):
182-
"""Add all datasets currently selected to a collection
183-
184-
Displays a dialog where the user can choose a collection
185-
they have write-access to.
186-
"""
187-
# get current selection
188-
dataset_ids = self.fw_datasets.get_entry_identifiers(selected=True)
189-
if not dataset_ids:
190-
# no datasets selected
191-
QtWidgets.QMessageBox.information(
192-
self, "No datasets selected",
193-
"Please select at least one dataset.")
194-
else:
195-
# get list of writable collections
196-
with ShowWaitCursor():
197-
api = get_ckan_api()
198-
grps = api.get("group_list_authz")
199-
grps = sorted(grps, key=lambda x: x["display_name"])
200-
item, ok = QtWidgets.QInputDialog.getItem(
201-
self,
202-
"Select a collection",
203-
f"Please choose a collection for {len(dataset_ids)} datasets.",
204-
[f"{ii}: {g['display_name']}" for ii, g in enumerate(grps)],
205-
0, # current index
206-
False, # editable
207-
)
208-
if ok:
209-
index = int(item.split(":")[0])
210-
collection = grps[index]
211-
with ShowWaitCursor():
212-
# add all datasets to that collection
213-
for did in dataset_ids:
214-
api.post(
215-
"member_create",
216-
data={"id": collection["id"],
217-
"object": did,
218-
"object_type": "package",
219-
# "capacity" should not be necessary
220-
# https://github.com/ckan/ckan/issues/6543
221-
"capacity": "member"})
222-
self.added_datasets_to_collection.emit(collection,
223-
dataset_ids)
224-
225-
@QtCore.pyqtSlot(str, str)
226-
def on_share_collections(self, id_type, identifier):
227-
"""Share a collection with a collaborator"""
228-
if id_type != "collection":
229-
raise ValueError(
230-
"`on_share_collections` only works for collections")
231-
232-
# TODO: Let user list and remove collaborators
233-
234-
user = self.choose_collaborator(f"collection {identifier}")
235-
236-
if user:
237-
api = get_ckan_api()
238-
api.post("member_create",
239-
data={"id": identifier,
240-
"object": user,
241-
"object_type": "user",
242-
"capacity": "member"})
243-
# TODO: add a success message in the status widget
244-
245-
@QtCore.pyqtSlot(str, str)
246-
def on_share_dataset(self, id_type, identifier):
247-
"""Share a collection with another user"""
248-
if id_type != "dataset":
249-
raise ValueError(
250-
"`on_share_dataset` only works for datasets")
251-
252-
# TODO: Let user list and remove collaborators
253-
254-
user = self.choose_collaborator(f"dataset {identifier}")
255-
256-
if user:
257-
api = get_ckan_api()
258-
api.post("package_collaborator_create",
259-
data={"id": identifier,
260-
"user_id": user,
261-
"capacity": "member"})
262-
# TODO: add a success message in the status widget
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
from PyQt6 import QtCore, QtWidgets
2+
3+
from ..dbview import FilterChain
4+
from ..tools import ShowWaitCursor
5+
from ..api import get_ckan_api
6+
7+
8+
class FilterChainMyData(FilterChain):
9+
added_datasets_to_collection = QtCore.pyqtSignal(dict, list)
10+
share_item = QtCore.pyqtSignal(str, str)
11+
12+
def __init__(self, *args, **kwargs):
13+
"""Filter chain with user-related features"""
14+
super(FilterChainMyData, self).__init__(*args, **kwargs)
15+
16+
# Enable the "add to collection tool box"
17+
self.fw_datasets.pushButton_custom.setText(
18+
"Add selected datasets to a collection...")
19+
self.fw_datasets.pushButton_custom.setVisible(True)
20+
self.fw_datasets.pushButton_custom.clicked.connect(
21+
self.on_add_datasets_to_collection)
22+
23+
# Enable share buttons for collections and datasets
24+
self.fw_datasets.active_actions.append("share")
25+
self.fw_collections.active_actions.append("share")
26+
self.fw_datasets.share_item.connect(self.on_share_dataset)
27+
self.fw_collections.share_item.connect(self.on_share_collections)
28+
29+
def choose_collaborator(self, what_for=None):
30+
"""Let the user choose a collaborator from a dropdown list"""
31+
# Fetch a list of users
32+
with ShowWaitCursor():
33+
api = get_ckan_api()
34+
# TODO: let the user search for collaborators and add them to a
35+
# memoized list.
36+
users = api.get("user_autocomplete", q="", limit=100)
37+
38+
for_what_for = f" for {what_for}"
39+
label = f"Please choose a collaborator{for_what_for}."
40+
ignored_users = ["default", "adminpaul", api.user_name]
41+
user_choices = sorted([
42+
f"{u['fullname'] or u['name'].capitalize()} ({u['name']})"
43+
for u in users if u["name"] not in ignored_users])
44+
item, ok = QtWidgets.QInputDialog.getItem(
45+
self,
46+
"Choose a user",
47+
label,
48+
user_choices,
49+
0, # current index
50+
False, # editable
51+
)
52+
if ok:
53+
username = item.rsplit("(", 1)[1].strip(")")
54+
return username
55+
else:
56+
return None
57+
58+
@QtCore.pyqtSlot()
59+
def on_add_datasets_to_collection(self):
60+
"""Add all datasets currently selected to a collection
61+
62+
Displays a dialog where the user can choose a collection
63+
they have write-access to.
64+
"""
65+
# get current selection
66+
dataset_ids = self.fw_datasets.get_entry_identifiers(selected=True)
67+
if not dataset_ids:
68+
# no datasets selected
69+
QtWidgets.QMessageBox.information(
70+
self, "No datasets selected",
71+
"Please select at least one dataset.")
72+
else:
73+
# get list of writable collections
74+
with ShowWaitCursor():
75+
api = get_ckan_api()
76+
grps = api.get("group_list_authz")
77+
grps = sorted(grps, key=lambda x: x["display_name"])
78+
item, ok = QtWidgets.QInputDialog.getItem(
79+
self,
80+
"Select a collection",
81+
f"Please choose a collection for {len(dataset_ids)} datasets.",
82+
[f"{ii}: {g['display_name']}" for ii, g in enumerate(grps)],
83+
0, # current index
84+
False, # editable
85+
)
86+
if ok:
87+
index = int(item.split(":")[0])
88+
collection = grps[index]
89+
with ShowWaitCursor():
90+
# add all datasets to that collection
91+
for did in dataset_ids:
92+
api.post(
93+
"member_create",
94+
data={"id": collection["id"],
95+
"object": did,
96+
"object_type": "package",
97+
# "capacity" should not be necessary
98+
# https://github.com/ckan/ckan/issues/6543
99+
"capacity": "member"})
100+
self.added_datasets_to_collection.emit(collection,
101+
dataset_ids)
102+
103+
@QtCore.pyqtSlot(str, str)
104+
def on_share_collections(self, id_type, identifier):
105+
"""Share a collection with a collaborator"""
106+
if id_type != "collection":
107+
raise ValueError(
108+
"`on_share_collections` only works for collections")
109+
110+
# TODO: Let user list and remove collaborators
111+
112+
user = self.choose_collaborator(f"collection {identifier}")
113+
114+
if user:
115+
api = get_ckan_api()
116+
api.post("member_create",
117+
data={"id": identifier,
118+
"object": user,
119+
"object_type": "user",
120+
"capacity": "member"})
121+
# TODO: add a success message in the status widget
122+
123+
@QtCore.pyqtSlot(str, str)
124+
def on_share_dataset(self, id_type, identifier):
125+
"""Share a collection with another user"""
126+
if id_type != "dataset":
127+
raise ValueError(
128+
"`on_share_dataset` only works for datasets")
129+
130+
# TODO: Let user list and remove collaborators
131+
132+
user = self.choose_collaborator(f"dataset {identifier}")
133+
134+
if user:
135+
api = get_ckan_api()
136+
api.post("package_collaborator_create",
137+
data={"id": identifier,
138+
"user_id": user,
139+
"capacity": "member"})
140+
# TODO: add a success message in the status widget

dcoraid/gui/panel_my_data/widget_my_data.ui

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
</layout>
9393
</item>
9494
<item>
95-
<widget class="FilterChainUser" name="user_filter_chain" native="true">
95+
<widget class="FilterChainMyData" name="user_filter_chain" native="true">
9696
<property name="sizePolicy">
9797
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
9898
<horstretch>0</horstretch>
@@ -105,9 +105,9 @@
105105
</widget>
106106
<customwidgets>
107107
<customwidget>
108-
<class>FilterChainUser</class>
108+
<class>FilterChainMyData</class>
109109
<extends>QWidget</extends>
110-
<header>dcoraid.gui.dbview.filter_chain</header>
110+
<header>dcoraid.gui.panel_my_data.filter_chain_my_data</header>
111111
<container>1</container>
112112
</customwidget>
113113
</customwidgets>

0 commit comments

Comments
 (0)