From fd83ad4ffcd727d97b9f027bd599fb13cdd37bab Mon Sep 17 00:00:00 2001 From: Levi Date: Thu, 9 Jun 2016 23:50:49 -0500 Subject: [PATCH] As an user I want to be able to cancel my VM Plan subscription. As an user I want to be able to receive an email each time that my VM status changes. --- hosting/admin.py | 4 +- hosting/models.py | 4 + hosting/static/hosting/css/commons.css | 8 ++ .../hosting/js/virtual_machine_detail.js | 18 +++ hosting/templates/emails/vm_activated.html | 13 -- hosting/templates/emails/vm_activated.txt | 15 -- .../templates/emails/vm_status_changed.html | 136 ++++++++++++++++++ .../templates/emails/vm_status_changed.txt | 136 ++++++++++++++++++ hosting/templates/hosting/base_short.html | 3 + .../hosting/virtual_machine_detail.html | 48 ++++++- .../templates/hosting/virtual_machines.html | 2 +- hosting/urls.py | 6 +- hosting/views.py | 28 +++- 13 files changed, 380 insertions(+), 41 deletions(-) create mode 100644 hosting/static/hosting/js/virtual_machine_detail.js delete mode 100644 hosting/templates/emails/vm_activated.html delete mode 100644 hosting/templates/emails/vm_activated.txt create mode 100644 hosting/templates/emails/vm_status_changed.html create mode 100644 hosting/templates/emails/vm_status_changed.txt diff --git a/hosting/admin.py b/hosting/admin.py index 17cb5591..8c9d59da 100644 --- a/hosting/admin.py +++ b/hosting/admin.py @@ -73,7 +73,7 @@ class VirtualMachinePlanAdmin(admin.ModelAdmin): def save_model(self, request, obj, form, change): email = self.email(obj) - if 'status' in form.changed_data and obj.status == VirtualMachinePlan.ONLINE_STATUS: + if 'status' in form.changed_data: context = { 'vm': obj } @@ -81,7 +81,7 @@ class VirtualMachinePlanAdmin(admin.ModelAdmin): 'subject': 'Your VM has been activated', 'to': email, 'context': context, - 'template_name': 'vm_activated', + 'template_name': 'vm_status_changed', 'template_path': 'emails/' } email = BaseEmail(**email_data) diff --git a/hosting/models.py b/hosting/models.py index e9f59478..887f0777 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -162,6 +162,10 @@ class VirtualMachinePlan(models.Model): self.save(update_fields=['public_key']) return private_key + def cancel_plan(self): + self.status = self.CANCELED_STATUS + self.save(update_fields=['status']) + class HostingOrder(models.Model): diff --git a/hosting/static/hosting/css/commons.css b/hosting/static/hosting/css/commons.css index f386cfd6..94e84df5 100644 --- a/hosting/static/hosting/css/commons.css +++ b/hosting/static/hosting/css/commons.css @@ -18,3 +18,11 @@ display: inline-block; vertical-align: baseline; } + +.space-above { + margin-top: 4%; +} + +.space-above-big { + margin-top: 20%; +} diff --git a/hosting/static/hosting/js/virtual_machine_detail.js b/hosting/static/hosting/js/virtual_machine_detail.js new file mode 100644 index 00000000..303f95ca --- /dev/null +++ b/hosting/static/hosting/js/virtual_machine_detail.js @@ -0,0 +1,18 @@ + +$( document ).ready(function() { + + $('#confirm-cancel').on('click', '.btn-ok', function(e) { + $('#virtual_machine_cancel_form').trigger('submit'); + }); + + var hash = window.location.hash; + hash && $('ul.nav a[href="' + hash + '"]').tab('show'); + + $('.nav-tabs a').click(function (e) { + $(this).tab('show'); + var scrollmem = $('body').scrollTop() || $('html').scrollTop(); + window.location.hash = this.hash; + $('html,body').scrollTop(scrollmem); + }); + +}); \ No newline at end of file diff --git a/hosting/templates/emails/vm_activated.html b/hosting/templates/emails/vm_activated.html deleted file mode 100644 index 92eec368..00000000 --- a/hosting/templates/emails/vm_activated.html +++ /dev/null @@ -1,13 +0,0 @@ - -{% load staticfiles bootstrap3%} - - - - - - - - You virtual machine {{vm.name}} has been activated. You can manage your vm on this link - - - \ No newline at end of file diff --git a/hosting/templates/emails/vm_activated.txt b/hosting/templates/emails/vm_activated.txt deleted file mode 100644 index f7f85457..00000000 --- a/hosting/templates/emails/vm_activated.txt +++ /dev/null @@ -1,15 +0,0 @@ - -{% load staticfiles bootstrap3%} - - - - - - - - You virtual machine {{vm.name}} has been activated. You can manage your vm in this link - - - - - \ No newline at end of file diff --git a/hosting/templates/emails/vm_status_changed.html b/hosting/templates/emails/vm_status_changed.html new file mode 100644 index 00000000..96261f44 --- /dev/null +++ b/hosting/templates/emails/vm_status_changed.html @@ -0,0 +1,136 @@ + + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ Your virtual machine {{vm.name}} status has been updated to {{vm.get_status_display}} +
+ You can manage your vm clicking on the button below +
+ +
+
+
+
+ + +
+ ungleich
+
+
+
+ + + diff --git a/hosting/templates/emails/vm_status_changed.txt b/hosting/templates/emails/vm_status_changed.txt new file mode 100644 index 00000000..96261f44 --- /dev/null +++ b/hosting/templates/emails/vm_status_changed.txt @@ -0,0 +1,136 @@ + + + + + + + +Oxygen Invoice + + + + + + + + + + + + + +
+
+ + +
+ +
+ + + +
+ logo + +
+
+ +
+
+
+
+ + + + + + + + + + +
+ Your virtual machine {{vm.name}} status has been updated to {{vm.get_status_display}} +
+ You can manage your vm clicking on the button below +
+ +
+
+
+
+ + +
+ ungleich
+
+
+
+ + + diff --git a/hosting/templates/hosting/base_short.html b/hosting/templates/hosting/base_short.html index 64c93781..5c6110c5 100644 --- a/hosting/templates/hosting/base_short.html +++ b/hosting/templates/hosting/base_short.html @@ -161,6 +161,9 @@ + + + diff --git a/hosting/templates/hosting/virtual_machine_detail.html b/hosting/templates/hosting/virtual_machine_detail.html index 6b97d6be..63ca9bfe 100644 --- a/hosting/templates/hosting/virtual_machine_detail.html +++ b/hosting/templates/hosting/virtual_machine_detail.html @@ -143,15 +143,49 @@

Current status

- {% if virtual_machine.status == 'pending' %} - {{virtual_machine.get_status_display}} - {% elif virtual_machine.status == 'online' %} - {{virtual_machine.get_status_display}} - {% else %} - {{virtual_machine.get_status_display}} - {% endif %} +
+ {% if virtual_machine.status == 'pending' %} + {{virtual_machine.get_status_display}} + {% elif virtual_machine.status == 'online' %} + {{virtual_machine.get_status_display}} + {% elif virtual_machine.status == 'canceled'%} + {{virtual_machine.get_status_display}} + {% endif %} +
+ {% if not virtual_machine.status == 'canceled' %} +
+
+
+
+ {% csrf_token %} +
+ + + +
+
+ + + +
+ {% endif %} diff --git a/hosting/templates/hosting/virtual_machines.html b/hosting/templates/hosting/virtual_machines.html index 61a2a573..707997ef 100644 --- a/hosting/templates/hosting/virtual_machines.html +++ b/hosting/templates/hosting/virtual_machines.html @@ -30,7 +30,7 @@ {% elif vm.status == 'online' %} {{vm.get_status_display}} {% else %} - {{vm.get_status_display}} + {{vm.get_status_display}} {% endif %} diff --git a/hosting/urls.py b/hosting/urls.py index 1368ab73..83bab74b 100644 --- a/hosting/urls.py +++ b/hosting/urls.py @@ -3,7 +3,7 @@ from django.conf.urls import url from .views import DjangoHostingView, RailsHostingView, PaymentVMView,\ NodeJSHostingView, LoginView, SignupView, IndexView, \ OrdersHostingListView, OrdersHostingDetailView, VirtualMachinesPlanListView,\ - VirtualMachineDetailView, GenerateVMSSHKeysView, OrdersHostingDeleteView, NotificationsView, \ + VirtualMachineView, GenerateVMSSHKeysView, OrdersHostingDeleteView, NotificationsView, \ MarkAsReadNotificationView urlpatterns = [ @@ -16,8 +16,10 @@ urlpatterns = [ url(r'orders/(?P\d+)/?$', OrdersHostingDetailView.as_view(), name='orders'), url(r'cancel_order/(?P\d+)/?$', OrdersHostingDeleteView.as_view(), name='delete_order'), url(r'my-virtual-machines/?$', VirtualMachinesPlanListView.as_view(), name='virtual_machines'), - url(r'my-virtual-machines/(?P\d+)/?$', VirtualMachineDetailView.as_view(), + url(r'my-virtual-machines/(?P\d+)/?$', VirtualMachineView.as_view(), name='virtual_machines'), + # url(r'my-virtual-machines/(?P\d+)/delete/?$', VirtualMachineCancelView.as_view(), + # name='virtual_machines_cancel'), url(r'my-virtual-machines/(?P\d+)/key/?$', GenerateVMSSHKeysView.as_view(), name='virtual_machine_key'), url(r'^notifications/$', NotificationsView.as_view(), name='notifications'), diff --git a/hosting/views.py b/hosting/views.py index d9026d4c..eca04023 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -350,8 +350,34 @@ class VirtualMachinesPlanListView(LoginRequiredMixin, ListView): return super(VirtualMachinesPlanListView, self).get_queryset() -class VirtualMachineDetailView(LoginRequiredMixin, DetailView): +class VirtualMachineView(LoginRequiredMixin, UpdateView): template_name = "hosting/virtual_machine_detail.html" login_url = reverse_lazy('hosting:login') model = VirtualMachinePlan context_object_name = "virtual_machine" + fields = '__all__' + + def get_success_url(self): + vm = self.get_object() + final_url = "%s%s" % (reverse('hosting:virtual_machines', kwargs={'pk': vm.id}), + '#status-v') + return final_url + + def post(self, *args, **kwargs): + vm = self.get_object() + vm.cancel_plan() + + context = { + 'vm': vm + } + email_data = { + 'subject': 'Virtual machine plan canceled', + 'to': self.request.user.email, + 'context': context, + 'template_name': 'vm_status_changed', + 'template_path': 'emails/' + } + email = BaseEmail(**email_data) + email.send() + + return HttpResponseRedirect(self.get_success_url())