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

enhance: WI-154 show field labels not keys #483

Merged
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
Loading