Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
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
ots
hypha
Commits
b8042cc1
Commit
b8042cc1
authored
6 years ago
by
Erin Mullaney
Browse files
Options
Downloads
Patches
Plain Diff
#957 move reviewer/role form save into view form_valid
parent
f31ec3a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/apply/funds/forms.py
+0
-17
0 additions, 17 deletions
opentech/apply/funds/forms.py
opentech/apply/funds/views.py
+28
-2
28 additions, 2 deletions
opentech/apply/funds/views.py
with
28 additions
and
19 deletions
opentech/apply/funds/forms.py
+
0
−
17
View file @
b8042cc1
from
django
import
forms
from
django.db.models
import
Q
from
django_select2.forms
import
Select2Widget
...
...
@@ -74,22 +73,6 @@ class UpdateReviewersForm(forms.ModelForm):
if
existing_submission_reviewer
:
self
.
fields
[
field_name
].
initial
=
existing_submission_reviewer
[
0
].
reviewer
def
save
(
self
,
*
args
,
**
kwargs
):
instance
=
super
().
save
(
*
args
,
**
kwargs
)
# Loop through self.cleaned_data and save reviewers by role type to submission
for
key
,
value
in
self
.
cleaned_data
.
items
():
role_pk
=
key
[
key
.
rindex
(
"
_
"
)
+
1
:]
role
=
ReviewerRole
.
objects
.
get
(
pk
=
role_pk
)
# Create the reviewer/role association to submission if it doesn't exist
submission_reviewer
,
_
=
ApplicationSubmissionReviewer
.
objects
.
get_or_create
(
submission
=
instance
,
reviewer
=
value
,
reviewer_role
=
role
)
# Delete any reviewer/role associations that existed previously
ApplicationSubmissionReviewer
.
objects
.
filter
(
Q
(
submission
=
instance
),
~
Q
(
reviewer
=
value
),
Q
(
reviewer_role
=
role
)).
delete
()
return
instance
class
BatchUpdateReviewersForm
(
forms
.
Form
):
staff_reviewers
=
forms
.
ModelMultipleChoiceField
(
...
...
This diff is collapsed.
Click to expand it.
opentech/apply/funds/views.py
+
28
−
2
View file @
b8042cc1
...
...
@@ -38,7 +38,15 @@ from .forms import (
UpdateReviewersForm
,
UpdateSubmissionLeadForm
,
)
from
.models
import
ApplicationSubmission
,
ApplicationRevision
,
RoundsAndLabs
,
RoundBase
,
LabBase
from
.models
import
(
ApplicationSubmission
,
ApplicationSubmissionReviewer
,
ApplicationRevision
,
ReviewerRole
,
RoundsAndLabs
,
RoundBase
,
LabBase
)
from
.tables
import
(
AdminSubmissionsTable
,
RoundsTable
,
...
...
@@ -269,8 +277,25 @@ class UpdateReviewersView(DelegatedViewMixin, UpdateView):
context_name
=
'
reviewer_form
'
def
form_valid
(
self
,
form
):
old_reviewers
=
set
(
self
.
get_object
().
reviewers
.
all
())
if
len
(
form
.
cleaned_data
.
values
())
!=
len
(
set
(
form
.
cleaned_data
.
values
())):
# If any of the users match
messages
.
error
(
self
.
request
,
mark_safe
(
_
(
'
Users cannot be assigned to multiple roles.
'
)
+
form
.
errors
.
as_ul
()))
return
self
.
form_invalid
(
form
)
# Loop through cleaned_data and save reviewers by role type to submission
for
key
,
value
in
form
.
cleaned_data
.
items
():
role_pk
=
key
[
key
.
rindex
(
"
_
"
)
+
1
:]
role
=
ReviewerRole
.
objects
.
get
(
pk
=
role_pk
)
# Create the reviewer/role association to submission if it doesn't exist
submission_reviewer
,
c
=
ApplicationSubmissionReviewer
.
objects
.
get_or_create
(
submission
=
form
.
instance
,
reviewer
=
value
,
reviewer_role
=
role
)
# Delete any reviewer/role associations that existed previously
ApplicationSubmissionReviewer
.
objects
.
filter
(
Q
(
submission
=
form
.
instance
),
~
Q
(
reviewer
=
value
),
Q
(
reviewer_role
=
role
)).
delete
()
response
=
super
().
form_valid
(
form
)
"""
old_reviewers = set(self.get_object().reviewers.all())
new_reviewers = set(form.instance.reviewers.all())
added = new_reviewers - old_reviewers
...
...
@@ -284,6 +309,7 @@ class UpdateReviewersView(DelegatedViewMixin, UpdateView):
added=added,
removed=removed,
)
"""
return
response
...
...
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