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
42fdf2ff
Commit
42fdf2ff
authored
4 years ago
by
Jean-Sébastien Caux
Browse files
Options
Downloads
Patches
Plain Diff
More partial work
parent
e62e637c
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
submissions/forms.py
+82
-50
82 additions, 50 deletions
submissions/forms.py
submissions/views.py
+6
-8
6 additions, 8 deletions
submissions/views.py
with
88 additions
and
58 deletions
submissions/forms.py
+
82
−
50
View file @
42fdf2ff
...
...
@@ -438,9 +438,10 @@ class SciPostPrefillForm(SubmissionPrefillForm):
'
referees_suggested
'
:
self
.
latest_submission
.
referees_suggested
,
'
secondary_areas
'
:
self
.
latest_submission
.
secondary_areas
,
'
subject_area
'
:
self
.
latest_submission
.
subject_area
,
'
submitted_to
'
:
self
.
journal
,
'
submitted_to
'
:
self
.
journal
.
id
,
'
submission_type
'
:
self
.
latest_submission
.
submission_type
,
'
thread_hash
'
:
self
.
latest_submission
.
thread_hash
,
'
is_resubmission_of
'
:
self
.
latest_submission
.
id
}
return
{}
...
...
@@ -460,41 +461,60 @@ class ArXivPrefillForm(SubmissionPrefillForm):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
preprint_server
=
'
arXiv
'
self
.
arxiv_data
=
None
self
.
metadata
=
None
super
().
__init__
(
*
args
,
**
kwargs
)
def
run_checks
(
self
):
super
().
run_checks
()
# TODO: add others here like self._check_if_already_published()
def
clean_arxiv_identifier_w_vn_nr
(
self
):
"""
Do basic prechecks based on the arXiv ID only.
"""
identifier
=
self
.
cleaned_data
.
get
(
'
arxiv_identifier_w_vn_nr
'
,
None
)
self
.
service
=
SubmissionService
(
self
.
requested_by
,
'
arxiv
'
,
identifier
=
identifier
,
thread_hash
=
self
.
thread_hash
)
self
.
service
.
run_checks
()
caller
=
ArxivCaller
(
identifier
)
if
caller
.
is_valid
:
self
.
arxiv_data
=
caller
.
data
self
.
metadata
=
caller
.
metadata
else
:
error_message
=
'
A preprint associated to this identifier does not exist.
'
raise
forms
.
ValidationError
(
error_message
)
# Check if identifier has already been used for submission
if
Submission
.
objects
.
filter
(
preprint__identifier_w_vn_nr
=
identifier
).
exists
():
error_message
=
'
This preprint version has already been submitted to SciPost.
'
raise
forms
.
ValidationError
(
error_message
,
code
=
'
duplicate
'
)
# Check if this paper has already been published (according to arXiv)
published_id
=
None
if
'
arxiv_doi
'
in
self
.
arxiv_data
:
published_id
=
self
.
arxiv_data
[
'
arxiv_doi
'
]
elif
'
arxiv_journal_ref
'
in
self
.
arxiv_data
:
published_id
=
self
.
arxiv_data
[
'
arxiv_journal_ref
'
]
if
published_id
:
error_message
=
(
'
This paper has been published under DOI %(published_id)s.
'
'
It cannot be submitted again.
'
),
raise
forms
.
ValidationError
(
error_message
,
code
=
'
published
'
,
params
=
{
'
published_id
'
:
published_id
})
return
identifier
def
get_prefill_data
(
self
):
"""
Return dictionary to prefill `SubmissionForm`.
"""
form_data
=
self
.
service
.
arxiv_data
form_data
[
'
identifier_w_vn_nr
'
]
=
self
.
cleaned_data
[
'
identifier_w_vn_nr
'
]
if
self
.
service
.
is_resubmission
():
form_data
=
self
.
arxiv_data
form_data
[
'
identifier_w_vn_nr
'
]
=
self
.
cleaned_data
[
'
arxiv_identifier_w_vn_nr
'
]
form_data
[
'
discipline
'
]
=
self
.
journal
.
discipline
form_data
[
'
submitted_to
'
]
=
self
.
journal
.
id
if
self
.
is_resubmission
():
form_data
.
update
({
'
discipline
'
:
self
.
service
.
latest_submission
.
discipline
,
'
approaches
'
:
self
.
service
.
latest_submission
.
approaches
,
'
referees_flagged
'
:
self
.
service
.
latest_submission
.
referees_flagged
,
'
referees_suggested
'
:
self
.
service
.
latest_submission
.
referees_suggested
,
'
secondary_areas
'
:
self
.
service
.
latest_submission
.
secondary_areas
,
'
subject_area
'
:
self
.
service
.
latest_submission
.
subject_area
,
'
submitted_to
'
:
self
.
journal
,
'
submission_type
'
:
self
.
service
.
latest_submission
.
submission_type
,
'
thread_hash
'
:
self
.
service
.
latest_submission
.
thread_hash
'
approaches
'
:
self
.
latest_submission
.
approaches
,
'
referees_flagged
'
:
self
.
latest_submission
.
referees_flagged
,
'
referees_suggested
'
:
self
.
latest_submission
.
referees_suggested
,
'
secondary_areas
'
:
self
.
latest_submission
.
secondary_areas
,
'
subject_area
'
:
self
.
latest_submission
.
subject_area
,
'
submission_type
'
:
self
.
latest_submission
.
submission_type
,
'
thread_hash
'
:
self
.
latest_submission
.
thread_hash
})
return
form_data
...
...
@@ -560,49 +580,60 @@ class SubmissionForm(forms.ModelForm):
}
def
__init__
(
self
,
*
args
,
**
kwargs
):
print
(
"
form kwargs[
'
initial
'
]: %s
"
%
kwargs
[
'
initial
'
])
self
.
requested_by
=
kwargs
.
pop
(
'
requested_by
'
)
self
.
preprint_server
=
kwargs
.
pop
(
'
preprint_server
'
,
'
arxiv
'
)
data
=
args
[
0
]
if
len
(
args
)
>
1
else
kwargs
.
get
(
'
data
'
,
{})
identifier
=
kwargs
[
'
initial
'
].
get
(
'
identifier_w_vn_nr
'
,
None
)
or
data
.
get
(
'
identifier_w_vn_nr
'
)
thread_hash
=
kwargs
[
'
initial
'
].
get
(
'
thread_hash
'
,
None
)
self
.
service
=
SubmissionService
(
self
.
requested_by
,
self
.
preprint_server
,
identifier
=
identifier
,
thread_hash
=
thread_hash
)
self
.
preprint_server
=
kwargs
.
pop
(
'
preprint_server
'
)
self
.
thread_hash
=
kwargs
[
'
initial
'
].
get
(
'
thread_hash
'
,
None
)
# print("form args:\n", args)
# print("form kwargs:\n", kwargs)
# print("is_resubmission: %s" % self.is_resubmission())
# data = args[0] if len(args) > 1 else kwargs.get('data', {})
# identifier = kwargs['initial'].get('identifier_w_vn_nr', None) or data.get('identifier_w_vn_nr')
# thread_hash = kwargs['initial'].get('thread_hash', None)
# self.service = SubmissionService(
# self.requested_by, self.preprint_server,
# identifier=identifier,
# thread_hash=thread_hash)
# if self.preprint_server == 'scipost':
# kwargs['initial'] = self.service.get_latest_submission_data()
super
().
__init__
(
*
args
,
**
kwargs
)
if
not
self
.
preprint_server
==
'
arxiv
'
:
#
No arXiv-specific data requir
ed
.
if
self
.
preprint_server
==
'
SciPost
'
:
#
SciPost identifier will be auto-generat
ed
del
self
.
fields
[
'
identifier_w_vn_nr
'
]
del
self
.
fields
[
'
arxiv_link
'
]
elif
not
self
.
preprint_server
==
'
scipost
'
:
else
:
# No need for a file upload if user is not using the SciPost preprint server.
del
self
.
fields
[
'
preprint_file
'
]
# Delete preprint server-specific fields
if
not
self
.
preprint_server
==
'
arXiv
'
:
# No arXiv-specific data required.
del
self
.
fields
[
'
arxiv_link
'
]
# Find all submission allowed to be resubmitted by current user.
self
.
fields
[
'
is_resubmission_of
'
].
queryset
=
Submission
.
objects
.
candidate_for_resubmission
(
self
.
requested_by
)
#
#
Find all submission allowed to be resubmitted by current user.
#
self.fields['is_resubmission_of'].queryset = Submission.objects.candidate_for_resubmission(
#
self.requested_by)
# Fill resubmission-dependent fields
if
self
.
is_resubmission
():
self
.
fields
[
'
is_resubmission_of
'
].
initial
=
self
.
service
.
latest_submission
else
:
# These fields are only available for resubmissions.
del
self
.
fields
[
'
author_comments
'
]
del
self
.
fields
[
'
list_of_changes
'
]
# # Fill resubmission-dependent fields
# if self.is_resubmission():
# self.fields['is_resubmission_of'].initial = self.service.latest_submission
# else:
# # These fields are only available for resubmissions.
# del self.fields['author_comments']
# del self.fields['list_of_changes']
# if not self.fields['is_resubmission_of'].initial:
# # No intial nor submitted data found.
# del self.fields['is_resubmission_of']
if
not
self
.
fields
[
'
is_resubmission_of
'
].
initial
:
# No intial nor submitted data found.
if
not
self
.
is_resubmission
():
del
self
.
fields
[
'
is_resubmission_of
'
]
del
self
.
fields
[
'
author_comments
'
]
del
self
.
fields
[
'
list_of_changes
'
]
# Select Journal instances.
self
.
fields
[
'
submitted_to
'
].
queryset
=
Journal
.
objects
.
active
().
exclude
(
name
=
'
SciPost Selections
'
)
self
.
fields
[
'
submitted_to
'
].
queryset
=
Journal
.
objects
.
active
().
submission_allowed
(
)
self
.
fields
[
'
submitted_to
'
].
label
=
'
Journal: submit to
'
# Proceedings submission fields
...
...
@@ -616,7 +647,8 @@ class SubmissionForm(forms.ModelForm):
del
self
.
fields
[
'
proceedings
'
]
def
is_resubmission
(
self
):
return
self
.
service
.
is_resubmission
()
# return self.service.is_resubmission()
return
self
.
thread_hash
is
not
None
def
clean
(
self
,
*
args
,
**
kwargs
):
"""
...
...
This diff is collapsed.
Click to expand it.
submissions/views.py
+
6
−
8
View file @
42fdf2ff
...
...
@@ -240,7 +240,6 @@ class RequestSubmissionView(LoginRequiredMixin, PermissionRequiredMixin, CreateV
messages
.
success
(
request
,
readymessage
,
fail_silently
=
True
)
# Gather data from ArXiv API if prefill form is valid
self
.
initial_data
=
self
.
prefill_form
.
get_prefill_data
()
print
(
"
initial data: %s
"
%
self
.
initial_data
)
return
super
().
get
(
request
)
else
:
for
code
,
err
in
self
.
prefill_form
.
errors
.
items
():
...
...
@@ -262,7 +261,7 @@ class RequestSubmissionView(LoginRequiredMixin, PermissionRequiredMixin, CreateV
kwargs
=
super
().
get_form_kwargs
()
kwargs
[
'
requested_by
'
]
=
self
.
request
.
user
kwargs
[
'
initial
'
]
=
getattr
(
self
,
'
initial_data
'
,
{})
kwargs
[
'
initial
'
][
'
resubmission
'
]
=
self
.
request
.
GET
.
get
(
'
resubmission
'
)
#
kwargs['initial']['resubmission'] = self.request.GET.get('resubmission')
# TODO remove
return
kwargs
@transaction.atomic
...
...
@@ -303,15 +302,16 @@ class RequestSubmissionUsingArXivView(RequestSubmissionView):
Redirect to `submit_choose_preprint_server` if arXiv identifier is not known.
"""
self
.
prefill_form
=
ArXivPrefillForm
(
request
.
GET
or
None
,
# identifier_w_vn_nr, [thread_hash]
request
.
GET
or
None
,
requested_by
=
self
.
request
.
user
,
journal_doi_label
=
journal_doi_label
)
journal_doi_label
=
journal_doi_label
,
thread_hash
=
request
.
GET
.
get
(
'
thread_hash
'
))
return
super
().
get
(
request
,
journal_doi_label
)
def
get_form_kwargs
(
self
):
"""
Form requires extra kwargs.
"""
kwargs
=
super
().
get_form_kwargs
()
kwargs
[
'
preprint_server
'
]
=
'
ar
x
iv
'
kwargs
[
'
preprint_server
'
]
=
'
ar
X
iv
'
return
kwargs
...
...
@@ -328,9 +328,7 @@ class RequestSubmissionUsingSciPostView(RequestSubmissionView):
def
get_form_kwargs
(
self
):
"""
Form requires extra kwargs.
"""
kwargs
=
super
().
get_form_kwargs
()
if
hasattr
(
self
,
'
thread_hash
'
):
kwargs
[
'
initial
'
][
'
thread_hash
'
]
=
self
.
thread_hash
kwargs
[
'
preprint_server
'
]
=
'
scipost
'
kwargs
[
'
preprint_server
'
]
=
'
SciPost
'
return
kwargs
...
...
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