Send order emails as plain text

This commit is contained in:
Nico Schottelius 2017-06-10 00:33:26 +02:00
parent ce33a4b3f2
commit 9f2f0f7db3

View file

@ -4,6 +4,7 @@ from .forms import BetaAccessForm
from .models import BetaAccess, BetaAccessVMType, BetaAccessVM
from django.contrib import messages
from django.core.urlresolvers import reverse_lazy, reverse
from django.core.mail import EmailMessage
from utils.mailer import BaseEmail
from django.shortcuts import render
from django.shortcuts import redirect
@ -59,7 +60,7 @@ class PricingView(TemplateView):
if not request.user.is_authenticated():
request.session['next'] = reverse('hosting:payment')
request.session['specs'] = {
request.session['specs'] = {
'cpu':cores,
'memory': memory,
'disk_size': storage,
@ -101,7 +102,7 @@ class OrderView(TemplateView):
manager = OpenNebulaManager()
template = manager.get_template(template_id)
template_data = VirtualMachineTemplateSerializer(template).data
name = request.POST.get('name')
email = request.POST.get('email')
name_field = forms.CharField()
@ -112,17 +113,13 @@ class OrderView(TemplateView):
messages.add_message(self.request, messages.ERROR, '%(value) is not a proper name.'.format(name))
return HttpResponseRedirect(reverse('datacenterlight:order'))
try:
try:
email = email_field.clean(email)
except ValidationError as err:
messages.add_message(self.request, messages.ERROR, '%(value) is not a proper email.'.format(email))
return HttpResponseRedirect(reverse('datacenterlight:order'))
# We have valid email and name of the customer, hence send an
# email to the admin
context = {
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()),
'name': name,
'email': email,
'cores': cores,
@ -132,13 +129,12 @@ class OrderView(TemplateView):
'template': template_data['name'],
}
email_data = {
'subject': 'New Order Received',
'subject': "Data Center Light Order from %s" % context['email'],
'to': 'info@ungleich.ch',
'context': context,
'template_name': 'new_order_notification',
'template_path': 'datacenterlight/emails/'
'body': "\n".join(["%s=%s" % (k, v) for (k, v) in context.items()]),
'reply_to': context['email'],
}
email = BaseEmail(**email_data)
email = EmailMessage(**email_data)
email.send()
return HttpResponseRedirect(reverse('datacenterlight:order_success'))