|
|
@@ -29,39 +29,39 @@ class AbstractEmail(models.Model):
|
|
29
|
29
|
|
|
30
|
30
|
|
|
31
|
31
|
class AbstractCommunicationEventType(models.Model):
|
|
32
|
|
-
|
|
|
32
|
+
|
|
33
|
33
|
# Code used for looking up this event programmatically.
|
|
34
|
34
|
# eg. PASSWORD_RESET
|
|
35
|
35
|
code = models.SlugField(_('Code'), max_length=128)
|
|
36
|
|
-
|
|
|
36
|
+
|
|
37
|
37
|
# Name is the friendly description of an event for use in the admin
|
|
38
|
38
|
name = models.CharField(_('Name'), max_length=255)
|
|
39
|
|
-
|
|
|
39
|
+
|
|
40
|
40
|
# We allow communication types to be categorised
|
|
41
|
41
|
ORDER_RELATED = _('Order related')
|
|
42
|
42
|
USER_RELATED = _('User related')
|
|
43
|
43
|
category = models.CharField(_('Category'), max_length=255, default=ORDER_RELATED)
|
|
44
|
|
-
|
|
|
44
|
+
|
|
45
|
45
|
# Template content for emails
|
|
46
|
46
|
email_subject_template = models.CharField(_('Email Subject Template'), max_length=255, blank=True)
|
|
47
|
47
|
email_body_template = models.TextField(_('Email Body Template'), blank=True, null=True)
|
|
48
|
48
|
email_body_html_template = models.TextField(_('Email Body HTML Temlate'), blank=True, null=True,
|
|
49
|
49
|
help_text=_("HTML template"))
|
|
50
|
|
-
|
|
|
50
|
+
|
|
51
|
51
|
# Template content for SMS messages
|
|
52
|
52
|
sms_template = models.CharField(_('SMS Template'), max_length=170, blank=True, help_text=_("SMS template"))
|
|
53
|
|
-
|
|
|
53
|
+
|
|
54
|
54
|
date_created = models.DateTimeField(auto_now_add=True)
|
|
55
|
55
|
date_updated = models.DateTimeField(auto_now=True)
|
|
56
|
|
-
|
|
|
56
|
+
|
|
57
|
57
|
objects = CommunicationTypeManager()
|
|
58
|
|
-
|
|
|
58
|
+
|
|
59
|
59
|
# File templates
|
|
60
|
60
|
email_subject_template_file = 'customer/emails/commtype_%s_subject.txt'
|
|
61
|
61
|
email_body_template_file = 'customer/emails/commtype_%s_body.txt'
|
|
62
|
62
|
email_body_html_template_file = 'customer/emails/commtype_%s_body.html'
|
|
63
|
63
|
sms_template_file = 'customer/sms/commtype_%s_body.txt'
|
|
64
|
|
-
|
|
|
64
|
+
|
|
65
|
65
|
class Meta:
|
|
66
|
66
|
abstract = True
|
|
67
|
67
|
verbose_name = _("Communication Event Type")
|
|
|
@@ -71,16 +71,11 @@ class AbstractCommunicationEventType(models.Model):
|
|
71
|
71
|
"""
|
|
72
|
72
|
Return a dict of templates with the context merged in
|
|
73
|
73
|
|
|
74
|
|
- We look first at the field templates but fail over to
|
|
75
|
|
- a set of file templates.
|
|
|
74
|
+ We look first at the field templates but fail over to
|
|
|
75
|
+ a set of file templates that follow a conventional path.
|
|
76
|
76
|
"""
|
|
77
|
|
- if ctx is None:
|
|
78
|
|
- ctx = {}
|
|
79
|
|
-
|
|
80
|
|
- # Pass base URL for serving images within HTML emails
|
|
81
|
|
- ctx['static_base_url'] = getattr(settings, 'OSCAR_STATIC_BASE_URL', None)
|
|
82
|
|
-
|
|
83
|
77
|
code = self.code.lower()
|
|
|
78
|
+
|
|
84
|
79
|
# Build a dict of message name to Template instance
|
|
85
|
80
|
templates = {'subject': 'email_subject_template',
|
|
86
|
81
|
'body': 'email_body_template',
|
|
|
@@ -89,14 +84,21 @@ class AbstractCommunicationEventType(models.Model):
|
|
89
|
84
|
for name, attr_name in templates.items():
|
|
90
|
85
|
field = getattr(self, attr_name, None)
|
|
91
|
86
|
if field:
|
|
|
87
|
+ # Template content is in a model field
|
|
92
|
88
|
templates[name] = Template(field)
|
|
93
|
89
|
else:
|
|
|
90
|
+ # Model field is empty - look for a file template
|
|
94
|
91
|
template_name = getattr(self, "%s_file" % attr_name) % code
|
|
95
|
92
|
try:
|
|
96
|
93
|
templates[name] = get_template(template_name)
|
|
97
|
94
|
except TemplateDoesNotExist:
|
|
98
|
95
|
templates[name] = None
|
|
99
|
|
-
|
|
|
96
|
+
|
|
|
97
|
+ # Pass base URL for serving images within HTML emails
|
|
|
98
|
+ if ctx is None:
|
|
|
99
|
+ ctx = {}
|
|
|
100
|
+ ctx['static_base_url'] = getattr(settings, 'OSCAR_STATIC_BASE_URL', None)
|
|
|
101
|
+
|
|
100
|
102
|
messages = {}
|
|
101
|
103
|
for name, template in templates.items():
|
|
102
|
104
|
messages[name] = template.render(Context(ctx)) if template else ''
|
|
|
@@ -105,13 +107,12 @@ class AbstractCommunicationEventType(models.Model):
|
|
105
|
107
|
messages['subject'] = messages['subject'].replace("\n", "")
|
|
106
|
108
|
|
|
107
|
109
|
return messages
|
|
108
|
|
-
|
|
|
110
|
+
|
|
109
|
111
|
def __unicode__(self):
|
|
110
|
|
- return self.name
|
|
111
|
|
-
|
|
|
112
|
+ return self.name
|
|
|
113
|
+
|
|
112
|
114
|
def is_order_related(self):
|
|
113
|
115
|
return self.category == self.ORDER_RELATED
|
|
114
|
|
-
|
|
|
116
|
+
|
|
115
|
117
|
def is_user_related(self):
|
|
116
|
|
- return self.category == self.USER_RELATED
|
|
117
|
|
-
|
|
|
118
|
+ return self.category == self.USER_RELATED
|