Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMD-72: All CMS Forms Should Send Confirmation E-Mail #817

Merged
merged 12 commits into from
Mar 19, 2024
Empty file.
55 changes: 55 additions & 0 deletions apps/email_management/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from django.apps import AppConfig
import logging
from djangocms_forms.signals import form_submission
from django.core.mail import send_mail

logger = logging.getLogger(f"portal.{__name__}")

def send_confirmation_email(form_name, form_data):

from django.contrib.sites.models import Site

# Get the current site
current_site = Site.objects.get_current()

# Get the site name
site_name = current_site.name

text_body = f"""
Greetings,

You have successfully submitted a form on the {site_name} website. Thank you for your submission.

Sincerely,
{site_name} Communications
"""
email_body = f"""
<p>Greetings,</p>
<p>
You have successfully submitted a form on the {site_name} website. Thank you for your submission.
</p>
<p>
Sincerely,<br>
{site_name} Communications
</p>
"""
send_mail(
f"TACC Form Submission Received: {form_name}",
text_body,
"no-reply@tacc.utexas.edu",
[form_data['email']],
html_message=email_body)


def callback(form, cleaned_data, **kwargs):
logger.debug(f"received submission from {form.name}")
logger.debug(type(cleaned_data))
if ('email' in cleaned_data):
send_confirmation_email(form.name, cleaned_data)

class EmailManagementConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.email_management'

def ready(self):
form_submission.connect(callback)
1 change: 1 addition & 0 deletions taccsite_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ def gettext(s): return s
# core TACC CMS
# HELP: If this were top of list, would TACC/Core-CMS/pull/169 fix break?
'taccsite_cms',
'apps.email_management',

# django CMS Bootstrap
# IDEA: Extend Bootstrap apps instead of overwrite
Expand Down