-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
60 lines (55 loc) · 2 KB
/
views.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
49
50
51
52
53
54
55
56
57
58
59
60
from django.shortcuts import render_to_response
from django.template.context import RequestContext, Context
from django.core.mail import send_mail
from django.template.loader import render_to_string
from models import *
# Create your views here.
def index(request):
args = {}
if request.method == 'POST':
cf = MessageForm(request.POST)
if cf.is_valid():
message = cf.save()
args['message_valid'] = True
welcomeEmail(message)
notifyEmail(message)
'''
send_mail('Thanks for contacting the Code Coop!',
"We got your message! We'll get back to you as soon as we can.",
[message.email],
fail_silently=False
)
send_mail(message.name + ' just sent us a message!',
message.message,
['[email protected]'],
fail_silently=False
)
'''
else:
args['message_valid'] = False
args['messageform'] = MessageForm()
return render_to_response('contact/index.html', RequestContext(request,args))
def welcomeEmail(message):
d = Context({ 'message': message })
msg_plain = render_to_string('email/welcome.txt', d)
msg_html = render_to_string('email/welcome.html', d)
send_mail(
'Thanks for the message!',
msg_plain,
[message.email],
html_message=msg_html,
)
def notifyEmail(message):
d = Context({ 'message': message })
msg_plain = render_to_string('email/notification.txt', d)
msg_html = render_to_string('email/notification.html', d)
send_mail(
message.name + ' sent us a message!',
msg_plain,
["[email protected]"],
html_message=msg_html,
)