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
06da1e9d
Commit
06da1e9d
authored
8 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
Improve commentaries.forms PEP
parent
f9379ec0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
commentaries/forms.py
+6
-5
6 additions, 5 deletions
commentaries/forms.py
scipost/factories.py
+1
-1
1 addition, 1 deletion
scipost/factories.py
with
7 additions
and
6 deletions
commentaries/forms.py
+
6
−
5
View file @
06da1e9d
...
@@ -47,7 +47,7 @@ class RequestCommentaryForm(forms.ModelForm):
...
@@ -47,7 +47,7 @@ class RequestCommentaryForm(forms.ModelForm):
# Either Arxiv-ID or DOI is given
# Either Arxiv-ID or DOI is given
if
not
cleaned_data
[
'
arxiv_identifier
'
]
and
not
cleaned_data
[
'
pub_DOI
'
]:
if
not
cleaned_data
[
'
arxiv_identifier
'
]
and
not
cleaned_data
[
'
pub_DOI
'
]:
msg
=
(
'
You must provide either a DOI (for a published paper)
'
msg
=
(
'
You must provide either a DOI (for a published paper)
'
'
or an arXiv identifier (for a preprint).
'
)
'
or an arXiv identifier (for a preprint).
'
)
self
.
add_error
(
'
arxiv_identifier
'
,
msg
)
self
.
add_error
(
'
arxiv_identifier
'
,
msg
)
self
.
add_error
(
'
pub_DOI
'
,
msg
)
self
.
add_error
(
'
pub_DOI
'
,
msg
)
elif
(
cleaned_data
[
'
arxiv_identifier
'
]
and
elif
(
cleaned_data
[
'
arxiv_identifier
'
]
and
...
@@ -61,14 +61,14 @@ class RequestCommentaryForm(forms.ModelForm):
...
@@ -61,14 +61,14 @@ class RequestCommentaryForm(forms.ModelForm):
elif
(
cleaned_data
[
'
pub_DOI
'
]
and
elif
(
cleaned_data
[
'
pub_DOI
'
]
and
Commentary
.
objects
.
filter
(
pub_DOI
=
cleaned_data
[
'
pub_DOI
'
]).
exists
()):
Commentary
.
objects
.
filter
(
pub_DOI
=
cleaned_data
[
'
pub_DOI
'
]).
exists
()):
msg
=
'
There already exists a Commentary Page on this publication, see
'
msg
=
'
There already exists a Commentary Page on this publication, see
'
self
.
existing_commentary
=
get_object_or_404
(
Commentary
,
pub_DOI
=
cleaned_data
[
'
pub_DOI
'
])
self
.
existing_commentary
=
get_object_or_404
(
Commentary
,
pub_DOI
=
cleaned_data
[
'
pub_DOI
'
])
self
.
add_error
(
'
pub_DOI
'
,
msg
)
self
.
add_error
(
'
pub_DOI
'
,
msg
)
# Current user is not known
# Current user is not known
if
not
self
.
user
or
not
Contributor
.
objects
.
filter
(
user
=
self
.
user
).
exists
():
if
not
self
.
user
or
not
Contributor
.
objects
.
filter
(
user
=
self
.
user
).
exists
():
self
.
add_error
(
None
,
'
Sorry, current user is not known to SciPost.
'
)
self
.
add_error
(
None
,
'
Sorry, current user is not known to SciPost.
'
)
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
"""
Prefill instance before save
"""
"""
Prefill instance before save
"""
self
.
instance
.
requested_by
=
Contributor
.
objects
.
get
(
user
=
self
.
user
)
self
.
instance
.
requested_by
=
Contributor
.
objects
.
get
(
user
=
self
.
user
)
...
@@ -135,7 +135,8 @@ class VetCommentaryForm(forms.Form):
...
@@ -135,7 +135,8 @@ class VetCommentaryForm(forms.Form):
self
.
add_error
(
None
,
'
No `commentary_id` provided
'
)
self
.
add_error
(
None
,
'
No `commentary_id` provided
'
)
return
cleaned_data
return
cleaned_data
else
:
else
:
self
.
commentary
=
Commentary
.
objects
.
select_related
(
'
requested_by__user
'
).
get
(
pk
=
self
.
commentary_id
)
self
.
commentary
=
Commentary
.
objects
.
select_related
(
'
requested_by__user
'
).
get
(
pk
=
self
.
commentary_id
)
# Check valid `user`
# Check valid `user`
if
not
self
.
user
:
if
not
self
.
user
:
...
@@ -149,7 +150,7 @@ class VetCommentaryForm(forms.Form):
...
@@ -149,7 +150,7 @@ class VetCommentaryForm(forms.Form):
"""
Raise ValueError if form isn
'
t validated
"""
"""
Raise ValueError if form isn
'
t validated
"""
if
not
self
.
is_cleaned
:
if
not
self
.
is_cleaned
:
raise
ValueError
((
'
VetCommentaryForm could not be processed
'
raise
ValueError
((
'
VetCommentaryForm could not be processed
'
'
because the data didn
\'
t validate
'
))
'
because the data didn
\'
t validate
'
))
def
get_commentary
(
self
):
def
get_commentary
(
self
):
"""
Return Commentary if available
"""
"""
Return Commentary if available
"""
...
...
This diff is collapsed.
Click to expand it.
scipost/factories.py
+
1
−
1
View file @
06da1e9d
import
factory
import
factory
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.models
import
Group
,
User
from
django.contrib.auth.models
import
Group
from
.models
import
Contributor
from
.models
import
Contributor
...
...
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