-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#M20. Add automated emails to signup and hackathon registration (#277)
* adding basic celery setting * Adding celery and model to store Email Templates * Fixing grammer in template
- Loading branch information
1 parent
310ac81
commit ab4b7c0
Showing
14 changed files
with
190 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 3.1.13 on 2023-01-04 15:38 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0018_slacksitesettings'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='EmailTemplate', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('display_name', models.CharField(max_length=255)), | ||
('description', models.TextField(blank=True, null=True)), | ||
('template_name', models.CharField(max_length=255)), | ||
('subject', models.CharField(max_length=1048)), | ||
('plain_text_message', models.TextField()), | ||
('html_message', models.TextField(blank=True, null=True)), | ||
('is_active', models.BooleanField(default=True)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 3.1.13 on 2023-01-04 16:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('accounts', '0019_emailtemplate'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelOptions( | ||
name='emailtemplate', | ||
options={'verbose_name': 'Email Template', 'verbose_name_plural': 'Email Templates'}, | ||
), | ||
migrations.AlterField( | ||
model_name='emailtemplate', | ||
name='template_name', | ||
field=models.CharField(max_length=255, unique=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
import os | ||
|
||
from celery import shared_task | ||
from django.conf import settings | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.core.mail import send_mail | ||
from smtplib import SMTPException | ||
|
||
from accounts.models import EmailTemplate, SlackSiteSettings | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@shared_task | ||
def send_email_from_template(user_email, user_name, hackathon_display_name, template_name): | ||
try: | ||
template = EmailTemplate.objects.get(template_name=template_name, is_active=True) | ||
user_name = user_name or user_email | ||
slack_settings = SlackSiteSettings.objects.first() | ||
if slack_settings and slack_settings.enable_welcome_emails: | ||
send_mail( | ||
subject=template.subject.format(hackathon=hackathon_display_name), | ||
message=template.plain_text_message.format(student=user_name, hackathon=hackathon_display_name), | ||
html_message=template.html_message.format(student=user_name, hackathon=hackathon_display_name), | ||
from_email=settings.DEFAULT_FROM_EMAIL, | ||
recipient_list=[user_email], | ||
fail_silently=False, | ||
) | ||
logger.info("Email {template_name} sucessfully sent to user {user.id}.") | ||
except ObjectDoesNotExist: | ||
logger.exception( | ||
(f"There is no template with the name {template_name}." | ||
"Please create it on the Django Admin Panel")) | ||
except SMTPException: | ||
logger.exception("There was an issue sending the email.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<p>Hi {student},</p> | ||
|
||
<p>Thank you so much for registering for the {hackathon}!</p> | ||
|
||
<p> | ||
<strong>What does participation involve?</strong><br> | ||
You'll be assigned to a team, and work together building a project based on the assigned theme in a limited number of days. Don't worry if you have limited coding experience, all levels are welcome, and we encourage alumni to participate! | ||
</p> | ||
|
||
<p> | ||
<strong>What am I committing to?</strong><br> | ||
We recommend at bare minimum you dedicate a minimum of 8-10 hours over the duration of the Hackathon. You will be expected to actively contribute to your team, not just observe. | ||
Please check your calendar and confirm that you are available before registering, as dropping out really lets your team down, and the team will be one person fewer. | ||
</p> | ||
|
||
<p> | ||
<strong>IMPORTANT!</strong><br> | ||
Please ensure your Profile is up to date, especially the 'Latest Module' entry. This is vital for the team selection process. We try our best to balance the teams fairly, so it really helps you and your team to be accurate with your profile. | ||
</p> | ||
|
||
<p> | ||
<strong>Register for the Intro Webinar!</strong><br> | ||
Please check the <a href="https://code-institute-room.slack.com/archives/CDAFARB71" target="_blank">#hackathon</a> channel for details on how to register for the intro and project presentations webinar. | ||
</p> | ||
|
||
<p> | ||
<strong>Need Help?</strong><br> | ||
Please ask any questions in the <a href="https://code-institute-room.slack.com/archives/CDAFARB71" target="_blank">#hackathon</a> channel, the HackTeam are ready and happy to help out. You can ask them a question by using the @hackteam tag on slack. | ||
</p> | ||
|
||
<p>Thanks again for signing up, we are excited to see what you and your team will create! Remember, hackathons are about team-building, learning and most importantly having fun. | ||
|
||
<p> | ||
Happy Hacking!<br> | ||
The Code Institute Community Team | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .celery import app as celery_app | ||
|
||
__all__ = ['celery_app'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import os | ||
|
||
from celery import Celery | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings') | ||
|
||
app = Celery('main') | ||
|
||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
|
||
app.autodiscover_tasks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.