Skip to content

Commit

Permalink
Merge pull request #196 from brunoamaral/190-the-email-template-conta…
Browse files Browse the repository at this point in the history
…ins-hardcoded-information

190 the email template contains hardcoded information
  • Loading branch information
brunoamaral authored Jul 24, 2022
2 parents 3b0cca2 + 9cb37e4 commit 3c18610
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 42 deletions.
4 changes: 4 additions & 0 deletions django/admin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os

from pathlib import Path
SITE_ID = 1

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down Expand Up @@ -41,6 +42,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'sitesettings',
'django_cron',
'db_maintenance',
'indexers',
Expand All @@ -55,6 +58,7 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.gzip.GZipMiddleware',
'django.contrib.sites.middleware.CurrentSiteMiddleware',
]

ROOT_URLCONF = 'admin.urls'
Expand Down
Empty file added django/sitesettings/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions django/sitesettings/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.contrib import admin

# Register your models here.
from .models import CustomSetting

class CustomSettingAdmin(admin.ModelAdmin):
list_display = ['site','title',]


admin.site.register(CustomSetting,CustomSettingAdmin)
6 changes: 6 additions & 0 deletions django/sitesettings/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class SitesettingsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'sitesettings'
Empty file.
9 changes: 9 additions & 0 deletions django/sitesettings/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models
from django.contrib.sites.models import Site

# Create your models here.
class CustomSetting(models.Model):
setting_id = models.AutoField(primary_key=True)
site = models.ForeignKey(Site, on_delete=models.PROTECT)
title = models.CharField(max_length=280,blank=False, null=False, unique=True)
email_footer = models.TextField(blank=True,null=True)
3 changes: 3 additions & 0 deletions django/sitesettings/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions django/sitesettings/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
31 changes: 23 additions & 8 deletions django/subscriptions/mercury.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from django.conf import settings
from subscriptions.models import Subscribers,Lists
from django_cron import CronJobBase, Schedule
from django.template.loader import get_template
from gregory.models import Articles,Trials
from django.conf import settings
from django.db.models import Q
from django.template.loader import get_template
from django.utils.html import strip_tags
import requests
from gregory.models import Articles,Trials
from sitesettings.models import *
from subscriptions.models import Subscribers,Lists
import datetime
import requests
from django.contrib.sites.models import Site

## Get custom settings from DB
customsettings = CustomSetting.objects.get(site=1)
site = Site.objects.get(pk=1)

list_clinical_trials = []
for email in Subscribers.objects.filter(subscriptions__list_name='Clinical Trials').values():
Expand Down Expand Up @@ -47,7 +53,10 @@ def do(self):
summary = {
"articles": articles,
"trials":trials,
"admin": admin
"admin": admin,
"title": customsettings.title,
"email_footer": customsettings.email_footer,
"site": site,
}
admin=str(summary['admin'].email)
html = get_template('emails/admin_summary.html').render(summary)
Expand Down Expand Up @@ -77,7 +86,10 @@ def do(self):
trials = Trials.objects.filter(~Q(sent_to_subscribers=True))
summary = {
"articles": articles,
"trials":trials
"trials":trials,
"title": customsettings.title,
"email_footer": customsettings.email_footer,
"site": site,
}
html = get_template('emails/weekly_summary.html').render(summary)
text= strip_tags(html)
Expand All @@ -104,7 +116,10 @@ def do(self):
subscribers.append(email['email'])

summary = {
"trials":trials
"trials":trials,
"title": customsettings.title,
"email_footer": customsettings.email_footer,
"site": site,
}
html = get_template('emails/trial_notification.html').render(summary)
text= strip_tags(html)
Expand Down
19 changes: 5 additions & 14 deletions django/templates/emails/admin_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gregory MS update</title>
<title>{{ title }} update</title>
<style>
@media only screen and (max-width: 620px) {
table.body h1 {
Expand Down Expand Up @@ -130,7 +130,7 @@ <h2 style="color: #000000; font-family: sans-serif; font-weight: 400; line-heigh
<li>ML GNB: {{article.ml_prediction_gnb}} </li>
<li>ML LR: {{article.ml_prediction_lr }} </li>
</ul>
<p><a href="https://api.gregory-ms.com/articles/{{article.article_id}}/">EDIT</a></p>
<p><a href="https://api.{{site.domain}}/articles/{{article.article_id}}/">EDIT</a></p>



Expand All @@ -153,17 +153,8 @@ <h2 style="color: #000000; font-family: sans-serif; font-weight: 400; line-heigh
<hr>

{% endfor %}
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">For the full list, please visit <a href="https://gregory-ms.com/" style="color: #3498db; text-decoration: underline;">https://gregory-ms.com/</a></p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">For adding people to this email list or further information, please contact Bruno Amaral:</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;"><strong>Mobile</strong>: +351 912 875 856</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;"><strong>Email</strong>: [email protected]</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">If you wish to unsubscribe, follow the link below.</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">Best wishes fom your friendly research bot.<br><strong>Gregory</strong></p>
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">For the full list, please visit <a href="https://{{site.domain}}/" style="color: #3498db; text-decoration: underline;">https://{{site.domain}}/</a></p>
{{email_footer | safe}}

</td>
</tr>
Expand All @@ -181,7 +172,7 @@ <h2 style="color: #000000; font-family: sans-serif; font-weight: 400; line-heigh
<tr>
<td class="content-block" style="font-family: sans-serif; vertical-align: top; padding-bottom: 10px; padding-top: 10px; color: #999999; font-size: 12px; text-align: center;" valign="top" align="center">
<span class="apple-link" style="color: #999999; font-size: 12px; text-align: center;">Gregory MS</span>
<br> For more information visit <a href="https://gregory-ms.com/" style="text-decoration: underline; color: #999999; font-size: 12px; text-align: center;">https://gregory-ms.com/</a>.
<br> For more information visit <a href="https://{{site.domain}}/" style="text-decoration: underline; color: #999999; font-size: 12px; text-align: center;">https://{{site.domain}}/</a>.
</td>
</tr>
<tr>
Expand Down
12 changes: 2 additions & 10 deletions django/templates/emails/trial_notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gregory MS update</title>
<title>{{ title }} update</title>
<style>
@media only screen and (max-width: 620px) {
table.body h1 {
Expand Down Expand Up @@ -131,15 +131,7 @@ <h2 style="color: #000000; font-family: sans-serif; font-weight: 400; line-heigh
{% endfor %}
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">For the full list, please visit <a href="https://gregory-ms.com/" style="color: #3498db; text-decoration: underline;">https://gregory-ms.com/</a></p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">For adding people to this email list or further information, please contact Bruno Amaral:</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;"><strong>Mobile</strong>: +351 912 875 856</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;"><strong>Email</strong>: [email protected]</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">If you wish to unsubscribe, follow the link below.</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">Best wishes fomyour friendly research bot.<br><strong>Gregory</strong></p>
{{email_footer | safe}}

</td>
</tr>
Expand Down
12 changes: 2 additions & 10 deletions django/templates/emails/weekly_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gregory MS update</title>
<title>{{ title }} update</title>
<style>
@media only screen and (max-width: 620px) {
table.body h1 {
Expand Down Expand Up @@ -147,15 +147,7 @@ <h2 style="color: #000000; font-family: sans-serif; font-weight: 400; line-heigh
{% endfor %}
<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">For the full list, please visit <a href="https://gregory-ms.com/" style="color: #3498db; text-decoration: underline;">https://gregory-ms.com/</a></p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">For adding people to this email list or further information, please contact Bruno Amaral:</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;"><strong>Mobile</strong>: +351 912 875 856</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;"><strong>Email</strong>: [email protected]</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">If you wish to unsubscribe, follow the link below.</p>

<p style="font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; margin-bottom: 15px;">Best wishes fom your friendly research bot.<br><strong>Gregory</strong></p>
{{email_footer | safe}}

</td>
</tr>
Expand Down

0 comments on commit 3c18610

Please sign in to comment.