From c2e24f4fb9954ab73e24e9acb24f6235e0b237f0 Mon Sep 17 00:00:00 2001 From: rachidatecs Date: Fri, 23 Jun 2023 15:28:51 -0400 Subject: [PATCH] tweak documentation and change ifs to elifs --- src/registrar/admin.py | 24 +++++-------------- src/registrar/models/domain_application.py | 28 +++++++++++++++------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/registrar/admin.py b/src/registrar/admin.py index 3e524ab80..93dc8ac38 100644 --- a/src/registrar/admin.py +++ b/src/registrar/admin.py @@ -94,31 +94,19 @@ class DomainApplicationAdmin(AuditedAdmin): if obj.status == models.DomainApplication.STARTED: # No conditions 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 # 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). + # for the side effects (like an email send). Same + # comment applies to original_obj method calls below. original_obj.submit(updated_domain_application=obj) - if 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). + elif obj.status == models.DomainApplication.INVESTIGATING: original_obj.in_review(updated_domain_application=obj) - if 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). + elif obj.status == models.DomainApplication.APPROVED: original_obj.approve(updated_domain_application=obj) - if 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. + elif obj.status == models.DomainApplication.WITHDRAWN: original_obj.withdraw() super().save_model(request, obj, form, change) diff --git a/src/registrar/models/domain_application.py b/src/registrar/models/domain_application.py index 6cb1482e7..71745b17c 100644 --- a/src/registrar/models/domain_application.py +++ b/src/registrar/models/domain_application.py @@ -499,7 +499,14 @@ class DomainApplication(TimeStampedModel): @transition(field="status", source=[STARTED, WITHDRAWN], target=SUBMITTED) 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 # can raise more informative exceptions @@ -515,8 +522,6 @@ class DomainApplication(TimeStampedModel): if not DraftDomain.string_could_be_domain(self.requested_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: # A DomainApplication is being passed to this method (ie from admin) updated_domain_application._send_status_update_email( @@ -525,7 +530,8 @@ class DomainApplication(TimeStampedModel): "emails/submission_confirmation_subject.txt", ) 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( "submission confirmation", "emails/submission_confirmation.txt", @@ -536,13 +542,13 @@ class DomainApplication(TimeStampedModel): def in_review(self, updated_domain_application): """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 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.""" - # 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( "application in review", "emails/status_change_in_review.txt", @@ -555,7 +561,13 @@ class DomainApplication(TimeStampedModel): This has substantial side-effects because it creates another database 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 @@ -575,8 +587,6 @@ class DomainApplication(TimeStampedModel): 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: # A DomainApplication is being passed to this method (ie from admin) updated_domain_application._send_status_update_email(