Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
PEDASI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Research Software Group
PEDASI
Commits
b810c228
Commit
b810c228
authored
6 years ago
by
James Graham
Browse files
Options
Downloads
Patches
Plain Diff
Refactor data connector plugin selection into DataSource model
parent
8e6d59b0
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
datasources/connectors/iotuk.py
+0
-3
0 additions, 3 deletions
datasources/connectors/iotuk.py
datasources/models.py
+15
-0
15 additions, 0 deletions
datasources/models.py
datasources/views.py
+3
-6
3 additions, 6 deletions
datasources/views.py
with
18 additions
and
9 deletions
datasources/connectors/iotuk.py
+
0
−
3
View file @
b810c228
...
...
@@ -8,9 +8,6 @@ from .base import BaseDataConnector
class
IoTUK
(
BaseDataConnector
):
name
=
'
IoTUK
'
def
__init__
(
self
,
url
=
'
https://api.iotuk.org.uk/iotOrganisation
'
):
super
().
__init__
(
location
=
url
)
def
get_data
(
self
,
dataset
:
typing
.
Optional
[
str
]
=
None
,
query_params
:
typing
.
Optional
[
typing
.
Mapping
[
str
,
str
]]
=
None
):
...
...
This diff is collapsed.
Click to expand it.
datasources/models.py
+
15
−
0
View file @
b810c228
...
...
@@ -3,6 +3,8 @@ from django.contrib.auth.models import Group
from
django.db
import
models
from
django.urls
import
reverse
from
datasources.connectors.base
import
BaseDataConnector
#: Length of CharFields used to hold the names of objects
MAX_LENGTH_NAME
=
63
...
...
@@ -61,6 +63,19 @@ class DataSource(models.Model):
plugin_name
=
models
.
CharField
(
max_length
=
MAX_LENGTH_NAME
,
blank
=
False
,
null
=
False
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
_data_connector
=
None
@property
def
data_connector
(
self
):
if
self
.
_data_connector
is
None
:
BaseDataConnector
.
load_plugins
(
'
datasources/connectors
'
)
plugin
=
BaseDataConnector
.
get_plugin
(
self
.
plugin_name
)
self
.
_data_connector
=
plugin
(
self
.
url
)
return
self
.
_data_connector
def
has_view_permission
(
self
,
user
:
settings
.
AUTH_USER_MODEL
)
->
bool
:
"""
Does a user have permission to use this data source?
...
...
This diff is collapsed.
Click to expand it.
datasources/views.py
+
3
−
6
View file @
b810c228
...
...
@@ -2,7 +2,6 @@ from django.views.generic.detail import DetailView
from
django.views.generic.list
import
ListView
from
profiles.permissions
import
OwnerPermissionRequiredMixin
from
datasources.connectors.base
import
BaseDataConnector
from
datasources
import
models
...
...
@@ -39,10 +38,8 @@ class DataSourceQueryView(DetailView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
().
get_context_data
(
**
kwargs
)
BaseDataConnector
.
load_plugins
(
'
datasources/connectors
'
)
plugin
=
BaseDataConnector
.
get_plugin
(
self
.
object
.
plugin_name
)
with
plugin
(
'
https://api.iotuk.org.uk/iotOrganisation
'
)
as
connector
:
context
[
'
results
'
]
=
connector
.
get_data
(
query_params
=
{
'
year
'
:
2018
})
context
[
'
results
'
]
=
self
.
object
.
data_connector
.
get_data
(
query_params
=
{
'
year
'
:
2018
}
)
return
context
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment