Skip to content

Commit

Permalink
moves content from template system to the db
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoamaral committed Jul 24, 2022
1 parent 0f667bc commit e7ac136
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 43 deletions.
3 changes: 2 additions & 1 deletion django/sitesettings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
class CustomSetting(models.Model):
setting_id = models.AutoField(primary_key=True)
site = models.ForeignKey(Site, on_delete=models.PROTECT)
title = models.TextField(blank=False, null=False, unique=True)
title = models.CharField(max_length=280,blank=False, null=False, unique=True)
email_footer = models.TextField(blank=True,null=True)
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 e7ac136

Please sign in to comment.