mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 09:37:03 +02:00
tweak documentation and change ifs to elifs
This commit is contained in:
parent
22e73c6fc2
commit
c2e24f4fb9
2 changed files with 25 additions and 27 deletions
|
@ -94,31 +94,19 @@ class DomainApplicationAdmin(AuditedAdmin):
|
||||||
if obj.status == models.DomainApplication.STARTED:
|
if obj.status == models.DomainApplication.STARTED:
|
||||||
# No conditions
|
# No conditions
|
||||||
pass
|
pass
|
||||||
if obj.status == models.DomainApplication.SUBMITTED:
|
elif obj.status == models.DomainApplication.SUBMITTED:
|
||||||
# This is an fsm in model which will throw an error if the
|
# This is an fsm in model which will throw an error if the
|
||||||
# transition condition is violated, so we call it on the
|
# transition condition is violated, so we call it on the
|
||||||
# original object which has the right status value, and pass
|
# original object which has the right status value, and pass
|
||||||
# the updated object which contains the up-to-date data
|
# the updated object which contains the up-to-date data
|
||||||
# for the side effects (like an email send).
|
# for the side effects (like an email send). Same
|
||||||
|
# comment applies to original_obj method calls below.
|
||||||
original_obj.submit(updated_domain_application=obj)
|
original_obj.submit(updated_domain_application=obj)
|
||||||
if obj.status == models.DomainApplication.INVESTIGATING:
|
elif obj.status == models.DomainApplication.INVESTIGATING:
|
||||||
# This is an fsm in model which will throw an error if the
|
|
||||||
# transition condition is violated, so we call it on the
|
|
||||||
# original object which has the right status value, and pass
|
|
||||||
# the updated object which contains the up-to-date data
|
|
||||||
# for the side effects (like an email send).
|
|
||||||
original_obj.in_review(updated_domain_application=obj)
|
original_obj.in_review(updated_domain_application=obj)
|
||||||
if obj.status == models.DomainApplication.APPROVED:
|
elif obj.status == models.DomainApplication.APPROVED:
|
||||||
# This is an fsm in model which will throw an error if the
|
|
||||||
# transition condition is violated, so we call it on the
|
|
||||||
# original object which has the right status value, and pass
|
|
||||||
# the updated object which contains the up-to-date data
|
|
||||||
# for the side effects (like an email send).
|
|
||||||
original_obj.approve(updated_domain_application=obj)
|
original_obj.approve(updated_domain_application=obj)
|
||||||
if obj.status == models.DomainApplication.WITHDRAWN:
|
elif obj.status == models.DomainApplication.WITHDRAWN:
|
||||||
# This is a transition annotated method in model which will throw an
|
|
||||||
# error if the condition is violated. To make this work, we need to
|
|
||||||
# call it on the original object which has the right status value.
|
|
||||||
original_obj.withdraw()
|
original_obj.withdraw()
|
||||||
|
|
||||||
super().save_model(request, obj, form, change)
|
super().save_model(request, obj, form, change)
|
||||||
|
|
|
@ -499,7 +499,14 @@ class DomainApplication(TimeStampedModel):
|
||||||
|
|
||||||
@transition(field="status", source=[STARTED, WITHDRAWN], target=SUBMITTED)
|
@transition(field="status", source=[STARTED, WITHDRAWN], target=SUBMITTED)
|
||||||
def submit(self, updated_domain_application=None):
|
def submit(self, updated_domain_application=None):
|
||||||
"""Submit an application that is started."""
|
"""Submit an application that is started.
|
||||||
|
|
||||||
|
As a side effect, an email notification is sent.
|
||||||
|
|
||||||
|
This method is called in admin.py on the original application
|
||||||
|
which has the correct status value, but is passed the changed
|
||||||
|
application which has the up-to-date data that we'll use
|
||||||
|
in the email."""
|
||||||
|
|
||||||
# check our conditions here inside the `submit` method so that we
|
# check our conditions here inside the `submit` method so that we
|
||||||
# can raise more informative exceptions
|
# can raise more informative exceptions
|
||||||
|
@ -515,8 +522,6 @@ class DomainApplication(TimeStampedModel):
|
||||||
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
|
if not DraftDomain.string_could_be_domain(self.requested_domain.name):
|
||||||
raise ValueError("Requested domain is not a valid domain name.")
|
raise ValueError("Requested domain is not a valid domain name.")
|
||||||
|
|
||||||
# When an application is submitted, we need to send a confirmation email
|
|
||||||
# This is a side-effect of the state transition
|
|
||||||
if updated_domain_application is not None:
|
if updated_domain_application is not None:
|
||||||
# A DomainApplication is being passed to this method (ie from admin)
|
# A DomainApplication is being passed to this method (ie from admin)
|
||||||
updated_domain_application._send_status_update_email(
|
updated_domain_application._send_status_update_email(
|
||||||
|
@ -525,7 +530,8 @@ class DomainApplication(TimeStampedModel):
|
||||||
"emails/submission_confirmation_subject.txt",
|
"emails/submission_confirmation_subject.txt",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# views/application.py
|
# Or this method is called with the right application
|
||||||
|
# for context, ie from views/application.py
|
||||||
self._send_status_update_email(
|
self._send_status_update_email(
|
||||||
"submission confirmation",
|
"submission confirmation",
|
||||||
"emails/submission_confirmation.txt",
|
"emails/submission_confirmation.txt",
|
||||||
|
@ -536,13 +542,13 @@ class DomainApplication(TimeStampedModel):
|
||||||
def in_review(self, updated_domain_application):
|
def in_review(self, updated_domain_application):
|
||||||
"""Investigate an application that has been submitted.
|
"""Investigate an application that has been submitted.
|
||||||
|
|
||||||
|
As a side effect, an email notification is sent.
|
||||||
|
|
||||||
This method is called in admin.py on the original application
|
This method is called in admin.py on the original application
|
||||||
which has the correct status value, but is passed the changed
|
which has the correct status value, but is passed the changed
|
||||||
application which has the up-to-date data that we'll use
|
application which has the up-to-date data that we'll use
|
||||||
in the email."""
|
in the email."""
|
||||||
|
|
||||||
# When an application is moved to in review, we need to send a
|
|
||||||
# confirmation email. This is a side-effect of the state transition
|
|
||||||
updated_domain_application._send_status_update_email(
|
updated_domain_application._send_status_update_email(
|
||||||
"application in review",
|
"application in review",
|
||||||
"emails/status_change_in_review.txt",
|
"emails/status_change_in_review.txt",
|
||||||
|
@ -555,7 +561,13 @@ class DomainApplication(TimeStampedModel):
|
||||||
|
|
||||||
This has substantial side-effects because it creates another database
|
This has substantial side-effects because it creates another database
|
||||||
object for the approved Domain and makes the user who created the
|
object for the approved Domain and makes the user who created the
|
||||||
application into an admin on that domain.
|
application into an admin on that domain. It also triggers an email
|
||||||
|
notification.
|
||||||
|
|
||||||
|
This method is called in admin.py on the original application
|
||||||
|
which has the correct status value, but is passed the changed
|
||||||
|
application which has the up-to-date data that we'll use
|
||||||
|
in the email.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# create the domain
|
# create the domain
|
||||||
|
@ -575,8 +587,6 @@ class DomainApplication(TimeStampedModel):
|
||||||
user=self.creator, domain=created_domain, role=UserDomainRole.Roles.ADMIN
|
user=self.creator, domain=created_domain, role=UserDomainRole.Roles.ADMIN
|
||||||
)
|
)
|
||||||
|
|
||||||
# When an application is moved to in review, we need to send a
|
|
||||||
# confirmation email. This is a side-effect of the state transition
|
|
||||||
if updated_domain_application is not None:
|
if updated_domain_application is not None:
|
||||||
# A DomainApplication is being passed to this method (ie from admin)
|
# A DomainApplication is being passed to this method (ie from admin)
|
||||||
updated_domain_application._send_status_update_email(
|
updated_domain_application._send_status_update_email(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue