Skip to content

Commit

Permalink
enhance: WI-154 show field labels not keys (#483)
Browse files Browse the repository at this point in the history
* 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 e375b3a.

---------

Co-authored-by: Jake Rosenberg <[email protected]>
  • Loading branch information
wesleyboar and jarosenb authored Oct 17, 2024
1 parent 5446e52 commit 14c4106
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions apps/tup-cms/src/apps/portal/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -50,7 +50,9 @@ def send_confirmation_email(form_name, form_data):
tour_receipt = "<p>A copy of your tour request is provided below for your records:</p>\n"
for key in form_data:
if not key.startswith('recaptcha_'):
tour_receipt += f"<p>{key}: {form_data[key]}</p>\n"
label = reverse_slugify(key) if key != 'form_id' else 'Form ID'
value = form_data[key]
tour_receipt += f"<p>{label}: {value}</p>\n"

email_body = f"""
<p>Greetings,</p>
Expand Down
23 changes: 23 additions & 0 deletions apps/tup-cms/src/apps/portal/utils.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 14c4106

Please sign in to comment.