diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py
index 5f59a319..db2912bd 100644
--- a/dynamicweb/settings/base.py
+++ b/dynamicweb/settings/base.py
@@ -132,6 +132,7 @@ TEMPLATES = [
'DIRS': [os.path.join(PROJECT_DIR, 'cms_templates/'),
os.path.join(PROJECT_DIR, 'cms_templates/djangocms_blog/'),
os.path.join(PROJECT_DIR, 'membership'),
+ os.path.join(PROJECT_DIR, 'hosting/templates/'),
os.path.join(PROJECT_DIR, 'ungleich/templates/djangocms_blog/'),
os.path.join(PROJECT_DIR, 'ungleich/templates/cms/ungleichch'),
os.path.join(PROJECT_DIR, 'ungleich/templates/ungleich')
diff --git a/hosting/admin.py b/hosting/admin.py
index 70392113..d8cf3012 100644
--- a/hosting/admin.py
+++ b/hosting/admin.py
@@ -1,5 +1,6 @@
from django.contrib import admin
-from .models import VirtualMachineType
+from .models import VirtualMachineType, VirtualMachinePlan
admin.site.register(VirtualMachineType)
+admin.site.register(VirtualMachinePlan)
diff --git a/hosting/static/hosting/img/DE_flag.png b/hosting/static/hosting/img/DE_flag.png
index d4f4526e..33db924c 100644
Binary files a/hosting/static/hosting/img/DE_flag.png and b/hosting/static/hosting/img/DE_flag.png differ
diff --git a/hosting/templates/emails/new_booked_vm.html b/hosting/templates/emails/new_booked_vm.html
new file mode 100644
index 00000000..8583ba1f
--- /dev/null
+++ b/hosting/templates/emails/new_booked_vm.html
@@ -0,0 +1,12 @@
+
+<
+
+
+
+
+
+
+NEW VM BOOKED
+
+
+
\ No newline at end of file
diff --git a/hosting/templates/emails/new_booked_vm.txt b/hosting/templates/emails/new_booked_vm.txt
new file mode 100644
index 00000000..8583ba1f
--- /dev/null
+++ b/hosting/templates/emails/new_booked_vm.txt
@@ -0,0 +1,12 @@
+
+<
+
+
+
+
+
+
+NEW VM BOOKED
+
+
+
\ No newline at end of file
diff --git a/hosting/templates/hosting/includes/_pricing.html b/hosting/templates/hosting/includes/_pricing.html
index 1f4e308e..2f8033bc 100644
--- a/hosting/templates/hosting/includes/_pricing.html
+++ b/hosting/templates/hosting/includes/_pricing.html
@@ -29,7 +29,7 @@
-
-
{{vm.hosting_company_name}}
+ {{vm.location_code}}
diff --git a/hosting/views.py b/hosting/views.py
index ad892143..60733274 100644
--- a/hosting/views.py
+++ b/hosting/views.py
@@ -12,7 +12,7 @@ from django.contrib import messages
from membership.models import CustomUser, StripeCustomer
from utils.stripe_utils import StripeUtils
from utils.forms import BillingAddressForm
-from utils.models import BillingAddress
+from utils.mailer import BaseEmail
from .models import VirtualMachineType, VirtualMachinePlan, HostingOrder
from .forms import HostingUserSignupForm, HostingUserLoginForm
from .mixins import ProcessVMSelectionMixin
@@ -174,6 +174,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
context.update({
'stripe_key': settings.STRIPE_API_PUBLIC_KEY
})
+
return context
def post(self, request, *args, **kwargs):
@@ -199,7 +200,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
customer = StripeCustomer.get_or_create(email=self.request.user.email,
token=token)
if not customer:
- form.add_error("__all__","Invalid credit card")
+ form.add_error("__all__", "Invalid credit card")
return self.render_to_response(self.get_context_data(form=form))
# Create Virtual Machine Plan
@@ -233,6 +234,18 @@ class PaymentVMView(LoginRequiredMixin, FormView):
# If the Stripe payment was successed, set order status approved
order.set_approved()
+
+ # Send notification to ungleich as soon as VM has been booked
+ # TODO send email using celery
+ email_data = {
+ 'subject': 'New VM request',
+ 'to': 'info@ungleich.ch',
+ 'template_name': 'new_booked_vm',
+ 'template_path': 'emails/'
+ }
+ email = BaseEmail(**email_data)
+ email.send()
+
request.session.update({
'charge': charge,
'order': order.id,
diff --git a/utils/mailer.py b/utils/mailer.py
index a12ffba6..8081152d 100644
--- a/utils/mailer.py
+++ b/utils/mailer.py
@@ -1,9 +1,35 @@
import six
from django.core.mail import send_mail
+from django.core.mail import EmailMultiAlternatives
+from django.template.loader import render_to_string
+
from django.conf import settings
+class BaseEmail(object):
+
+ def __init__(self, *args, **kwargs):
+ self.to = kwargs.get('to')
+ self.template_name = kwargs.get('template_name')
+ self.template_path = kwargs.get('template_path')
+ self.subject = kwargs.get('subject')
+ self.context = kwargs.get('context', {})
+ self.template_full_path = '%s%s' % (self.template_path, self.template_name)
+
+ text_content = render_to_string('%s.txt' % self.template_full_path,
+ {'data': self.context})
+ html_content = render_to_string('%s.html' % self.template_full_path,
+ {'data': self.context})
+
+ self.email = EmailMultiAlternatives(self.subject, text_content)
+ self.email.attach_alternative(html_content, "text/html")
+ self.email.to = ['info@digitalglarus.ch']
+
+ def send(self):
+ self.email.send()
+
+
class BaseMailer(object):
def __init__(self):
self._slug = None
@@ -50,3 +76,4 @@ class DigitalGlarusRegistrationMailer(BaseMailer):
self.registration = self.message
self._message = self._message.format(slug=self._slug)
super().__init__()
+