Skip to content

Commit 874f521

Browse files
committed
adding basic celery setting
1 parent 310ac81 commit 874f521

3 files changed

Lines changed: 82 additions & 0 deletions

File tree

hackathon/tasks.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import logging
2+
import os
3+
4+
from celery import shared_task
5+
from django.conf import settings
6+
from django.core.mail import send_mail
7+
from smtplib import SMTPException
8+
9+
from accounts.models import EmailTemplate, SlackSiteSettings
10+
11+
logger = logging.getLogger(__name__)
12+
13+
14+
@shared_task
15+
def send_email_from_template(user, hackathon, template_name):
16+
try:
17+
template = EmailTemplate.objects.get(template_name=template_name)
18+
user_name = user.first_name or user.email
19+
slack_settings = SlackSiteSettings.objects.first()
20+
if slack_settings and slack_settings.enable_welcome_emails:
21+
send_mail(
22+
subject=template.format(hackathon=hackathon.display_name),
23+
message=template.plain_text_message.format(student=user_name, hackathon=hackathon.display_name),
24+
html_message=template.html_message.format(student=user_name, hackathon=hackathon.display_name),
25+
from_email=slack_settings.from_email,
26+
recipient_list=[user.email],
27+
fail_silently=False,
28+
)
29+
logger.info("Email {template_name} sucessfully sent to user {user.id}.")
30+
except template.DoesNotExist:
31+
logger.exception(
32+
(f"There is no template with the name {template_name}."
33+
"Please create it on the Django Admin Panel"))
34+
except SMTPException:
35+
logger.exception("There was an issue sending the email.")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<p>Hi {student},</p>
2+
3+
<p>Thank you so much for registering for the {hackathon}!</p>
4+
5+
<p>
6+
<strong>What does participation involve?</strong><br>
7+
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!
8+
</p>
9+
10+
<p>
11+
<strong>What am I committing to?</strong><br>
12+
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.
13+
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 a person short.
14+
</p>
15+
16+
<p>
17+
<strong>!IMPORTANT</strong><br>
18+
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.
19+
</p>
20+
21+
<p>
22+
<strong>Register for the Intro Webinar!</strong><br>
23+
Please check the #hackathon channel for details on how to register for the intro and project presentations webinar.
24+
</p>
25+
26+
<p>
27+
<strong>Need Help?</strong><br>
28+
Please ask any questions in the #hackathon channel, the HackTeam are ready and happy to help out. You can ask them a question by using the @hackteam tag on slack.
29+
</p>
30+
31+
<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.
32+
33+
<p>
34+
Happy Hacking!<br>
35+
The Code Institute Community Team
36+
</p>

main/celery.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import os
2+
3+
from celery import Celery
4+
5+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings')
6+
7+
app = Celery('main')
8+
9+
app.config_from_object('django.conf:settings', namespace='CELERY')
10+
11+
app.autodiscover_tasks()

0 commit comments

Comments
 (0)