Skip to content

Commit 748896c

Browse files
committed
Bump to 1.2.1
- Fixed display of online links to files. Now uses guid information field provided by the OSF, instead of parsing the comments link - Fixed the situation in which actions for a previous experiment were still executed after opening a new experiment. Opening a new experiment empties the pending actions queue.
1 parent 1519c1f commit 748896c

File tree

5 files changed

+35
-41
lines changed

5 files changed

+35
-41
lines changed

QOpenScienceFramework/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.2.0"
1+
__version__ = "1.2.1"
22
__author__ = "Daniel Schreij"
33

44
import os

QOpenScienceFramework/manager.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ class ConnectionManager(QtNetwork.QNetworkAccessManager):
5050
success_message = QtCore.Signal('QString','QString')
5151
"""PyQt signal to send a success message."""
5252

53-
# Dictionary holding requests in progress, so that they can be repeated if
54-
# mid-request it is discovered that the OAuth2 token is no longer valid.
55-
pending_requests = {}
56-
5753
def __init__(self, *args, **kwargs):
5854
""" Constructor
5955
@@ -123,6 +119,10 @@ def __init__(self, *args, **kwargs):
123119
# The icon to show on the progress dialog
124120
self._progress_icon = None
125121

122+
# Dictionary holding requests in progress, so that they can be repeated if
123+
# mid-request it is discovered that the OAuth2 token is no longer valid.
124+
self.pending_requests = {}
125+
126126
### properties
127127
@property
128128
def progress_icon(self):
@@ -248,6 +248,12 @@ def func_wrapper(inst, *args, **kwargs):
248248
return func(inst, *args, **kwargs)
249249
return func_wrapper
250250

251+
def clear_pending_requests(self):
252+
""" Resets the pending network requests that still need to be executed.
253+
Network requests
254+
"""
255+
self.pending_requests = {}
256+
251257
def add_token(self, request):
252258
"""Adds the OAuth2 token to a HTTP request.
253259
@@ -1043,4 +1049,5 @@ def set_logged_in_user(self, user_data):
10431049
for (user_id, request) in self.pending_requests.values():
10441050
if user_id == self.logged_in_user['data']['id']:
10451051
request()
1046-
self.pending_requests = {}
1052+
# Clear the pending actions queue, just to be sure.
1053+
self.clear_pending_requests()

QOpenScienceFramework/widgets/osfexplorer.py

+16-30
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ def __create_properties_pane(self):
318318
labelStyle = 'font-weight: bold'
319319

320320
self.common_fields = ['Name','Type']
321-
self.file_fields = ['Size','Created','Modified','Link']
321+
self.file_fields = ['Size','Created','Modified','Online']
322322

323323
self.properties = {}
324324
for field in self.common_fields + self.file_fields:
325325
label = QtWidgets.QLabel(_(field))
326326
label.setStyleSheet(labelStyle)
327-
if field == "Link":
327+
if field == "Online":
328328
# Initialize label with some HTML to trigger the rich text mode
329329
value = QtWidgets.QLabel('<a></a>')
330330
value.setOpenExternalLinks(True)
@@ -538,36 +538,22 @@ def set_file_properties(self, data):
538538
for field in self.properties[row]:
539539
field.show()
540540

541-
# Get the link to the file on the website of OSF. This is not readily
542-
# available from the returned API data, but can be parsed from the
543-
# comments URL, of which it is the [target] filter parameter
541+
# Get the link to the file on the website of OSF.
544542
# Sadly, this is URL is not always available for all files, so hide the
545-
# row if parsing fails.
546-
try:
547-
comments_url = data["relationships"]["comments"]["links"]["related"]\
548-
["href"]
549-
except KeyError as e:
550-
warnings.warn('Could not retrieve comments url, because of missing field {}'.format(e))
551-
self.properties["Link"][0].hide()
552-
self.properties["Link"][1].hide()
543+
# row if the GUID is not provided.
544+
545+
guid = data["attributes"]["guid"]
546+
if guid is None:
547+
self.properties["Online"][0].hide()
548+
self.properties["Online"][1].hide()
553549
else:
554-
# Use regular expression to search for the relevant part of the url
555-
try:
556-
target = re.search('filter\[target\]\=\w+', comments_url).group(0)
557-
except AttributeError:
558-
# If this didn't work, hide the row altogether
559-
self.properties["Link"][0].hide()
560-
self.properties["Link"][1].hide()
561-
else:
562-
# Get the ID part of the filter parameter and generate the url
563-
web_id = target.split("=")[1]
564-
web_url = u"{}/{}".format(osf.settings['website_url'], web_id)
565-
a = u"<a href=\"{0}\">{0}</a>".format(web_url)
566-
# Set the URL in the field
567-
self.properties["Link"][1].setText(a)
568-
# Show the row
569-
self.properties["Link"][0].show()
570-
self.properties["Link"][1].show()
550+
web_url = u"{}/{}".format(osf.settings['website_url'], guid)
551+
a = u"<a href=\"{0}\">{0}</a>".format(web_url)
552+
# Set the URL in the field
553+
self.properties["Online"][1].setText(a)
554+
# Show the row
555+
self.properties["Online"][0].show()
556+
self.properties["Online"][1].show()
571557

572558
def set_folder_properties(self, data):
573559
"""

QOpenScienceFramework/widgets/projecttree.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,14 @@ def refresh_contents(self):
427427
time depending on the number of projects that the user has, so it is
428428
recommended to use a partial refresh (refresh_children_of_node), wherever
429429
you can. """
430+
430431
# If tree is already refreshing, don't start again, as this will result
431432
# in a crash
432-
if self.isRefreshing == True:
433+
if self.isRefreshing:
433434
return
434435
# Set flag that tree is currently refreshing
435436
self.isRefreshing = True
437+
436438
# Save current item selection to restore it after refresh
437439
current_item = self.currentItem()
438440
if current_item:
@@ -651,7 +653,8 @@ def process_repo_contents(self, logged_in_user):
651653
def handle_login(self):
652654
""" Callback function for EventDispatcher when a login event is detected. """
653655
self.active_requests = []
654-
self.refresh_contents()
656+
if not self.isRefreshing:
657+
self.refresh_contents()
655658

656659
def handle_logout(self):
657660
""" Callback function for EventDispatcher when a logout event is detected. """

setup.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env python
22

3-
import os
4-
import glob
53
import QOpenScienceFramework
64
from setuptools import setup
75

@@ -32,4 +30,4 @@
3230
],
3331
include_package_data=True,
3432
packages = ['QOpenScienceFramework'],
35-
)
33+
)

0 commit comments

Comments
 (0)