Add editable templates for bulk email
Adds the edX Marketing-approved template as html default.
This commit is contained in:
committed by
Sarina Canelake
parent
d341d6d26d
commit
8f93051d30
42
lms/djangoapps/bulk_email/forms.py
Normal file
42
lms/djangoapps/bulk_email/forms.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import logging
|
||||
|
||||
from django import forms
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from bulk_email.models import CourseEmailTemplate, COURSE_EMAIL_MESSAGE_BODY_TAG
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CourseEmailTemplateForm(forms.ModelForm):
|
||||
"""Form providing validation of CourseEmail templates."""
|
||||
|
||||
class Meta:
|
||||
model = CourseEmailTemplate
|
||||
|
||||
def _validate_template(self, template):
|
||||
"""Check the template for required tags."""
|
||||
index = template.find(COURSE_EMAIL_MESSAGE_BODY_TAG)
|
||||
if index < 0:
|
||||
msg = 'Missing tag: "{}"'.format(COURSE_EMAIL_MESSAGE_BODY_TAG)
|
||||
log.warning(msg)
|
||||
raise ValidationError(msg)
|
||||
if template.find(COURSE_EMAIL_MESSAGE_BODY_TAG, index + 1) >= 0:
|
||||
msg = 'Multiple instances of tag: "{}"'.format(COURSE_EMAIL_MESSAGE_BODY_TAG)
|
||||
log.warning(msg)
|
||||
raise ValidationError(msg)
|
||||
# TODO: add more validation here, including the set of known tags
|
||||
# for which values will be supplied. (Email will fail if the template
|
||||
# uses tags for which values are not supplied.)
|
||||
|
||||
def clean_html_template(self):
|
||||
"""Validate the HTML template."""
|
||||
template = self.cleaned_data["html_template"]
|
||||
self._validate_template(template)
|
||||
return template
|
||||
|
||||
def clean_plain_template(self):
|
||||
"""Validate the plaintext template."""
|
||||
template = self.cleaned_data["plain_template"]
|
||||
self._validate_template(template)
|
||||
return template
|
||||
Reference in New Issue
Block a user