Simpler event handler dispatch
This commit is contained in:
parent
b60a8ff57d
commit
c731af3d7c
@ -4,33 +4,31 @@ from atst.models.request_status_event import RequestStatus
|
||||
|
||||
|
||||
class RequestStatusEventHandler(object):
|
||||
STATUS_TRANSITIONS = set([
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_ACCEPTANCE,
|
||||
RequestStatus.PENDING_FINANCIAL_VERIFICATION,
|
||||
),
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_ACCEPTANCE,
|
||||
RequestStatus.CHANGES_REQUESTED,
|
||||
),
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_APPROVAL,
|
||||
RequestStatus.CHANGES_REQUESTED_TO_FINVER,
|
||||
),
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_APPROVAL,
|
||||
RequestStatus.APPROVED,
|
||||
),
|
||||
])
|
||||
|
||||
def __init__(self, queue):
|
||||
self.queue = queue
|
||||
|
||||
def handle_status_change(self, request, old_status, new_status):
|
||||
handler = self._get_handler(old_status, new_status)
|
||||
if handler:
|
||||
handler(request)
|
||||
|
||||
def _get_handler(self, old_status, new_status):
|
||||
return {
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_ACCEPTANCE,
|
||||
RequestStatus.PENDING_FINANCIAL_VERIFICATION,
|
||||
): self._send_email,
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_ACCEPTANCE,
|
||||
RequestStatus.CHANGES_REQUESTED,
|
||||
): self._send_email,
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_APPROVAL,
|
||||
RequestStatus.CHANGES_REQUESTED_TO_FINVER,
|
||||
): self._send_email,
|
||||
(
|
||||
RequestStatus.PENDING_CCPO_APPROVAL,
|
||||
RequestStatus.APPROVED,
|
||||
): self._send_email,
|
||||
}.get((old_status, new_status))
|
||||
if (old_status, new_status) in self.STATUS_TRANSITIONS:
|
||||
self._send_email(request)
|
||||
|
||||
def _send_email(self, request):
|
||||
email_body = render_template(
|
||||
|
Loading…
x
Reference in New Issue
Block a user