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
3978f25d
Commit
3978f25d
authored
7 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
Correct Submission factories
parent
8d63be66
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
submissions/factories.py
+49
-17
49 additions, 17 deletions
submissions/factories.py
with
49 additions
and
17 deletions
submissions/factories.py
+
49
−
17
View file @
3978f25d
import
factory
import
datetime
import
pytz
from
django.utils
import
timezone
from
scipost.factories
import
ContributorFactory
from
scipost.models
import
Contributor
from
journals.constants
import
SCIPOST_JOURNALS_DOMAINS
from
common.helpers
import
random_arxiv_identifier_without_version_number
,
random_scipost_journal
from
.constants
import
STATUS_UNASSIGNED
,
STATUS_EIC_ASSIGNED
,
STATUS_RESUBMISSION_INCOMING
,
\
STATUS_PUBLISHED
STATUS_PUBLISHED
,
SUBMISSION_TYPE
from
.models
import
Submission
from
faker
import
Faker
...
...
@@ -21,7 +19,7 @@ class SubmissionFactory(factory.django.DjangoModelFactory):
model
=
Submission
author_list
=
factory
.
Faker
(
'
name
'
)
submitted_by
=
factory
.
SubFactory
(
ContributorFactory
)
submitted_by
=
Contributor
.
objects
.
first
(
)
submitted_to_journal
=
factory
.
Sequence
(
lambda
n
:
random_scipost_journal
())
title
=
factory
.
lazy_attribute
(
lambda
x
:
Faker
().
sentence
())
abstract
=
factory
.
lazy_attribute
(
lambda
x
:
Faker
().
paragraph
())
...
...
@@ -32,7 +30,8 @@ class SubmissionFactory(factory.django.DjangoModelFactory):
abstract
=
Faker
().
paragraph
()
author_comments
=
Faker
().
paragraph
()
remarks_for_editors
=
Faker
().
paragraph
()
submission_type
=
'
Letter
'
submission_type
=
factory
.
Iterator
(
SUBMISSION_TYPE
,
getter
=
lambda
c
:
c
[
0
])
is_current
=
True
@factory.post_generation
def
fill_arxiv_fields
(
self
,
create
,
extracted
,
**
kwargs
):
...
...
@@ -43,11 +42,13 @@ class SubmissionFactory(factory.django.DjangoModelFactory):
@factory.post_generation
def
contributors
(
self
,
create
,
extracted
,
**
kwargs
):
contributors
=
list
(
Contributor
.
objects
.
order_by
(
'
?
'
)
.
exclude
(
pk
=
self
.
submitted_by
.
pk
).
all
()[:
3
])
contributors
=
list
(
Contributor
.
objects
.
order_by
(
'
?
'
)[:
4
])
# Auto-add the submitter as an author
self
.
submitted_by
=
contributors
.
pop
()
if
not
create
:
return
# Auto-add the submitter as an author
self
.
authors
.
add
(
self
.
submitted_by
)
# Add three random authors
...
...
@@ -60,11 +61,13 @@ class SubmissionFactory(factory.django.DjangoModelFactory):
timezone
.
now
()
if
kwargs
.
get
(
'
submission
'
,
False
):
self
.
submission_date
=
kwargs
[
'
submission
'
]
else
:
self
.
submission_date
=
Faker
().
date_time_between
(
start_date
=
"
-3y
"
,
end_date
=
"
now
"
,
tzinfo
=
pytz
.
UTC
)
self
.
cycle
.
update_deadline
()
return
self
.
submission_date
=
Faker
().
date_time_between
(
start_date
=
"
-3y
"
,
end_date
=
"
now
"
,
tzinfo
=
pytz
.
UTC
).
date
()
self
.
latest_activity
=
Faker
().
date_time_between
(
start_date
=
self
.
submission_date
,
end_date
=
"
now
"
,
tzinfo
=
pytz
.
UTC
)
self
.
cycle
.
update_deadline
()
class
UnassignedSubmissionFactory
(
SubmissionFactory
):
...
...
@@ -79,24 +82,53 @@ class EICassignedSubmissionFactory(SubmissionFactory):
open_for_commenting
=
True
open_for_reporting
=
True
@factory.post_generation
def
report_dates
(
self
,
create
,
extracted
,
**
kwargs
):
self
.
reporting_deadline
=
self
.
latest_activity
+
datetime
.
timedelta
(
weeks
=
2
)
@factory.post_generation
def
eic
(
self
,
create
,
extracted
,
**
kwargs
):
'''
Assign an EIC to submission.
'''
author_ids
=
list
(
self
.
authors
.
values_list
(
'
id
'
,
flat
=
True
))
self
.
editor_in_charge
=
(
Contributor
.
objects
.
order_by
(
'
?
'
)
.
exclude
(
pk
=
self
.
submitted_by
.
pk
)
.
exclude
(
pk__in
=
author_ids
).
first
())
class
ResubmittedScreeningSubmissionFactory
(
SubmissionFactory
):
class
ResubmittedSubmissionFactory
(
SubmissionFactory
):
'''
This Submission is a newer version of a Submission which is
already known by the SciPost database.
'''
status
=
STATUS_RESUBMISSION_INCOMING
open_for_commenting
=
True
open_for_reporting
=
True
is_resubmission
=
True
@factory.post_generation
def
alter_arxiv_fields
(
self
,
create
,
extracted
,
**
kwargs
):
'''
Alter arxiv fields to save as version 2.
'''
self
.
arxiv_identifier_w_vn_nr
=
'
%sv2
'
%
self
.
arxiv_identifier_wo_vn_nr
self
.
arxiv_vn_nr
=
2
@factory.post_generation
def
eic
(
self
,
create
,
extracted
,
**
kwargs
):
'''
Assign an EIC to submission.
'''
author_ids
=
list
(
self
.
authors
.
values_list
(
'
id
'
,
flat
=
True
))
self
.
editor_in_charge
=
(
Contributor
.
objects
.
order_by
(
'
?
'
)
.
exclude
(
pk
=
self
.
submitted_by
.
pk
)
.
exclude
(
pk__in
=
author_ids
).
first
())
@factory.post_generation
def
dates
(
self
,
create
,
extracted
,
**
kwargs
):
"""
Overwrite the parent `dates` method to skip the update_deadline call.
"""
timezone
.
now
()
if
kwargs
.
get
(
'
submission
'
,
False
):
self
.
submission_date
=
kwargs
[
'
submission
'
]
return
self
.
submission_date
=
Faker
().
date_time_between
(
start_date
=
"
-3y
"
,
end_date
=
"
now
"
,
tzinfo
=
pytz
.
UTC
).
date
()
self
.
latest_activity
=
Faker
().
date_time_between
(
start_date
=
self
.
submission_date
,
end_date
=
"
now
"
,
tzinfo
=
pytz
.
UTC
)
class
PublishedSubmissionFactory
(
SubmissionFactory
):
status
=
STATUS_PUBLISHED
open_for_commenting
=
False
open_for_reporting
=
False
is_current
=
True
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