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
3f7f105e
Commit
3f7f105e
authored
4 years ago
by
Shrikrishna Singh
Committed by
Fredrik Jonsson
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Change DeterminationBlock choices based on phase and pop while edit
parent
43f33ae6
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
hypha/apply/determinations/forms.py
+1
-4
1 addition, 4 deletions
hypha/apply/determinations/forms.py
hypha/apply/determinations/views.py
+42
-0
42 additions, 0 deletions
hypha/apply/determinations/views.py
with
43 additions
and
4 deletions
hypha/apply/determinations/forms.py
+
1
−
4
View file @
3f7f105e
...
...
@@ -58,16 +58,13 @@ class DeterminationModelForm(StreamBaseForm, forms.ModelForm, metaclass=MixedMet
for
field
in
self
.
_meta
.
widgets
:
self
.
fields
[
field
].
disabled
=
True
# TODO need to find this field on runtime
# self.fields['8ab49696-f8ee-4810-bb60-551c000127c9'].choices = self.outcome_choices_for_phase(submission, user)
# self.fields['outcome'].choices = self.outcome_choices_for_phase(submission, user)
self
.
fields
[
'
outcome
'
].
choices
=
self
.
outcome_choices_for_phase
(
submission
,
user
)
if
self
.
draft_button_name
in
self
.
data
:
for
field
in
self
.
fields
.
values
():
field
.
required
=
False
if
edit
:
# TODO also need to pop the stream field for outcome
self
.
fields
.
pop
(
'
outcome
'
)
self
.
draft_button_name
=
None
...
...
This diff is collapsed.
Click to expand it.
hypha/apply/determinations/views.py
+
42
−
0
View file @
3f7f105e
...
...
@@ -38,12 +38,16 @@ from .utils import (
has_final_determination
,
outcome_from_actions
,
transition_from_outcome
,
determination_actions
)
from
.options
import
(
NEEDS_MORE_INFO
,
TRANSITION_DETERMINATION
,
DETERMINATION_CHOICES
)
from
.blocks
import
DeterminationBlock
def
get_form_for_stages
(
submissions
):
forms
=
[
...
...
@@ -83,6 +87,25 @@ def get_fields_for_stage(submission):
return
forms
[
0
].
form
.
form_fields
def
outcome_choices_for_phase
(
submission
,
user
):
"""
Outcome choices correspond to Phase transitions.
We need to filter out non-matching choices.
i.e. a transition to In Review is not a determination, while Needs more info or Rejected are.
"""
available_choices
=
set
()
choices
=
dict
(
DETERMINATION_CHOICES
)
for
transition_name
in
determination_actions
(
user
,
submission
):
try
:
determination_type
=
TRANSITION_DETERMINATION
[
transition_name
]
except
KeyError
:
pass
else
:
available_choices
.
add
((
determination_type
,
choices
[
determination_type
]))
return
available_choices
@method_decorator
(
staff_required
,
name
=
'
dispatch
'
)
class
DeterminationCreateOrUpdateView
(
BaseStreamForm
,
CreateOrUpdateView
):
submission_form_class
=
DeterminationModelForm
...
...
@@ -139,6 +162,17 @@ class DeterminationCreateOrUpdateView(BaseStreamForm, CreateOrUpdateView):
kwargs
[
'
action
'
]
=
self
.
request
.
GET
.
get
(
'
action
'
)
return
kwargs
def
get_form_class
(
self
):
form_fields
=
self
.
get_form_fields
()
field_blocks
=
self
.
get_defined_fields
()
for
field_block
in
field_blocks
:
if
isinstance
(
field_block
.
block
,
DeterminationBlock
):
outcome_choices
=
outcome_choices_for_phase
(
self
.
submission
,
self
.
request
.
user
)
form_fields
[
field_block
.
id
].
choices
=
outcome_choices
return
type
(
'
WagtailStreamForm
'
,
(
self
.
submission_form_class
,),
form_fields
)
def
get_success_url
(
self
):
return
self
.
submission
.
get_absolute_url
()
...
...
@@ -490,6 +524,14 @@ class DeterminationEditView(BaseStreamForm, UpdateView):
kwargs
[
'
initial
'
]
=
self
.
object
.
data
return
kwargs
def
get_form_class
(
self
):
form_fields
=
self
.
get_form_fields
()
field_blocks
=
self
.
get_defined_fields
()
for
field_block
in
field_blocks
:
if
isinstance
(
field_block
.
block
,
DeterminationBlock
):
form_fields
.
pop
(
field_block
.
id
)
return
type
(
'
WagtailStreamForm
'
,
(
self
.
submission_form_class
,),
form_fields
)
def
form_valid
(
self
,
form
):
super
().
form_valid
(
form
)
determination
=
self
.
get_object
()
...
...
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