-
Notifications
You must be signed in to change notification settings - Fork 41
/
previews.py
48 lines (34 loc) · 1.37 KB
/
previews.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import random
from django import forms
try:
from django.utils.lorem_ipsum import words, paragraphs
except ImportError:
from django.contrib.webdesign.lorem_ipsum import paragraphs, words
from mailviews.previews import Preview, site
from mailviews.tests.emails.views import (BasicEmailMessageView,
BasicHTMLEmailMessageView)
class BasicPreview(Preview):
message_view = BasicEmailMessageView
verbose_name = 'Basic Message'
description = 'A basic text email message.'
def get_message_view(self, request):
subject = words(random.randint(5, 20), common=False)
content = '\n'.join(paragraphs(random.randint(3, 6)))
return self.message_view(subject, content)
class BasicHTMLPreview(BasicPreview):
message_view = BasicHTMLEmailMessageView
verbose_name = 'Basic HTML Message'
description = 'A basic HTML email message.'
class CustomizationForm(forms.Form):
subject = forms.CharField()
content = forms.CharField(widget=forms.Textarea)
def get_message_view_kwargs(self):
return self.cleaned_data
class CustomizablePreview(Preview):
message_view = BasicEmailMessageView
verbose_name = 'Basic Message, with Form'
description = 'A basic text email message, but customizable.'
form_class = CustomizationForm
site.register(BasicPreview)
site.register(BasicHTMLPreview)
site.register(CustomizablePreview)