Skip to content

Commit

Permalink
CMD-72: All CMS Forms Should Send Confirmation E-Mail (#817)
Browse files Browse the repository at this point in the history
* add email confirmation capability

* remove unnecessary files, add to settings.py.

* make comment adjustments

* fix: typo in email messages

* fix: typo in email messages

* Update apps/email_management/apps.py

Co-authored-by: Wesley B <62723358+wesleyboar@users.noreply.github.com>

* unindent paragraphs

* update indentation

---------

Co-authored-by: Wesley B <62723358+wesleyboar@users.noreply.github.com>
  • Loading branch information
R-Tomas-Gonzalez and wesleyboar authored Mar 19, 2024
1 parent cea6b4e commit 0a193ef
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
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

0 comments on commit 0a193ef

Please sign in to comment.