forked from GamesDoneQuick/donation-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailutil.py
More file actions
27 lines (23 loc) · 972 Bytes
/
mailutil.py
File metadata and controls
27 lines (23 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import post_office
def get_email_template(name, default=None):
"""Get an email template, or fall back to use the default template object (if provided)"""
try:
return post_office.models.EmailTemplate.objects.get(name=name)
except post_office.models.EmailTemplate.DoesNotExist:
return default
def get_or_create_email_template(name, default):
'Get an email template, or fall back to creating one, using the provided name onto the default template' ''
# the extra bookkeeping here is to ensure that `default` is not modified as a side-effect
oldPk = default.pk
oldId = default.id
try:
return post_office.models.EmailTemplate.objects.get(name=name)
except post_office.models.EmailTemplate.DoesNotExist:
default.pk = None
default.id = None
default.name = name
default.save()
return get_email_template(name)
finally:
default.pk = oldPk
default.id = oldId