From 38934b08836ae568c125011acc9b7e91cf466a16 Mon Sep 17 00:00:00 2001 From: Levi Date: Thu, 16 Feb 2017 22:32:14 -0500 Subject: [PATCH] added request beta notification --- datacenterlight/models.py | 12 +- .../templates/datacenterlight/beta.html | 4 +- .../request_beta_access_notification.html | 131 ++++++++++++++++++ .../request_beta_access_notification.txt | 131 ++++++++++++++++++ datacenterlight/views.py | 24 +++- .../emails/password_reset_email.html | 2 +- 6 files changed, 297 insertions(+), 7 deletions(-) create mode 100644 datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.html create mode 100644 datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.txt diff --git a/datacenterlight/models.py b/datacenterlight/models.py index 545d8bfc..56ce1bc9 100644 --- a/datacenterlight/models.py +++ b/datacenterlight/models.py @@ -8,7 +8,7 @@ class BetaAccessVMType(models.Model): price = models.FloatField() def __str__(self): - return "ID: %s - ssd %s - ram %s - cpu %s - price %s " % \ + return "ID: %s - SSD %s - RAM %s - CPU %s - Price %s " % \ (self.id, str(self.ssd), self.ram, self.cpu, self.price) @@ -33,11 +33,17 @@ class BetaAccessVM(models.Model): def create(cls, data): VM_KEY_ID = 0 VM_AMOUNT = 1 + ZERO = 0 email = data.get('email') beta_access = BetaAccess.objects.create(email=email) vm_data = [(key, value) for key, value in data.items() if 'vm' in key] - + created_vms = [] for vm in vm_data: + if int(vm[VM_AMOUNT]) == ZERO: + continue vm_id = vm[VM_KEY_ID].split('-').pop() vm_type = BetaAccessVMType.objects.get(id=vm_id) - cls.objects.create(access=beta_access, amount=vm[VM_AMOUNT], type=vm_type) + created_vms.append(cls.objects.create(access=beta_access, + amount=vm[VM_AMOUNT], type=vm_type)) + + return created_vms diff --git a/datacenterlight/templates/datacenterlight/beta.html b/datacenterlight/templates/datacenterlight/beta.html index 628369e5..53e87d0e 100644 --- a/datacenterlight/templates/datacenterlight/beta.html +++ b/datacenterlight/templates/datacenterlight/beta.html @@ -14,7 +14,7 @@ - +
@@ -39,7 +39,7 @@ {% for vm in vms %}
- +
number of VMs ({{vm.ssd}} GB SSD, {{vm.ram}} GB RAM, {{vm.cpu}} CPU) - {{vm.price}}chf / day
diff --git a/datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.html b/datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.html new file mode 100644 index 00000000..7991eb69 --- /dev/null +++ b/datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.html @@ -0,0 +1,131 @@ +{% load static from staticfiles %} + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ An user requested a beta access + + +
+

User {{email}} requested beta access

+ {% for vm in vms %} + Type: {{vm.type}} - Amount: {{vm.amount}} + {% endfor %} +
 
+
+
+
+ + +
Your data center light team
+
+
+
+ + + diff --git a/datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.txt b/datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.txt new file mode 100644 index 00000000..92a03a99 --- /dev/null +++ b/datacenterlight/templates/datacenterlight/emails/request_beta_access_notification.txt @@ -0,0 +1,131 @@ +{% load static from staticfiles %} + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ An user requested a beta access + + +
+

User {{email}} requested beta access

+ {% for vm in vms %} + Type: {{vm.type}} + {% endfor %} +
 
+
+
+
+ + +
Your data center light team
+
+
+
+ + + diff --git a/datacenterlight/views.py b/datacenterlight/views.py index 44363852..3d012df6 100644 --- a/datacenterlight/views.py +++ b/datacenterlight/views.py @@ -35,8 +35,30 @@ class BetaProgramView(CreateView): def post(self, request, *args, **kwargs): data = request.POST - BetaAccessVM.create(data) + vms = BetaAccessVM.create(data) + + context = { + 'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host()), + 'email': data.get('email'), + 'vms': vms + } + + email_data = { + 'subject': 'DatacenterLight Beta Access Request', + 'to': 'info@ungleich.ch', + 'context': context, + 'template_name': 'request_beta_access_notification', + 'template_path': 'datacenterlight/emails/' + } + email = BaseEmail(**email_data) + email.send() + + messages.add_message(self.request, messages.SUCCESS, self.success_message) return HttpResponseRedirect(self.get_success_url()) + # return super(BetaProgramView, self).form_valid(form) + + + # def form_valid(self, form): diff --git a/digitalglarus/templates/digitalglarus/emails/password_reset_email.html b/digitalglarus/templates/digitalglarus/emails/password_reset_email.html index 42562b05..1688af72 100644 --- a/digitalglarus/templates/digitalglarus/emails/password_reset_email.html +++ b/digitalglarus/templates/digitalglarus/emails/password_reset_email.html @@ -111,7 +111,7 @@
My Account
- Reset password link + Reset password link