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

introduce some duplication #75

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
56 changes: 56 additions & 0 deletions python-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,62 @@ def _send_receipt_email(user: User, transaction: DbTransaction, email: str = Non
return False


def _send_receipt_email2(user: User, transaction: DbTransaction, email: str = None) -> bool:
"""Send an e-mail with the a receipt for the transaction to the user.
Return true if email address found.
"""
if not email:
email = user.receipt_email
if email:
locale = user.locale
if locale is None:
locale = shared.config.default_locale
logger.debug("Send receipt in %s to %s", locale, user.receipt_email)
try:
t = Template(name='receipt_email', locale=locale, global_variables=shared.jinja_globals)
template_env = {'transaction': transaction}
subject = t.render(template_env, section='subject')
message = t.render(template_env, section='body')
content_type = t.content_type
except TemplateNotFound:
subject = "Receipt from BobCat"
message = f"Receipt for transaction: {transaction.id}"
content_type = 'text/plain'
services.email_sender.send(email_from=None, email_to=email, subject=subject, message=message,
content_type=content_type)
return True
else:
return False


def _send_receipt_email3(user: User, transaction: DbTransaction, email: str = None) -> bool:
"""Send an e-mail with the a receipt for the transaction to the user.
Return true if email address found.
"""
if not email:
email = user.receipt_email
if email:
locale = user.locale
if locale is None:
locale = shared.config.default_locale
logger.debug("Send receipt in %s to %s", locale, user.receipt_email)
try:
t = Template(name='receipt_email', locale=locale, global_variables=shared.jinja_globals)
template_env = {'transaction': transaction}
subject = t.render(template_env, section='subject')
message = t.render(template_env, section='body')
content_type = t.content_type
except TemplateNotFound:
subject = "Receipt from BobCat"
message = f"Receipt for transaction: {transaction.id}"
content_type = 'text/plain'
services.email_sender.send(email_from=None, email_to=email, subject=subject, message=message,
content_type=content_type)
return True
else:
return False


def _remove_id_from_optional_set(id: str, id_set: Optional[Set[str]]):
"""Remove id from set. Return True if removed or no set."""
if id_set is None:
Expand Down