Skip to content

Commit

Permalink
Merge pull request #1108 from linea-it/subscription_fixes_03
Browse files Browse the repository at this point in the history
Subscription fixes 03
  • Loading branch information
rcboufleur authored Nov 29, 2024
2 parents ab4a4f3 + f5f3afa commit 45193ab
Show file tree
Hide file tree
Showing 18 changed files with 523 additions and 1,042 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
165 changes: 42 additions & 123 deletions backend/newsletter/templates/activate_subscription.html
Original file line number Diff line number Diff line change
@@ -1,125 +1,44 @@
{% extends "email_base.tpl" %} {% block content %}
<div
style="
background: #f4f4f4;
background-color: #f4f4f4;
margin: 0px auto;
max-width: 600px;
"
>
<table
align="center"
border="0"
cellpadding="0"
cellspacing="0"
role="presentation"
style="background: #f4f4f4; background-color: #f4f4f4; width: 100%"
>
<tbody>
<tr>
<td style="width: 100px">
<div
style="
text-align: center;
color: #e5e5e5;
height: 10px;
width: 600px;
padding: 10px;
background-color: #f4f4f4;
"
></div>
</td>
</tr>
</tbody>
</table>
</div>
<tr>
<td style="padding: 20px;">
<p style="font-size: 14px; color: #5a5c5f; line-height: 1.5;">
Thank you for subscribing to the LIneA Occultation Prediction
Database. We are excited to have you on board. Before you start
receiving customized predictions, we need to activate your account.
</p>
<p style="font-size: 14px; color: #5a5c5f; line-height: 1.5;">
Please click the button below to proceed.
</p>
<div style="text-align: center; padding: 10px">
<a href="{{host}}/api/subscription/activate/?c={{activation_code}}" style="
display: inline-block;
background-color: #0076BC;
color: #ffffff;
text-decoration: none;
font-size: 14px;
padding: 10px 20px;
border-radius: 4px;
line-height: 1.5;
" target="_blank">
Activate Account
</a>
</div>

<div
style="
background: #f4f4f4;
background-color: #f4f4f4;
margin: 0px auto;
max-width: 600px;
"
>
<table
align="center"
border="0"
cellpadding="15"
cellspacing="0"
role="presentation"
style="background: #f4f4f4; background-color: #f4f4f4; width: 100%"
>
<tbody>
<tr>
<td style="width: 100px">
<div
style="
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 14px;
font-style: normal;
text-align: center;
color: rgb(79, 78, 78);
height: 55px;
width: 570px;
padding: 20px 10px;
background-color: #f4f4f4;
"
>
Thank you for subscribing to the LIneA Occultation Prediction
Database. We are excited to have you on board. Before you start
receiving customized predictions, we need to activate your account.
Please click the button below to proceed.
</div>
<div style="text-align: center; padding: 10px">
<a
href="{{host}}/api/subscription/activate/?c={{activation_code}}"
style="
display: inline-block;
font-family: Roboto, Helvetica, Arial, sans-serif;
font-weight: normal;
font-size: 18px;
border-radius: 6px;
background-color: #0076bc;
color: #f4f4f4;
text-decoration: none;
padding: 10px 20px;
cursor: pointer;
"
target="_blank"
>
Activate Account
</a>
</div>
<div
style="
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 14px;
text-align: center;
color: rgb(79, 78, 78);
padding: 10px;
background-color: #f4f4f4;
"
>
<br />Or copy and paste the following link into your browser to
activate your account:
</div>
<div
style="
font-family: Roboto, Helvetica, Arial, sans-serif;
font-size: 12px;
text-align: center;
color: rgb(79, 78, 78);
word-wrap: break-word;
padding: 10px;
background-color: #f4f4f4;
"
>
{{host}}/api/subscription/activate/?c={{activation_code}}
</div>
</td>
</tr>
</tbody>
</table>
</div>
{% include 'footer.html' %} {% endblock %}
<p style="font-size: 14px; color: #5a5c5f; text-align: center; margin: 10px 0; line-height: 1;">
Or copy and paste the following link into your browser to activate your account:
<div style="
font-size: 12px;
text-align: center;
padding: 10px;
color: #5a5c5f;
">
{{host}}/api/subscription/activate/?c={{activation_code}}
</div>
</p>
<p style="font-size: 14px; color: #5a5c5f; text-align: left; margin: 10px 0; line-height: 1.5;">
Best regards,<br>
The LIneA Team
</p>
</td>
</tr>
{% endblock %}
64 changes: 9 additions & 55 deletions backend/newsletter/templates/activation_confirm.html
Original file line number Diff line number Diff line change
@@ -1,56 +1,10 @@
{% extends "base.tpl" %} {% block content %}
<body>
<div id="login">
<table>
<tbody>
<tr class="row">
<div style="margin: auto">
<img
src="https://tno-dev.linea.org.br/img/tno_logo_projetos.png"
style="width: 140px; margin: auto"
alt="tno_logo_projetos"
/>
</div>
<div style="text-align: center; margin: auto">
<p
style="
font-family: Oxanium;
font-weight: 100;
font-size: 24px;
font-style: normal;
font-weight: normal;
text-align: center;
color: #e5e5e5;
height: 50px;
width: 470px;
padding: 10px;
background-color: #0076bc;
"
>
LIneA Occultation Prediction Database
</p>
<p
style="
font-family: Roboto, Helvetica, Arial, sans-serif;
font-weight: normal;
font-size: 16px;
"
>
Thanks! You have successfully activated your subscription.
</p>
<p
style="
font-family: Roboto, Helvetica, Arial, sans-serif;
font-weight: normal;
font-size: 16px;
"
>
Please, check your email inbox.
</p>
</div>
</tr>
</tbody>
</table>
</div>
</body>
{% endblock %}
<!-- Body -->
<tr>
<td style="padding: 20px;">
<p style="font-size: 14px; color: #5a5c5f; line-height: 1.5; text-align: center; ">
Thanks! You have successfully activated your subscription.<br><br>
Please, check your email inbox.
</td>
</tr>
{% endblock %}
Loading

0 comments on commit 45193ab

Please sign in to comment.