Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Versioning support #107

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
eb10887
WIP: Version controlled database models
u8sand Sep 7, 2018
6cc6fcd
WIP: Version controlled database models
u8sand Sep 10, 2018
fd7b5b3
Versioned migrations
u8sand Sep 10, 2018
c84a652
Completed migrations to new Database
u8sand Sep 10, 2018
13432c9
objects -> objects.current
u8sand Sep 10, 2018
c81ce76
WIP: refactoring of FAIRshakeAPI.views for version controlled assessment
u8sand Sep 10, 2018
6c57718
Base64-serialize uuid fields
u8sand Sep 11, 2018
c1a5f98
Enabled multiple urls to be specified
u8sand Sep 12, 2018
9fe1bd4
Added cache table directions to README
u8sand Sep 12, 2018
48a3d44
Added slug fields (defaulting to uuid)
u8sand Sep 12, 2018
38c7ef5
Merge branch 'master' into versioning
u8sand Sep 12, 2018
766d729
Made FAIRsharing automated assessment use DOI
u8sand Sep 12, 2018
dc75488
Removed author name search vector
u8sand Sep 13, 2018
bb8aaa6
Added quotes to data-target ids--now slugs
u8sand Sep 13, 2018
0d88c51
Ensure slugs don't collide with object ids as that will be a fallback
u8sand Sep 13, 2018
e29bc8b
Added coverage and information on running tests
u8sand Sep 13, 2018
c63b084
Wrote some FAIRshake API unit tests
u8sand Sep 13, 2018
ff01228
Wrote some FAIRshakeHub unit tests
u8sand Sep 13, 2018
affc675
Permissions fix for Assessment list/retrieve
u8sand Sep 13, 2018
cad977f
CustomUUIDField handle None value
u8sand Sep 13, 2018
7ae2bb0
Fixed VersionQueryEx edge case (instance is str)
u8sand Sep 13, 2018
96fd16c
Moved CustomRouter to extensions.rest_framework_ex
u8sand Sep 13, 2018
6e0d1d5
Fixed assessment object query model names
u8sand Sep 13, 2018
b60a90f
Merge branch 'master' into versioning
u8sand Sep 17, 2018
d72de8a
Merge branch 'master' into versioning
u8sand Sep 17, 2018
8aeac02
Merge branch 'master' into versioning
u8sand Sep 17, 2018
8983efc
Added unique_together constraints on assessment and answers
u8sand Sep 17, 2018
359bf97
Merge branch 'master' into versioning
u8sand Sep 18, 2018
448ef7c
Merge branch 'master' into versioning
u8sand Sep 18, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FAIRshake/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'corsheaders',
'ajax_select',
'analytical',
'versions_tests',
'allauth',
'allauth.account',
'allauth.socialaccount',
Expand All @@ -73,6 +74,7 @@
'extensions.allauth_ex',
'extensions.drf_yasg_ex',
'extensions.rest_auth_ex',
'extensions.versions_ex',
'extensions.rest_framework_ex',
'FAIRshakeHub',
'FAIRshakeAPI',
Expand Down
94 changes: 46 additions & 48 deletions FAIRshakeAPI/assessments/fairsharing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,59 @@
import re
from django.conf import settings
from scripts.pyswagger_wrapper import SwaggerClient

url_re = re.compile(r'^https?://doi.org/(.+)$')

metric_to_attr = {
'metric:9': 'licence',
'metric:60': 'homepage',
'metric:101': 'taxonomies',
'metric:102': 'domains',
}

class Assessment:
inputs = [
'target:fairsharing'
'target:url'
]
outputs = [
# 'target:url',
# 'target:description',
# 'target:title',
# 'target:doi',
# 'target:authors'
'metric:9', # license
'metric:60', # title
'metric:101', # taxonomies
'metric:102', # domains
]
] + list(metric_to_attr.keys())

@classmethod
def perform(kls, inputs):
client = SwaggerClient(
'https://fairsharing.org/api/?format=openapi',
headers={
'Api-Key': settings.ASSESSMENT_CONFIG['fairsharing']['api-key'],
}
)
results = client.actions.database_summary_read.call(
bsg_id=inputs['target:fairsharing']
)
return {
# 'target:url': {
# 'answer': results['data'].get('homepage'),
# 'comment': results['data'].get('homepage'),
# },
# 'target:description': {
# 'answer': results['data'].get('description'),
# 'comment': results['data'].get('description'),
# },
# 'target:title': {
# 'answer': results['data'].get('name'),
# 'comment': results['data'].get('name'),
# },
'metric:9': {
'answer': 'yes' if results.get('licence') else 'no',
'comment': results.get('licence'),
},
'metric:60': {
'answer': 'yes' if results['data'].get('homepage') is not None else 'no',
'comment': results['data'].get('homepage'),
},
'metric:101': {
'answer': 'yes' if results['data'].get('taxonomies') else 'no',
'comment': results['data'].get('taxonomies'),
},
'metric:102': {
'answer': 'yes' if results['data'].get('domains') else 'no',
'comment': results['data'].get('domains'),
},
# 'target:doi': results['data'].get('doi'),
# 'target:authors': results['data'].get('maintainers'),
}
url = inputs['target:url']
dois = [m.group(1) for m in map(url_re.match, url.splitlines()) if m]

if dois:
client = SwaggerClient(
'https://fairsharing.org/api/?format=openapi',
headers={
'Api-Key': settings.ASSESSMENT_CONFIG['fairsharing']['api-key'],
}
)

results = [
result
for doi in dois
for result in client.actions.database_summary_list.call(
doi=doi,
)['results']
]

if len(results) > 1:
logging.warn('More than 1 DOI was identified in the fairsharing database! (%s)' % (url))
if len(results) >= 1:
data = results[0]['data']
else:
data = None

return {
key: {
'answer': 'yes' if data.get(attr) else 'no',
'comment': data.get(attr),
}
for key, attr in metric_to_attr.items()
} if data else {key: {} for key in metric_to_attr.keys()}
37 changes: 19 additions & 18 deletions FAIRshakeAPI/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ def __init__(self, *args, **kwargs):
help_text=None,
initial=getattr(self.instance, child).all() if self.instance and self.instance.id else [],
)


def clean_slug(self):
slug = self.cleaned_data.get('slug')
try:
if any([
self.Meta.model.objects.current.get(slug=slug) != self.instance,
self.Meta.model.objects.get(id=slug) != self.instance,
]):
raise forms.ValidationError(
'Slug was already taken, please try something different.'
)
except self.Meta.model.DoesNotExist:
pass
return slug

def save(self, *args, commit=True, **kwargs):
''' Explicitly add children for children in the reverse direction.
'''
Expand All @@ -43,6 +57,7 @@ class Meta:
'image',
'tags',
'type',
'slug',
'digital_objects',
'authors',
)
Expand All @@ -57,6 +72,7 @@ class Meta:
'image',
'tags',
'type',
'slug',
'rubrics',
'authors',
)
Expand All @@ -71,6 +87,7 @@ class Meta:
'image',
'tags',
'type',
'slug',
'license',
'metrics',
'authors',
Expand All @@ -86,27 +103,11 @@ class Meta:
'image',
'tags',
'type',
'slug',
'license',
'rationale',
'principle',
'fairmetrics',
'authors',
)

class AssessmentForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(AssessmentForm, self).__init__(*args, **kwargs)

self.fields['target'].widget = forms.HiddenInput()
self.fields['rubric'].widget = forms.HiddenInput()
self.fields['project'].widget = forms.HiddenInput()

class Meta:
model = models.Assessment
fields = (
'target',
'rubric',
'project',
)

class AnswerForm(forms.ModelForm):
Expand Down
Loading