mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-18 18:39:21 +02:00
Add custom field transitions
Kudos to rachid
This commit is contained in:
parent
6542d03bc5
commit
3a9683cf49
1 changed files with 19 additions and 3 deletions
|
@ -803,9 +803,14 @@ class DomainApplicationAdminForm(forms.ModelForm):
|
||||||
# first option in status transitions is current state
|
# first option in status transitions is current state
|
||||||
available_transitions = [(current_state, application.get_status_display())]
|
available_transitions = [(current_state, application.get_status_display())]
|
||||||
|
|
||||||
transitions = get_available_FIELD_transitions(
|
if application.investigator is not None:
|
||||||
application, models.DomainApplication._meta.get_field("status")
|
transitions = get_available_FIELD_transitions(
|
||||||
)
|
application, models.DomainApplication._meta.get_field("status")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
transitions = self.get_custom_field_transitions(
|
||||||
|
application, models.DomainApplication._meta.get_field("status")
|
||||||
|
)
|
||||||
|
|
||||||
for transition in transitions:
|
for transition in transitions:
|
||||||
available_transitions.append((transition.target, transition.target.label))
|
available_transitions.append((transition.target, transition.target.label))
|
||||||
|
@ -816,6 +821,17 @@ class DomainApplicationAdminForm(forms.ModelForm):
|
||||||
if not application.creator.is_restricted():
|
if not application.creator.is_restricted():
|
||||||
self.fields["status"].widget.choices = available_transitions
|
self.fields["status"].widget.choices = available_transitions
|
||||||
|
|
||||||
|
def get_custom_field_transitions(self, instance, field):
|
||||||
|
"""Custom implementation of get_available_FIELD_transitions
|
||||||
|
in the FSM. Allows us to still display fields filtered out by a condition."""
|
||||||
|
curr_state = field.get_state(instance)
|
||||||
|
transitions = field.transitions[instance.__class__]
|
||||||
|
|
||||||
|
for name, transition in transitions.items():
|
||||||
|
meta = transition._django_fsm
|
||||||
|
if meta.has_transition(curr_state):
|
||||||
|
yield meta.get_transition(curr_state)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
# clean is called from clean_forms, which is called from is_valid
|
# clean is called from clean_forms, which is called from is_valid
|
||||||
# after clean_fields. it is used to determine form level errors.
|
# after clean_fields. it is used to determine form level errors.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue