SciPost Code Repository
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SciPost
Manage
Activity
Members
Labels
Plan
Issues
118
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SciPost
SciPost
Commits
b96b90b8
Commit
b96b90b8
authored
7 years ago
by
Geert Kapteijns
Browse files
Options
Downloads
Patches
Plain Diff
preliminary test for request commentary view
parent
843484e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
commentaries/forms.py
+12
-8
12 additions, 8 deletions
commentaries/forms.py
commentaries/test_views.py
+16
-1
16 additions, 1 deletion
commentaries/test_views.py
scipost/services.py
+38
-3
38 additions, 3 deletions
scipost/services.py
with
66 additions
and
12 deletions
commentaries/forms.py
+
12
−
8
View file @
b96b90b8
...
...
@@ -10,16 +10,20 @@ from scipost.models import Contributor
class
DOIToQueryForm
(
forms
.
Form
):
VALID_DOI_REGEXP
=
r
'
^(?i)10.\d{4,9}/[-._;()/:A-Z0-9]+$
'
doi
=
forms
.
RegexField
(
regex
=
VALID_DOI_REGEXP
,
strip
=
False
,
widget
=
forms
.
TextInput
(
doi
=
forms
.
CharField
(
widget
=
forms
.
TextInput
(
{
'
label
'
:
'
DOI
'
,
'
placeholder
'
:
'
ex.: 10.21468/00.000.000000
'
}))
def
clean_doi
(
self
):
input_doi
=
self
.
cleaned_data
[
'
doi
'
]
if
Commentary
.
objects
.
filter
(
pub_DOI
=
input_doi
).
exists
():
error_message
=
'
There already exists a Commentary Page on this publication.
'
raise
forms
.
ValidationError
(
error_message
)
return
input_doi
# class DOIToQueryForm(forms.Form):
# VALID_DOI_REGEXP = r'^(?i)10.\d{4,9}/[-._;()/:A-Z0-9]+$'
# doi = forms.RegexField(regex=VALID_DOI_REGEXP, strip=False, widget=forms.TextInput(
# {'label': 'DOI', 'placeholder': 'ex.: 10.21468/00.000.000000'}))
#
# def clean_doi(self):
# input_doi = self.cleaned_data['doi']
# if Commentary.objects.filter(pub_DOI=input_doi).exists():
# error_message = 'There already exists a Commentary Page on this publication.'
# raise forms.ValidationError(error_message)
# return input_doi
class
IdentifierToQueryForm
(
forms
.
Form
):
...
...
This diff is collapsed.
Click to expand it.
commentaries/test_views.py
+
16
−
1
View file @
b96b90b8
...
...
@@ -7,7 +7,7 @@ from scipost.factories import ContributorFactory, UserFactory
from
.factories
import
UnvettedCommentaryFactory
,
VettedCommentaryFactory
,
UnpublishedVettedCommentaryFactory
from
.forms
import
CommentarySearchForm
from
.models
import
Commentary
from
.views
import
RequestCommentary
from
.views
import
RequestCommentary
,
prefill_using_DOI
from
common.helpers.test
import
add_groups_and_permissions
...
...
@@ -35,6 +35,21 @@ class RequestCommentaryTest(TestCase):
raise
NotImplementedError
class
PrefillUsingDOITest
(
TestCase
):
def
setUp
(
self
):
add_groups_and_permissions
()
self
.
target
=
reverse
(
'
commentaries:prefill_using_DOI
'
)
self
.
physrev_doi
=
'
10.1103/PhysRevB.92.214427
'
def
test_submit_valid_physrev_doi
(
self
):
post_data
=
{
'
doi
'
:
self
.
physrev_doi
}
request
=
RequestFactory
().
post
(
self
.
target
,
post_data
)
request
.
user
=
UserFactory
()
response
=
prefill_using_DOI
(
request
)
self
.
assertRedirects
(
response
,
reverse
(
'
commentaries:request_commentary
'
))
class
VetCommentaryRequestsTest
(
TestCase
):
"""
Test cases for `vet_commentary_requests` view method
"""
...
...
This diff is collapsed.
Click to expand it.
scipost/services.py
+
38
−
3
View file @
b96b90b8
...
...
@@ -17,10 +17,45 @@ class DOICaller:
def
_call_crosslink
(
self
):
url
=
'
http://api.crossref.org/works/%s
'
%
self
.
doi_string
self
.
crossref_data
=
requests
.
get
(
url
).
json
()
self
.
crossref_data
=
requests
.
get
(
url
).
json
()[
'
message
'
]
def
_format_data
(
self
):
data
=
self
.
crossref_data
pub_title
=
data
[
'
title
'
][
0
]
authorlist
=
[
'
{} {}
'
.
format
(
author
[
'
given
'
],
author
[
'
family
'
])
for
author
in
data
[
'
author
'
]]
journal
=
data
[
'
container-title
'
][
0
]
volume
=
data
.
get
(
'
volume
'
,
''
)
pages
=
self
.
_get_pages
(
data
)
pub_data
=
self
.
_get_pub_date
(
data
)
def
_get_pages
(
self
,
data
):
# For Physical Review
pages
=
data
.
get
(
'
article-number
'
,
''
)
# For other journals?
pages
=
data
.
get
(
'
page
'
,
''
)
return
pages
def
_get_pub_date
(
self
,
data
):
date_parts
=
data
.
get
(
'
issued
'
,
{}).
get
(
'
date_parts
'
,
{})
date_parts
=
data
[
'
issued
'
][
'
date-parts
'
][
0
]
year
=
date_parts
[
0
]
month
=
date_parts
[
1
]
day
=
date_parts
[
2
]
pub_date
=
"
{}-{}-{}
"
.
format
(
year
,
month
,
day
)
pub_date
=
''
try
:
pub_date
=
(
str
(
data
[
'
message
'
][
'
issued
'
][
'
date-parts
'
][
0
][
0
])
+
'
-
'
+
str
(
data
[
'
message
'
][
'
issued
'
][
'
date-parts
'
][
0
][
1
]))
try
:
pub_date
+=
'
-
'
+
str
(
data
[
'
message
'
][
'
issued
'
][
'
date-parts
'
][
0
][
2
])
except
(
IndexError
,
KeyError
):
pass
except
(
IndexError
,
KeyError
):
pass
def
_collect_data
(
self
):
# read out json here.
...
...
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