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

Allow custom subject delimiter #19

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion django_pony_express/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class BaseEmailService:
"""

SUBJECT_PREFIX = None
SUBJECT_DELIMITER = " - "
GitRon marked this conversation as resolved.
Show resolved Hide resolved
FROM_EMAIL = None
REPLY_TO_ADDRESS = []

Expand Down Expand Up @@ -165,7 +166,7 @@ def get_subject(self) -> str:
emails. Can be overridden if required.
"""
if self.SUBJECT_PREFIX:
return f"{self.SUBJECT_PREFIX} - {self.subject}"
return f"{self.SUBJECT_PREFIX}{self.SUBJECT_DELIMITER}{self.subject}"
return self.subject

def get_from_email(self) -> str:
Expand Down
3 changes: 2 additions & 1 deletion docs/features/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## Default "FROM"

You can set a subject prefix, so that all your emails look more similar when setting the constant ``SUBJECT_PREFIX``.
You can set a subject prefix, so that all your emails look more similar when setting the constant ``SUBJECT_PREFIX``.\
Additionally, you can define a custom `SUBJECT_DELIMITER`, which will be added between your custom `SUBJECT_PREFIX` and your `subject`.

If you wish to define a custom "from" email, you can do so via the ``FROM_EMAIL`` constant. Take care:
If you do not set it, the ``DEFAULT_FROM_EMAIL`` variable from the django settings is used.
Expand Down
2 changes: 1 addition & 1 deletion docs/features/internal_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


* ``get_subject()``
This method combines the constant ``SUBJECT_PREFIX`` with the variable `subject`. Can be overwritten, if required.
This method combines the constants ``SUBJECT_PREFIX`` and ``SUBJECT_DELIMITER`` with the variable `subject`. Can be overwritten, if required.


* ``get_from_email()``
Expand Down
13 changes: 13 additions & 0 deletions tests/services/base/test_base_mail_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ def test_get_subject_with_prefix(self):
service.SUBJECT_PREFIX = prefix
service.subject = subject
self.assertIn(prefix, service.get_subject())
self.assertIn(service.SUBJECT_DELIMITER, service.get_subject())
self.assertIn(subject, service.get_subject())

def test_get_subject_with_prefix_and_custom_delimiter(self):
prefix = "Pony Express"
custom_delimiter = " | "
subject = "I am a subject!"
service = BaseEmailService()
service.SUBJECT_PREFIX = prefix
service.SUBJECT_DELIMITER = custom_delimiter
service.subject = subject
self.assertIn(prefix, service.get_subject())
self.assertIn(custom_delimiter, service.get_subject())
self.assertIn(subject, service.get_subject())

@override_settings(DEFAULT_FROM_EMAIL="[email protected]")
Expand Down