From 9f2f0f7db3e9ee87fea85b2dbdcae2fa831f0a1d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 10 Jun 2017 00:33:26 +0200 Subject: [PATCH 1/4] Send order emails as plain text --- datacenterlight/views.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index d7b6a3e5..dfe3ae8b 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -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')) From 3750ba518281271a356aa2eee17e976ff6d5cf0e Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sat, 10 Jun 2017 12:42:31 +0530 Subject: [PATCH 2/4] Changed the to and reply-to fields for EmailMessage to list, as it expects input of that type --- datacenterlight/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index dfe3ae8b..1c9fa7ec 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -130,9 +130,9 @@ class OrderView(TemplateView): } email_data = { 'subject': "Data Center Light Order from %s" % context['email'], - 'to': 'info@ungleich.ch', + 'to': ['info@ungleich.ch'], 'body': "\n".join(["%s=%s" % (k, v) for (k, v) in context.items()]), - 'reply_to': context['email'], + 'reply_to': [context['email']], } email = EmailMessage(**email_data) email.send() From 9b40af3975125c26fe33929ae36918393a6352d8 Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sat, 10 Jun 2017 15:41:25 +0530 Subject: [PATCH 3/4] Removed the unnecessary new_order_notification* email templates as we no longer use them. --- .../emails/new_order_notification.html | 137 ------------------ .../emails/new_order_notification.txt | 137 ------------------ 2 files changed, 274 deletions(-) delete mode 100644 datacenterlight/templates/datacenterlight/emails/new_order_notification.html delete mode 100644 datacenterlight/templates/datacenterlight/emails/new_order_notification.txt diff --git a/datacenterlight/templates/datacenterlight/emails/new_order_notification.html b/datacenterlight/templates/datacenterlight/emails/new_order_notification.html deleted file mode 100644 index 5f14c983..00000000 --- a/datacenterlight/templates/datacenterlight/emails/new_order_notification.html +++ /dev/null @@ -1,137 +0,0 @@ -{% load static from staticfiles %} - - - - - - -Oxygen Invoice - - - - - - - - - - - - - -
-
- - -
- -
- - - -
- logo - -
-
- -
-
-
-
- - - - - - - - - - -
- We have received a new order. -
-

-

User details

- Name: {{name}}
- Email: {{email}}
- -

VM details

- Cores: {{cores}}
- Memory: {{memory}}
- Storage: {{storage}}
- Price: {{price}}
- Template: {{template}}
- -

 
-
-
-
- - -
Your data center light team
-
-
-
- - - diff --git a/datacenterlight/templates/datacenterlight/emails/new_order_notification.txt b/datacenterlight/templates/datacenterlight/emails/new_order_notification.txt deleted file mode 100644 index 5f14c983..00000000 --- a/datacenterlight/templates/datacenterlight/emails/new_order_notification.txt +++ /dev/null @@ -1,137 +0,0 @@ -{% load static from staticfiles %} - - - - - - -Oxygen Invoice - - - - - - - - - - - - - -
-
- - -
- -
- - - -
- logo - -
-
- -
-
-
-
- - - - - - - - - - -
- We have received a new order. -
-

-

User details

- Name: {{name}}
- Email: {{email}}
- -

VM details

- Cores: {{cores}}
- Memory: {{memory}}
- Storage: {{storage}}
- Price: {{price}}
- Template: {{template}}
- -

 
-
-
-
- - -
Your data center light team
-
-
-
- - - From 943fc741bf943b631fcad66d2287849b0ec1821d Mon Sep 17 00:00:00 2001 From: "M.Ravi" Date: Sun, 11 Jun 2017 20:06:54 +0530 Subject: [PATCH 4/4] Modified the IndexView to send text email on receiving new order --- datacenterlight/views.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/datacenterlight/views.py b/datacenterlight/views.py index db89a069..f0ef1852 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -280,7 +280,6 @@ class IndexView(CreateView): return HttpResponseRedirect(reverse('datacenterlight:order')) context = { - 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()), 'name': name, 'email': email, 'cores': cores, @@ -290,14 +289,13 @@ class IndexView(CreateView): 'template': template_data['name'], } email_data = { - 'subject': 'New Order Received', - 'to': 'info@ungleich.ch', - 'context': context, - 'template_name': 'new_order_notification', - 'template_path': 'datacenterlight/emails/' + 'subject': "Data Center Light Order from %s" % context['email'], + 'to': ['info@ungleich.ch'], + 'body': "\n".join(["%s=%s" % (k, v) for (k, v) in context.items()]), + 'reply_to': [context['email']], } - email = BaseEmail(**email_data) - email.send() + email = EmailMessage(**email_data) + email.send() return HttpResponseRedirect(reverse('datacenterlight:order_success'))