mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 17:47:02 +02:00
updated code for readability; handled ineligible status; tested for restricted user
This commit is contained in:
parent
31d04c0269
commit
af5ca2afdf
2 changed files with 23 additions and 5 deletions
|
@ -264,21 +264,25 @@ class DomainApplicationAdminForm(forms.ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
instance = kwargs.get("instance")
|
application = kwargs.get("instance")
|
||||||
if instance and instance.pk:
|
if application and application.pk:
|
||||||
current_state = instance.status
|
current_state = application.status
|
||||||
|
|
||||||
# first option in status transitions is current state
|
# first option in status transitions is current state
|
||||||
available_transitions = [(current_state, current_state)]
|
available_transitions = [(current_state, current_state)]
|
||||||
|
|
||||||
transitions = get_available_FIELD_transitions(
|
transitions = get_available_FIELD_transitions(
|
||||||
instance, models.DomainApplication._meta.get_field("status")
|
application, models.DomainApplication._meta.get_field("status")
|
||||||
)
|
)
|
||||||
|
|
||||||
for transition in transitions:
|
for transition in transitions:
|
||||||
available_transitions.append((transition.target, transition.target))
|
available_transitions.append((transition.target, transition.target))
|
||||||
|
|
||||||
self.fields["status"].widget.choices = available_transitions
|
# only set the available transitions if the user is not restricted
|
||||||
|
# from editing the domain application; otherwise, the form will be
|
||||||
|
# readonly and the status field will not have a widget
|
||||||
|
if not application.creator.is_restricted():
|
||||||
|
self.fields["status"].widget.choices = available_transitions
|
||||||
|
|
||||||
|
|
||||||
class DomainApplicationAdmin(ListHeaderAdmin):
|
class DomainApplicationAdmin(ListHeaderAdmin):
|
||||||
|
|
|
@ -120,6 +120,20 @@ class TestDomainApplicationAdminForm(TestCase):
|
||||||
DomainApplication._meta.get_field("status").choices,
|
DomainApplication._meta.get_field("status").choices,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_form_choices_when_ineligible(self):
|
||||||
|
# Create a form instance with a domain application with ineligible status
|
||||||
|
ineligible_application = DomainApplication(status="ineligible")
|
||||||
|
|
||||||
|
# Attempt to create a form with the ineligible application
|
||||||
|
# The form should not raise an error, but choices should be the
|
||||||
|
# full list of possible choices
|
||||||
|
form = DomainApplicationAdminForm(instance=ineligible_application)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
form.fields["status"].widget.choices,
|
||||||
|
DomainApplication._meta.get_field("status").choices,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestDomainApplicationAdmin(TestCase):
|
class TestDomainApplicationAdmin(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue