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
14ae4eff
Commit
14ae4eff
authored
7 years ago
by
Jorran de Wit
Browse files
Options
Downloads
Patches
Plain Diff
Reduce lines of code draft_registration_inv
parent
fc08930e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scipost/forms.py
+34
-0
34 additions, 0 deletions
scipost/forms.py
scipost/models.py
+4
-5
4 additions, 5 deletions
scipost/models.py
scipost/views.py
+8
-31
8 additions, 31 deletions
scipost/views.py
with
46 additions
and
36 deletions
scipost/forms.py
+
34
−
0
View file @
14ae4eff
...
...
@@ -133,6 +133,40 @@ class DraftInvitationForm(forms.ModelForm):
'
cited_in_submission
'
,
'
cited_in_publication
'
]
def
__init__
(
self
,
*
args
,
**
kwargs
):
'''
This form has a required keyword argument `current_user` which is used for validation of
the form fields.
'''
self
.
current_user
=
kwargs
.
pop
(
'
current_user
'
)
super
().
__init__
(
*
args
,
**
kwargs
)
def
clean_email
(
self
):
email
=
self
.
cleaned_data
[
'
email
'
]
if
RegistrationInvitation
.
objects
.
filter
(
email
=
email
).
exists
():
self
.
add_error
(
'
email
'
,
'
This email address has already been used for an invitation
'
)
if
DraftInvitation
.
objects
.
filter
(
email
=
email
).
exists
():
self
.
add_error
(
'
email
'
,
(
'
This email address has already been
'
'
used for a draft invitation
'
))
if
User
.
objects
.
filter
(
email
=
email
).
exists
():
self
.
add_error
(
'
email
'
,
'
This email address is already associated to a Contributor
'
)
return
email
def
clean_invitation_type
(
self
):
invitation_type
=
self
.
cleaned_data
[
'
invitation_type
'
]
if
invitation_type
==
'
F
'
and
not
self
.
current_user
.
has_perm
(
'
scipost.can_invite_Fellows
'
):
self
.
add_error
(
'
invitation_type
'
,
(
'
You do not have the authorization
'
'
to send a Fellow-type invitation.
'
'
Consider Contributor, or cited (sub/pub).
'
))
if
invitation_type
==
'
R
'
:
self
.
add_error
(
'
invitation_type
'
,
(
'
Referee-type invitations must be made
'
'
by the Editor-in-charge at the relevant
'
'
Submission
\'
s Editorial Page.
'
))
return
invitation_type
class
RegistrationInvitationForm
(
forms
.
ModelForm
):
cited_in_submission
=
AutoCompleteSelectField
(
'
submissions_lookup
'
,
required
=
False
)
...
...
This diff is collapsed.
Click to expand it.
scipost/models.py
+
4
−
5
View file @
14ae4eff
...
...
@@ -205,8 +205,8 @@ class DraftInvitation(models.Model):
Draft of an invitation, filled in by an officer.
"""
title
=
models
.
CharField
(
max_length
=
4
,
choices
=
TITLE_CHOICES
)
first_name
=
models
.
CharField
(
max_length
=
30
,
default
=
''
)
last_name
=
models
.
CharField
(
max_length
=
30
,
default
=
''
)
first_name
=
models
.
CharField
(
max_length
=
30
)
last_name
=
models
.
CharField
(
max_length
=
30
)
email
=
models
.
EmailField
()
invitation_type
=
models
.
CharField
(
max_length
=
2
,
choices
=
INVITATION_TYPE
,
default
=
INVITATION_CONTRIBUTOR
)
...
...
@@ -216,10 +216,9 @@ class DraftInvitation(models.Model):
cited_in_publication
=
models
.
ForeignKey
(
'
journals.Publication
'
,
on_delete
=
models
.
CASCADE
,
blank
=
True
,
null
=
True
)
drafted_by
=
models
.
ForeignKey
(
Contributor
,
on_delete
=
models
.
CASCADE
,
drafted_by
=
models
.
ForeignKey
(
'
scipost.Contributor
'
,
on_delete
=
models
.
CASCADE
,
blank
=
True
,
null
=
True
)
date_drafted
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
date_drafted
=
models
.
DateTimeField
(
auto_now_add
=
True
)
processed
=
models
.
BooleanField
(
default
=
False
)
def
__str__
(
self
):
...
...
This diff is collapsed.
Click to expand it.
scipost/views.py
+
8
−
31
View file @
14ae4eff
...
...
@@ -392,36 +392,13 @@ def draft_registration_invitation(request):
This is similar to the registration_invitations method,
which is used to complete the invitation process.
"""
errormessage
=
''
if
request
.
method
==
'
POST
'
:
draft_inv_form
=
DraftInvitationForm
(
request
.
POST
)
Utils
.
load
({
'
contributor
'
:
request
.
user
.
contributor
,
'
form
'
:
draft_inv_form
})
if
draft_inv_form
.
is_valid
():
if
Utils
.
email_already_invited
():
errormessage
=
(
'
DUPLICATE ERROR:
'
'
This email address has already been used for an invitation
'
)
elif
Utils
.
email_already_drafted
():
errormessage
=
(
'
DUPLICATE ERROR:
'
'
This email address has already been used for a draft invitation
'
)
elif
Utils
.
email_already_taken
():
errormessage
=
(
'
DUPLICATE ERROR:
'
'
This email address is already associated to a Contributor
'
)
elif
(
draft_inv_form
.
cleaned_data
[
'
invitation_type
'
]
==
'
F
'
and
not
request
.
user
.
has_perm
(
'
scipost.can_invite_Fellows
'
)):
errormessage
=
(
'
You do not have the authorization to send a Fellow-type
'
'
invitation. Consider Contributor, or cited (sub/pub).
'
)
elif
(
draft_inv_form
.
cleaned_data
[
'
invitation_type
'
]
==
'
R
'
):
errormessage
=
(
'
Referee-type invitations must be made by the Editor-in-charge
'
'
at the relevant Submission
\'
s Editorial Page.
'
)
else
:
Utils
.
create_draft_invitation
()
messages
.
success
(
request
,
'
Draft invitation saved.
'
)
return
redirect
(
reverse
(
'
scipost:draft_registration_invitation
'
))
else
:
errormessage
=
'
The form was not filled validly.
'
else
:
draft_inv_form
=
DraftInvitationForm
()
draft_inv_form
=
DraftInvitationForm
(
request
.
POST
or
None
,
current_user
=
request
.
user
)
if
draft_inv_form
.
is_valid
():
invitation
=
draft_inv_form
.
save
(
commit
=
False
)
invitation
.
drafted_by
=
request
.
user
.
contributor
invitation
.
save
()
messages
.
success
(
request
,
'
Draft invitation saved.
'
)
return
redirect
(
reverse
(
'
scipost:draft_registration_invitation
'
))
sent_reg_inv
=
RegistrationInvitation
.
objects
.
filter
(
responded
=
False
,
declined
=
False
)
sent_reg_inv_fellows
=
sent_reg_inv
.
filter
(
invitation_type
=
'
F
'
).
order_by
(
'
last_name
'
)
...
...
@@ -445,7 +422,7 @@ def draft_registration_invitation(request):
existing_drafts
=
DraftInvitation
.
objects
.
filter
(
processed
=
False
).
order_by
(
'
last_name
'
)
context
=
{
'
draft_inv_form
'
:
draft_inv_form
,
'
errormessage
'
:
errormessage
,
'
draft_inv_form
'
:
draft_inv_form
,
'
sent_reg_inv_fellows
'
:
sent_reg_inv_fellows
,
'
sent_reg_inv_contrib
'
:
sent_reg_inv_contrib
,
'
sent_reg_inv_ref
'
:
sent_reg_inv_ref
,
...
...
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