Skip to content

Commit

Permalink
Bump to 1.2.1
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
dschreij committed Mar 6, 2017
1 parent 1519c1f commit 748896c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 41 deletions.
2 changes: 1 addition & 1 deletion QOpenScienceFramework/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.2.0"
__version__ = "1.2.1"
__author__ = "Daniel Schreij"

import os
Expand Down
17 changes: 12 additions & 5 deletions QOpenScienceFramework/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ class ConnectionManager(QtNetwork.QNetworkAccessManager):
success_message = QtCore.Signal('QString','QString')
"""PyQt signal to send a success message."""

# Dictionary holding requests in progress, so that they can be repeated if
# mid-request it is discovered that the OAuth2 token is no longer valid.
pending_requests = {}

def __init__(self, *args, **kwargs):
""" Constructor
Expand Down Expand Up @@ -123,6 +119,10 @@ def __init__(self, *args, **kwargs):
# The icon to show on the progress dialog
self._progress_icon = None

# Dictionary holding requests in progress, so that they can be repeated if
# mid-request it is discovered that the OAuth2 token is no longer valid.
self.pending_requests = {}

### properties
@property
def progress_icon(self):
Expand Down Expand Up @@ -248,6 +248,12 @@ def func_wrapper(inst, *args, **kwargs):
return func(inst, *args, **kwargs)
return func_wrapper

def clear_pending_requests(self):
""" Resets the pending network requests that still need to be executed.
Network requests
"""
self.pending_requests = {}

def add_token(self, request):
"""Adds the OAuth2 token to a HTTP request.
Expand Down Expand Up @@ -1043,4 +1049,5 @@ def set_logged_in_user(self, user_data):
for (user_id, request) in self.pending_requests.values():
if user_id == self.logged_in_user['data']['id']:
request()
self.pending_requests = {}
# Clear the pending actions queue, just to be sure.
self.clear_pending_requests()
46 changes: 16 additions & 30 deletions QOpenScienceFramework/widgets/osfexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ def __create_properties_pane(self):
labelStyle = 'font-weight: bold'

self.common_fields = ['Name','Type']
self.file_fields = ['Size','Created','Modified','Link']
self.file_fields = ['Size','Created','Modified','Online']

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

# Get the link to the file on the website of OSF. This is not readily
# available from the returned API data, but can be parsed from the
# comments URL, of which it is the [target] filter parameter
# Get the link to the file on the website of OSF.
# Sadly, this is URL is not always available for all files, so hide the
# row if parsing fails.
try:
comments_url = data["relationships"]["comments"]["links"]["related"]\
["href"]
except KeyError as e:
warnings.warn('Could not retrieve comments url, because of missing field {}'.format(e))
self.properties["Link"][0].hide()
self.properties["Link"][1].hide()
# row if the GUID is not provided.

guid = data["attributes"]["guid"]
if guid is None:
self.properties["Online"][0].hide()
self.properties["Online"][1].hide()
else:
# Use regular expression to search for the relevant part of the url
try:
target = re.search('filter\[target\]\=\w+', comments_url).group(0)
except AttributeError:
# If this didn't work, hide the row altogether
self.properties["Link"][0].hide()
self.properties["Link"][1].hide()
else:
# Get the ID part of the filter parameter and generate the url
web_id = target.split("=")[1]
web_url = u"{}/{}".format(osf.settings['website_url'], web_id)
a = u"<a href=\"{0}\">{0}</a>".format(web_url)
# Set the URL in the field
self.properties["Link"][1].setText(a)
# Show the row
self.properties["Link"][0].show()
self.properties["Link"][1].show()
web_url = u"{}/{}".format(osf.settings['website_url'], guid)
a = u"<a href=\"{0}\">{0}</a>".format(web_url)
# Set the URL in the field
self.properties["Online"][1].setText(a)
# Show the row
self.properties["Online"][0].show()
self.properties["Online"][1].show()

def set_folder_properties(self, data):
"""
Expand Down
7 changes: 5 additions & 2 deletions QOpenScienceFramework/widgets/projecttree.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,14 @@ def refresh_contents(self):
time depending on the number of projects that the user has, so it is
recommended to use a partial refresh (refresh_children_of_node), wherever
you can. """

# If tree is already refreshing, don't start again, as this will result
# in a crash
if self.isRefreshing == True:
if self.isRefreshing:
return
# Set flag that tree is currently refreshing
self.isRefreshing = True

# Save current item selection to restore it after refresh
current_item = self.currentItem()
if current_item:
Expand Down Expand Up @@ -651,7 +653,8 @@ def process_repo_contents(self, logged_in_user):
def handle_login(self):
""" Callback function for EventDispatcher when a login event is detected. """
self.active_requests = []
self.refresh_contents()
if not self.isRefreshing:
self.refresh_contents()

def handle_logout(self):
""" Callback function for EventDispatcher when a logout event is detected. """
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env python

import os
import glob
import QOpenScienceFramework
from setuptools import setup

Expand Down Expand Up @@ -32,4 +30,4 @@
],
include_package_data=True,
packages = ['QOpenScienceFramework'],
)
)

0 comments on commit 748896c

Please sign in to comment.