Skip to content

Commit

Permalink
enh: implement DBInterrogator functions for generating a private user…
Browse files Browse the repository at this point in the history
… DB (#5)
  • Loading branch information
paulmueller committed Sep 6, 2021
1 parent 77608cb commit 91a9a7a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 71 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- feat: implement download manager
- enh: allow to download all resources of a collection (#13)
- enh: implement search for packages the user has access to
- enh: implement DBInterrogator functions for generating a private
user db (partly #5)
- ref: simplify `dbmodel` submodule (just use Interrogator)
- ref: expand dedicated `api` submodule (moved dunctions from
`upload.dataset`)
Expand Down
4 changes: 3 additions & 1 deletion dcoraid/dbmodel/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .db_api import APIInterrogator # noqa: F401
# flake8: noqa: F401
from .db_api import APIInterrogator
from .extract import DBExtract
36 changes: 17 additions & 19 deletions dcoraid/gui/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import pathlib
import traceback

import pkg_resources
import shutil
import signal
Expand All @@ -14,7 +16,7 @@
from PyQt5 import uic, QtCore, QtGui, QtWidgets

from ..api import APIKeyError
from ..dbmodel import APIInterrogator
from ..dbmodel import APIInterrogator, DBExtract
from .._version import version as __version__

from .api import get_ckan_api
Expand Down Expand Up @@ -101,11 +103,8 @@ def __init__(self, *args, **kwargs):
self.timer.timeout.connect(self.refresh_login_status)
self.timer.start(300000)

# Update private data tab
self.refresh_private_data()
# If a new dataset has been uploaded, refresh private data
# TODO: only add one dataset instead of downloading everything again.
self.panel_upload.upload_finished.connect(self.refresh_private_data)
# Signals for user datasets (my data)
self.pushButton_user_refresh.clicked.connect(self.refresh_private_data)

# Signals for public data browser
self.pushButton_public_search.clicked.connect(self.on_public_search)
Expand All @@ -114,11 +113,12 @@ def __init__(self, *args, **kwargs):
self.public_filter_chain.download_resource.connect(
self.panel_download.download_resource)

QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents,
300)

# Run wizard if necessary
if ((self.settings.value("user scenario", "") != "anonymous")
and not self.settings.value("auth/api key", "")):
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents,
300)
# User has not done anything yet
self.on_wizard()

Expand Down Expand Up @@ -223,22 +223,20 @@ def refresh_login_status(self):
icon=icon,
server=api.server)

@run_async
@QtCore.pyqtSlot()
def refresh_private_data(self):
self.tab_user.setCursor(QtCore.Qt.WaitCursor)
return
# TODO:
# - what happens if the user changes the server? Ask to restart?
api = get_ckan_api()
data = DBExtract()
if api.is_available() and api.api_key:
ai = APIInterrogator(api=api, mode="user")
try:
db_extract = ai.get_datasets_user()
except APIKeyError:
pass
else:
self.user_filter_chain.set_db_extract(db_extract)
ai = APIInterrogator(api=api)
if self.checkBox_user_following.isChecked():
data += ai.get_datasets_user_following()
if self.checkBox_user_owned.isChecked():
data += ai.get_datasets_user_owned()
if self.checkBox_user_shared.isChecked():
data += ai.get_datasets_user_shared()
self.user_filter_chain.set_db_extract(data)
self.tab_user.setCursor(QtCore.Qt.ArrowCursor)


Expand Down
84 changes: 33 additions & 51 deletions dcoraid/gui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<bool>true</bool>
</property>
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tab_browse">
<attribute name="icon">
<iconset theme="globe">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</attribute>
<attribute name="title">
<string>Public Data</string>
Expand Down Expand Up @@ -108,68 +108,43 @@
</layout>
</widget>
<widget class="QWidget" name="tab_user">
<property name="enabled">
<bool>false</bool>
</property>
<attribute name="icon">
<iconset theme="street-view">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</attribute>
<attribute name="title">
<string>My Data</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="user_search">
<property name="placeholderText">
<string>Search my data on DCOR...</string>
<widget class="QCheckBox" name="checkBox_user_owned">
<property name="text">
<string>uploaded by me</string>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QCheckBox" name="checkBox_user_shared">
<property name="text">
<string>shared with me</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Private and public data</string>
</property>
</item>
<item>
<property name="text">
<string>Public data only</string>
</property>
</item>
<item>
<property name="text">
<string>Private data only</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<widget class="QCheckBox" name="checkBox_user_following">
<property name="text">
<string>Include data shared with me</string>
<string>followed by me</string>
</property>
<property name="checked">
<bool>true</bool>
Expand All @@ -189,6 +164,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_user_refresh">
<property name="text">
<string>Update</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down Expand Up @@ -216,7 +198,7 @@
</property>
<attribute name="icon">
<iconset theme="people-arrows">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</attribute>
<attribute name="title">
<string>Sharing</string>
Expand Down Expand Up @@ -353,7 +335,7 @@
<widget class="QWidget" name="tab_upload">
<attribute name="icon">
<iconset theme="upload">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</attribute>
<attribute name="title">
<string>Uploads</string>
Expand All @@ -379,7 +361,7 @@
<widget class="QWidget" name="tab_download">
<attribute name="icon">
<iconset theme="download">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</attribute>
<attribute name="title">
<string>Downloads</string>
Expand All @@ -405,7 +387,7 @@
<widget class="QWidget" name="tab_maintain">
<attribute name="icon">
<iconset theme="broom">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</attribute>
<attribute name="title">
<string>Maintenance</string>
Expand Down Expand Up @@ -453,7 +435,7 @@
<action name="actionSoftware">
<property name="icon">
<iconset theme="code-branch">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<property name="text">
<string>Software</string>
Expand All @@ -467,7 +449,7 @@
<action name="actionQuit">
<property name="icon">
<iconset theme="times-circle">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<property name="text">
<string>Quit</string>
Expand All @@ -481,7 +463,7 @@
<action name="actionPreferences">
<property name="icon">
<iconset theme="cogs">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<property name="text">
<string>Preferences...</string>
Expand All @@ -490,7 +472,7 @@
<action name="actionAbout">
<property name="icon">
<iconset theme="info">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<property name="text">
<string>About</string>
Expand All @@ -499,7 +481,7 @@
<action name="actionSetupWizard">
<property name="icon">
<iconset theme="hat-wizard">
<normaloff>.</normaloff>.</iconset>
<normaloff>../../../../.designer/backup</normaloff>../../../../.designer/backup</iconset>
</property>
<property name="text">
<string>Setup wizard...</string>
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dbmodel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_get_circles():
db = db_api.APIInterrogator(api=api)
circles = db.get_circles()
assert common.CIRCLE in circles
# requires that the "dcoraid" user is in the figshare-import circle
assert "figshare-import" in circles


Expand All @@ -24,6 +25,7 @@ def test_get_collections():
db = db_api.APIInterrogator(api=api)
collections = db.get_collections()
assert common.COLLECTION in collections
# requires that the "dcoraid" user is in the figshare-collection collection
assert "figshare-collection" in collections


Expand Down

0 comments on commit 91a9a7a

Please sign in to comment.