diff --git a/dynamicweb/settings/base.py b/dynamicweb/settings/base.py index 5f59a319..ab2d6763 100644 --- a/dynamicweb/settings/base.py +++ b/dynamicweb/settings/base.py @@ -54,6 +54,7 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'easy_thumbnails', 'utils', + 'stored_messages', 'mptt', 'parler', 'taggit', @@ -132,6 +133,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..ef6249a6 100644 --- a/hosting/admin.py +++ b/hosting/admin.py @@ -1,5 +1,32 @@ from django.contrib import admin -from .models import VirtualMachineType + +from utils.mailer import BaseEmail +from .models import VirtualMachineType, VirtualMachinePlan + + +class VirtualMachinePlanAdmin(admin.ModelAdmin): + list_display = ('name', 'id', 'email') + + def email(self, obj): + return obj.hosting_orders.latest('id').customer.user.email + + def save_model(self, request, obj, form, change): + email = self.email(obj) + if 'status' in form.changed_data and obj.status == VirtualMachinePlan.ONLINE_STATUS: + context = { + 'vm': obj + } + email_data = { + 'subject': 'Your VM has been activated', + 'to': email, + 'context': context, + 'template_name': 'vm_activated', + 'template_path': 'emails/' + } + email = BaseEmail(**email_data) + email.send() + obj.save() admin.site.register(VirtualMachineType) +admin.site.register(VirtualMachinePlan, VirtualMachinePlanAdmin) diff --git a/hosting/migrations/0019_virtualmachineplan_status.py b/hosting/migrations/0019_virtualmachineplan_status.py new file mode 100644 index 00000000..e1bd5382 --- /dev/null +++ b/hosting/migrations/0019_virtualmachineplan_status.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-05-26 02:57 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hosting', '0018_virtualmachineplan_public_key'), + ] + + operations = [ + migrations.AddField( + model_name='virtualmachineplan', + name='status', + field=models.CharField(choices=[('pending', 'Pending for activation'), ('online', 'Online')], default='online', max_length=20), + ), + ] diff --git a/hosting/migrations/0020_auto_20160526_0258.py b/hosting/migrations/0020_auto_20160526_0258.py new file mode 100644 index 00000000..7cafc1ac --- /dev/null +++ b/hosting/migrations/0020_auto_20160526_0258.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-05-26 02:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hosting', '0019_virtualmachineplan_status'), + ] + + operations = [ + migrations.AlterField( + model_name='virtualmachineplan', + name='status', + field=models.CharField(choices=[('pending', 'Pending for activation'), ('online', 'Online')], default='pending', max_length=20), + ), + ] diff --git a/hosting/migrations/0021_auto_20160526_0445.py b/hosting/migrations/0021_auto_20160526_0445.py new file mode 100644 index 00000000..90ed64b1 --- /dev/null +++ b/hosting/migrations/0021_auto_20160526_0445.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.4 on 2016-05-26 04:45 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('hosting', '0020_auto_20160526_0258'), + ] + + operations = [ + migrations.AlterField( + model_name='virtualmachineplan', + name='status', + field=models.CharField(choices=[('pending', 'Pending for activation'), ('online', 'Online'), ('canceled', 'Canceled')], default='pending', max_length=20), + ), + ] diff --git a/hosting/models.py b/hosting/models.py index 55709fca..518ba175 100644 --- a/hosting/models.py +++ b/hosting/models.py @@ -3,12 +3,13 @@ import os from django.db import models from django.utils.translation import ugettext_lazy as _ from django.utils.functional import cached_property -from membership.models import StripeCustomer -from utils.models import BillingAddress + from Crypto.PublicKey import RSA +from stored_messages.settings import stored_messages_settings - +from membership.models import StripeCustomer +from utils.models import BillingAddress from .managers import VMPlansManager @@ -81,12 +82,24 @@ class VirtualMachineType(models.Model): class VirtualMachinePlan(models.Model): + + PENDING_STATUS = 'pending' + ONLINE_STATUS = 'online' + CANCELED_STATUS = 'canceled' + + VM_STATUS_CHOICES = ( + (PENDING_STATUS, 'Pending for activation'), + (ONLINE_STATUS, 'Online'), + (CANCELED_STATUS, 'Canceled') + ) + cores = models.IntegerField() memory = models.IntegerField() disk_size = models.IntegerField() vm_type = models.ForeignKey(VirtualMachineType) price = models.FloatField() public_key = models.TextField() + status = models.CharField(max_length=20, choices=VM_STATUS_CHOICES, default=PENDING_STATUS) objects = VMPlansManager() @@ -97,11 +110,22 @@ class VirtualMachinePlan(models.Model): def hosting_company_name(self): return self.vm_type.get_hosting_company_display() + @cached_property + def location(self): + return self.vm_type.get_location_display() + @cached_property def name(self): name = 'vm-%s' % self.id return name + @cached_property + def notifications(self): + stripe_customer = StripeCustomer.objects.get(hostingorder__vm_plan=self) + backend = stored_messages_settings.STORAGE_BACKEND() + messages = backend.inbox_list(stripe_customer.user) + return messages + @classmethod def create(cls, data, user): instance = cls.objects.create(**data) 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..2785e686 --- /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..2785e686 --- /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/emails/vm_activated.html b/hosting/templates/emails/vm_activated.html new file mode 100644 index 00000000..92eec368 --- /dev/null +++ b/hosting/templates/emails/vm_activated.html @@ -0,0 +1,13 @@ + +{% 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 new file mode 100644 index 00000000..f7f85457 --- /dev/null +++ b/hosting/templates/emails/vm_activated.txt @@ -0,0 +1,15 @@ + +{% 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/hosting/base_short.html b/hosting/templates/hosting/base_short.html index 874b590f..55466815 100644 --- a/hosting/templates/hosting/base_short.html +++ b/hosting/templates/hosting/base_short.html @@ -71,7 +71,11 @@ My Orders - +
  • + + Notifications + +