Skip to content

Commit

Permalink
refactor: Backend related email templates refactor and minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rcboufleur committed Nov 29, 2024
1 parent ff7e899 commit f5f3afa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 288 deletions.
6 changes: 5 additions & 1 deletion backend/coreAdmin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR, os.path.join(BASE_DIR, "templates")],
"DIRS": [
BASE_DIR,
os.path.join(BASE_DIR, "templates"),
os.path.join(BASE_DIR, "newsletter/templates"),
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand Down
8 changes: 5 additions & 3 deletions backend/newsletter/events_send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ def exec_send_mail(self):
try:
path = "newsletter"
path_link = Path(settings.DATA_TMP_URL).joinpath(path)
link = str(path_link / attachment.filename)
link = settings.SITE_URL + str(
path_link / attachment.filename
)

self.log.info("Attachment found: %s", attachment.filename)
data = self.get_context_data(attachment.filename)[0:15]
data = self.get_context_data(attachment.filename)[0:10]

# Validate data structure
required_keys = [
Expand Down Expand Up @@ -119,7 +121,7 @@ def exec_send_mail(self):
)
date_end = f"{end_str[:4]}-{end_str[4:6]}-{end_str[6:8]}"
date_time = [
dt[:-1] if dt.endswith("Z") else dt
dt.replace("T", " ").rstrip("Z")
for dt in data["date_time"]
]

Expand Down
21 changes: 14 additions & 7 deletions backend/newsletter/newsletter_send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def send_events_mail(self, subscription: Subscription, email, context):
de acordo com as preferencias do usuario.
"""
# print(context[5], context[6])
data = {
"date": context[3],
"name": context[4],
"velocity": context[5],
"closest_approach": context[6],
"closest_approach_uncertainty_km": context[7],
"gaia_magnitude": context[8],
"id": context[10],
}
transformed_data = [
dict(zip(data.keys(), values)) for values in zip(*data.values())
]

html_content = render_to_string(
"results.html",
{
Expand All @@ -79,14 +92,8 @@ def send_events_mail(self, subscription: Subscription, email, context):
"filter_name": context[0],
"date_start": context[1],
"date_end": context[2],
"date": context[3],
"name": context[4],
"velocity": context[5],
"closest_approach": context[6],
"closest_approach_uncertainty_km": context[7],
"gaia_magnitude": context[8],
"link": context[9],
"id": context[10],
"data": transformed_data,
},
)

Expand Down
3 changes: 1 addition & 2 deletions backend/newsletter/process_event_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ def query_occultation(self, date_start, date_end, filter_set):
for prediction in occultation_queryset:
result = OccultationSerializer(prediction).data
result["url"] = (
"http:"
+ settings.SITE_URL.rstrip("/")
settings.SITE_URL.rstrip("/")
+ "/prediction-event-detail/"
+ prediction.hash_id
)
Expand Down
275 changes: 0 additions & 275 deletions backend/templates/validation_token_email_template.html

This file was deleted.

0 comments on commit f5f3afa

Please sign in to comment.