Skip to content

Commit

Permalink
Merge pull request #90 from idabblewith/main
Browse files Browse the repository at this point in the history
test: emails errors
  • Loading branch information
idabblewith authored Jun 27, 2024
2 parents 2c68075 + 315bd12 commit 385ab91
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 37 deletions.
88 changes: 54 additions & 34 deletions documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@

# PDF GENERATION ===================================================


def determine_doc_kind_url_string(dockind:str):
if dockind == "conceptplan" or dockind == "concept":
return "concept"
elif dockind == "projectplan" or dockind == "project":
return "project"
elif dockind == "progressreport" or dockind == "progress":
return "progress"
elif dockind == "studentreport" or dockind == "student":
return "student"
else:
return "closure"
if dockind == "conceptplan" or dockind == "concept":
return "concept"
elif dockind == "projectplan" or dockind == "project":
return "project"
elif dockind == "progressreport" or dockind == "progress":
return "progress"
elif dockind == "studentreport" or dockind == "student":
return "student"
else:
return "closure"


class BeginUnapprovedReportDocGeneration(APIView):
Expand Down Expand Up @@ -3224,7 +3225,8 @@ def post(self, req):
"projectclosure": "Project Closure",
}
document_kind_as_title = document_kind_dict[document_kind]
email_subject = f"SPMS: Review {document_kind_as_title}"
project_tag = project.get_project_tag()
email_subject = f"SPMS: Review {document_kind_as_title} ({project_tag})"

processed = []
for recipient in recipients_list:
Expand Down Expand Up @@ -3384,12 +3386,13 @@ def post(self, req):
).strip() # nicely rendered html title

processed = []
project_tag = project.get_project_tag()
for recipient in recipients_list:
if recipient["pk"] not in processed:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
# if recipient["pk"] == 101073:
email_subject = f"SPMS: Project Closed"
email_subject = f"SPMS: {project_tag} Closed"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3422,8 +3425,9 @@ def post(self, req):
)
else: # test
print(f"TEST: Sending email to {recipient["name"]}")
project_tag = project.get_project_tag()
if recipient["pk"] == 101073:
email_subject = f"SPMS: Project Closed"
email_subject = f"SPMS: {project_tag} Closed"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3504,14 +3508,14 @@ def post(self, req):
"projectclosure": "Project Closure",
}
document_kind_as_title = document_kind_dict[document_kind]

project_tag = project.get_project_tag()
processed = []
for recipient in recipients_list:
if recipient["pk"] not in processed:
# if recipient["pk"] == 101073:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
email_subject = f"SPMS: New {document_kind_as_title} Ready"
email_subject = f"SPMS: New {document_kind_as_title} Ready ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3548,7 +3552,7 @@ def post(self, req):
print(f"TEST: Sending email to {recipient["name"]}")
# test
if recipient["pk"] == 101073:
email_subject = f"SPMS: New {document_kind_as_title} Ready"
email_subject = f"SPMS: New {document_kind_as_title} Ready ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3634,14 +3638,15 @@ def post(self, req):
"projectclosure": "Project Closure",
}
document_kind_as_title = document_kind_dict[document_kind]
project_tag = project.get_project_tag()

processed = []
for recipient in recipients_list:
if recipient["pk"] not in processed:
# if recipient["pk"] == 101073:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
email_subject = f"SPMS: {document_kind_as_title} Sent Back"
email_subject = f"SPMS: {document_kind_as_title} Sent Back ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3680,8 +3685,9 @@ def post(self, req):
else:
print(f"TEST: Sending email to {recipient["name"]}")
# test
project_tag = project.get_project_tag()
if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Sent Back"
email_subject = f"SPMS: {document_kind_as_title} Sent Back ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3767,14 +3773,15 @@ def post(self, req):
"projectclosure": "Project Closure",
}
document_kind_as_title = document_kind_dict[document_kind]
project_tag = project.get_project_tag()

processed = []
for recipient in recipients_list:
if recipient["pk"] not in processed:
if (
recipient["pk"] == 101073
): # Change to if settings.DEBUG == True mass replace
email_subject = f"SPMS: Concept Plan Review"
email_subject = f"SPMS: Review {document_kind_as_title} ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3857,14 +3864,15 @@ def post(self, req):
"projectclosure": "Project Closure",
}
document_kind_as_title = document_kind_dict[document_kind]
project_tag = project.get_project_tag()

processed = []
for recipient in recipients_list:
if recipient["pk"] not in processed:
# if recipient["pk"] == 101073:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
email_subject = f"SPMS: {document_kind_as_title} Approved"
email_subject = f"SPMS: {document_kind_as_title} Approved ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -3899,9 +3907,10 @@ def post(self, req):
)
else:
# test
project_tag = project.get_project_tag()
print(f"TEST: Sending email to {recipient["name"]}")
if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Approved"
email_subject = f"SPMS: {document_kind_as_title} Approved ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -4237,12 +4246,13 @@ def post(self, req):
stage = int(stage)

processed = []
project_tag = project.get_project_tag()
for recipient in recipients_list:
if recipient["pk"] not in processed:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
# if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Recalled"
email_subject = f"SPMS: {document_kind_as_title} Recalled ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -4282,9 +4292,10 @@ def post(self, req):
)
else:
# test
project_tag = project.get_project_tag()
print(f"TEST: Sending email to {recipient["name"]}")
if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Recalled"
email_subject = f"SPMS: {document_kind_as_title} Recalled ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -4811,14 +4822,15 @@ def post(self, req):
"email": user_email,
}
recipients_list.append(ba_data_obj)
project_tag = project.get_project_tag()

processed = []
for recipient in recipients_list:
if recipient["pk"] not in processed:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
# if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Approved"
email_subject = f"SPMS: {document_kind_as_title} Approved ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -4855,11 +4867,12 @@ def post(self, req):
status=HTTP_400_BAD_REQUEST,
)
else:
project_tag = project.get_project_tag()
# test
print(f"TEST: Sending email to {recipient["name"]}")
if recipient["pk"] == 101073:
email_subject = (
f"SPMS: {document_kind_as_title} Approved"
f"SPMS: {document_kind_as_title} Approved ({project_tag})"
)
to_email = [recipient["email"]]

Expand Down Expand Up @@ -5061,7 +5074,7 @@ def post(self, req):

if stage == 3:
if u_document.kind == "projectclosure":
# Reopen project, keeping closure
# Reopen project, keeping closure (recalling an approved stage 3 for a closure means that the project was closed - and is being reopened)
templ = "./email_templates/project_reopened_email.html"
project = document.project
project.status = "closure_requested"
Expand Down Expand Up @@ -5107,12 +5120,13 @@ def post(self, req):
print(recipients_list)

processed = []
project_tag = project.get_project_tag()
for recipient in recipients_list:
if recipient["pk"] not in processed:

if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
email_subject = f"SPMS: {document_kind_as_title} {'Reopened' if (u_document.kind == 'projectclosure' and stage == 3) else 'Recalled'}"
email_subject = f"SPMS: {document_kind_as_title} {'Reopened' if (u_document.kind == 'projectclosure' and stage == 3) else 'Recalled'} ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -5153,9 +5167,10 @@ def post(self, req):
status=HTTP_400_BAD_REQUEST,
)
else:
project_tag = project.get_project_tag()
print(f"TEST: Sending email to {recipient["name"]}")
if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} {'Reopened' if (u_document.kind == 'projectclosure' and stage == 3) else 'Recalled'}"
email_subject = f"SPMS: {document_kind_as_title} {'Reopened' if (u_document.kind == 'projectclosure' and stage == 3) else 'Recalled'} ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -5336,12 +5351,13 @@ def post(self, req):
recipients_list.append(data_obj)

processed = []
project_tag = project.get_project_tag()
for recipient in recipients_list:
if recipient["pk"] not in processed:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
# if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Sent Back"
email_subject = f"SPMS: {document_kind_as_title} Sent Back ({project_tag})"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -5386,7 +5402,7 @@ def post(self, req):
print(f"TEST: Sending email to {recipient["name"]}")
if recipient["pk"] == 101073:
email_subject = (
f"SPMS: {document_kind_as_title} Sent Back"
f"SPMS: {document_kind_as_title} Sent Back ({project_tag})"
)
to_email = [recipient["email"]]

Expand Down Expand Up @@ -5539,12 +5555,13 @@ def post(self, req):
recipients_list.append(p_leader_data_obj)

processed = []
project_tag = project.get_project_tag()
for recipient in recipients_list:
if recipient["pk"] not in processed:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
# if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Re-Opened"
email_subject = f"SPMS: {project_tag} Re-Opened"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -5586,7 +5603,7 @@ def post(self, req):
# test
print(f"TEST: Sending email to {recipient["name"]}")
if recipient["pk"] == 101073:
email_subject = f"SPMS: {document_kind_as_title} Re-Opened"
email_subject = f"SPMS: {project_tag} Re-Opened"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -9020,13 +9037,16 @@ def post(self, req, pk):
}
recipients_list.append(p_leader_data_obj)


project_tag = project.get_project_tag()

processed = []
for recipient in recipients_list:
if recipient["pk"] not in processed:
if settings.ON_TEST_NETWORK != True and settings.DEBUG != True:
print(f"PRODUCTION: Sending email to {recipient["name"]}")
# if recipient["pk"] == 101073:
email_subject = f"SPMS: {plain_project_name} Re-Opened"
email_subject = f"SPMS: {project_tag} Re-Opened"
to_email = [recipient["email"]]

template_props = {
Expand Down Expand Up @@ -9067,7 +9087,7 @@ def post(self, req, pk):
print(f"TEST: Sending email to {recipient["name"]}")
if recipient["pk"] == 101073:
# if recipient["pk"] == 101073:
email_subject = f"SPMS: {plain_project_name} Re-Opened"
email_subject = f"SPMS: {project_tag} Re-Opened"
to_email = [recipient["email"]]

template_props = {
Expand Down
Loading

0 comments on commit 385ab91

Please sign in to comment.