From 14c410608937a93ada085479b7e6da5fd2de35a3 Mon Sep 17 00:00:00 2001 From: Wesley B <62723358+wesleyboar@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:50:04 -0500 Subject: [PATCH] enhance: WI-154 show field labels not keys (#483) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhance: WI-154 do not show recaptcha data * enhance: WI-154 use field labels not keys * test: tour email add labels ⚠️ NOT WORKING * fix: WI-154 ignore `form_id` * fix: WI-154 title case properly * fix: WI-154 title case fix has typo * fix: WI-154 restore form id but title cased well * refactor: (minor change) to reduce diff * Revert "refactor: (minor change) to reduce diff" This reverts commit e375b3a360b064a23440d4a3e1846c8e261dd671. --------- Co-authored-by: Jake Rosenberg --- apps/tup-cms/src/apps/portal/apps.py | 6 ++++-- apps/tup-cms/src/apps/portal/utils.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 apps/tup-cms/src/apps/portal/utils.py diff --git a/apps/tup-cms/src/apps/portal/apps.py b/apps/tup-cms/src/apps/portal/apps.py index 0286653d1..09cf2ac44 100644 --- a/apps/tup-cms/src/apps/portal/apps.py +++ b/apps/tup-cms/src/apps/portal/apps.py @@ -5,7 +5,7 @@ from djangocms_forms.signals import form_submission from django.conf import settings from django.core.mail import send_mail - +from .utils import reverse_slugify logger = logging.getLogger(f"portal.{__name__}") service_url = settings.TUP_SERVICES_URL @@ -50,7 +50,9 @@ def send_confirmation_email(form_name, form_data): tour_receipt = "

A copy of your tour request is provided below for your records:

\n" for key in form_data: if not key.startswith('recaptcha_'): - tour_receipt += f"

{key}: {form_data[key]}

\n" + label = reverse_slugify(key) if key != 'form_id' else 'Form ID' + value = form_data[key] + tour_receipt += f"

{label}: {value}

\n" email_body = f"""

Greetings,

diff --git a/apps/tup-cms/src/apps/portal/utils.py b/apps/tup-cms/src/apps/portal/utils.py new file mode 100644 index 000000000..34d2abd47 --- /dev/null +++ b/apps/tup-cms/src/apps/portal/utils.py @@ -0,0 +1,23 @@ +"""Utilities for Portal +""" + +def reverse_slugify(slug): + """ + + :param str slug: A name that is lowercase and uses hyphens instead of spaces + :rtype: str + + ..note:: Usage: + ``` + slug = "and-hello-world-this-is-a-slug" + original_text = reverse_slugify(slug) + print(original_text) # Output: "And Hello World This is a Slug" + ``` + """ + + words_to_exclude = {'a', 'is', 'to', 'of', 'for', 'and', 'or', 'in'} + words = slug.split('-') + words_for_title = [ word if word.lower() in words_to_exclude else word.capitalize() for word in words ] + text = ' '.join(words_for_title) + + return text