diff --git a/hosting/admin.py b/hosting/admin.py
index ef6249a6..17cb5591 100644
--- a/hosting/admin.py
+++ b/hosting/admin.py
@@ -1,7 +1,68 @@
from django.contrib import admin
+from django.utils.html import format_html
+from django.core.urlresolvers import reverse
from utils.mailer import BaseEmail
-from .models import VirtualMachineType, VirtualMachinePlan
+from utils.stripe_utils import StripeUtils
+
+from .forms import HostingOrderAdminForm
+from .models import VirtualMachineType, VirtualMachinePlan, HostingOrder
+
+
+class HostingOrderAdmin(admin.ModelAdmin):
+ # fields = ('slug', 'imdb_link', 'start', 'finish', 'added_by')
+ list_display = ('id', 'created_at', 'plan', 'user')
+ search_fields = ['vm_plan__id', 'customer__user__email']
+
+ def save_model(self, request, obj, form, change):
+ if not change:
+ customer = form.cleaned_data.get('customer')
+
+ # Get and set billing address from the lastest charged order
+ last_order = HostingOrder.objects.filter(customer=customer).latest('id')
+ billing_address = last_order.billing_address
+ obj.billing_address = billing_address
+
+ charge = form.cleaned_data.get('charge')
+ # Associate an order with a stripe payment
+ obj.set_stripe_charge(charge)
+
+ # If the Stripe payment was successed, set order status approved
+ obj.set_approved()
+
+ context = {
+ 'order': obj,
+ 'vm': obj.vm_plan
+ }
+ email_data = {
+ 'subject': 'New VM request',
+ 'to': obj.customer.user.email,
+ 'context': context,
+ 'template_name': 'vm_charged',
+ 'template_path': 'emails/'
+ }
+ email = BaseEmail(**email_data)
+ email.send()
+
+ obj.save()
+ return obj
+
+ def get_form(self, request, obj=None, **kwargs):
+ if obj is None:
+ kwargs['form'] = HostingOrderAdminForm
+ return super(HostingOrderAdmin, self).get_form(request, obj, **kwargs)
+
+ def user(self, obj):
+ email = obj.customer.user.email
+ user_url = reverse("admin:membership_customuser_change", args=[obj.customer.user.id])
+ return format_html("{email}", url=user_url, email=email)
+
+ def plan(self, obj):
+ vm_name = obj.vm_plan.name
+ vm_url = reverse("admin:hosting_virtualmachineplan_change", args=[obj.vm_plan.id])
+ return format_html("{vm_name}", url=vm_url, vm_name=vm_name)
+
+ plan.short_description = "Virtual Machine Plan"
class VirtualMachinePlanAdmin(admin.ModelAdmin):
@@ -28,5 +89,6 @@ class VirtualMachinePlanAdmin(admin.ModelAdmin):
obj.save()
+admin.site.register(HostingOrder, HostingOrderAdmin)
admin.site.register(VirtualMachineType)
admin.site.register(VirtualMachinePlan, VirtualMachinePlanAdmin)
diff --git a/hosting/forms.py b/hosting/forms.py
index ddb30e1c..c6537355 100644
--- a/hosting/forms.py
+++ b/hosting/forms.py
@@ -2,6 +2,34 @@ from django import forms
from membership.models import CustomUser
from django.contrib.auth import authenticate
+from utils.stripe_utils import StripeUtils
+
+from .models import HostingOrder
+
+
+class HostingOrderAdminForm(forms.ModelForm):
+
+ class Meta:
+ model = HostingOrder
+ fields = ['vm_plan', 'customer']
+
+ def clean(self):
+ customer = self.cleaned_data.get('customer')
+ vm_plan = self.cleaned_data.get('vm_plan')
+
+ # Make a charge to the customer
+ stripe_utils = StripeUtils()
+ charge_response = stripe_utils.make_charge(customer=customer.stripe_id,
+ amount=vm_plan.price)
+ charge = charge_response.get('response_object')
+ if not charge:
+ raise forms.ValidationError(charge_response.get('error'))
+
+ self.cleaned_data.update({
+ 'charge': charge
+ })
+ return self.cleaned_data
+
class HostingUserLoginForm(forms.Form):
diff --git a/hosting/models.py b/hosting/models.py
index 518ba175..a8237f3a 100644
--- a/hosting/models.py
+++ b/hosting/models.py
@@ -104,7 +104,7 @@ class VirtualMachinePlan(models.Model):
objects = VMPlansManager()
def __str__(self):
- return "%s" % (self.id)
+ return self.name
@cached_property
def hosting_company_name(self):
diff --git a/hosting/static/hosting/css/landing-page.css b/hosting/static/hosting/css/landing-page.css
index c79f35a7..52e14f6e 100644
--- a/hosting/static/hosting/css/landing-page.css
+++ b/hosting/static/hosting/css/landing-page.css
@@ -72,12 +72,12 @@ h6 {
}
.intro-login {
- background: url(../img/intro-bg.jpg) no-repeat center center;
+ background: url(../img/login-bg.jpg) no-repeat center center;
background-size: cover;
}
.intro-signup {
- background: url(../img/configure.jpg) no-repeat center center;
+ background: url(../img/signup-bg.png) no-repeat center center;
background-size: cover;
}
diff --git a/hosting/static/hosting/css/pricing.css b/hosting/static/hosting/css/pricing.css
index 227be49d..8eba7ffa 100644
--- a/hosting/static/hosting/css/pricing.css
+++ b/hosting/static/hosting/css/pricing.css
@@ -36,13 +36,21 @@
height: 150px;
}
+.pricing li .form-control{
+ width:auto;
+ display:inline-block;
+}
+
.pricing big {
font-size: 32px;
}
.pricing h3 {
- margin-bottom: 0;
- font-size: 36px;
+ margin-bottom: 0;
+ font-size: 31px;
+ font-weight: bold;
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
+
.pricing span {
font-size: 12px;
color: #999;
@@ -103,7 +111,7 @@
.pricing .short-input{
min-width: 0;
- width: 90px;
+ width: 75px !important;
display: inline;
}
diff --git a/hosting/static/hosting/img/card-django.png b/hosting/static/hosting/img/card-django.png
index 92dfc2df..902be1b4 100644
Binary files a/hosting/static/hosting/img/card-django.png and b/hosting/static/hosting/img/card-django.png differ
diff --git a/hosting/static/hosting/img/login-bg.jpg b/hosting/static/hosting/img/login-bg.jpg
new file mode 100644
index 00000000..afe2b29e
Binary files /dev/null and b/hosting/static/hosting/img/login-bg.jpg differ
diff --git a/hosting/static/hosting/img/signup-bg.png b/hosting/static/hosting/img/signup-bg.png
new file mode 100644
index 00000000..c4803bc0
Binary files /dev/null and b/hosting/static/hosting/img/signup-bg.png differ
diff --git a/hosting/templates/emails/new_booked_vm.html b/hosting/templates/emails/new_booked_vm.html
index 2785e686..a36f12a8 100644
--- a/hosting/templates/emails/new_booked_vm.html
+++ b/hosting/templates/emails/new_booked_vm.html
@@ -1,12 +1,139 @@
-
-
-
+
+
+
-
+
+
+Oxygen Invoice
-
-
-NEW VM BOOKED
-
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Your virtual machine {{vm.name}} subscription has been charged,
+
+ we are going to contact you as soon your virtual machine has been activated.
+
+ You can view your invoice clicking on the button below.
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+
-
\ No newline at end of file
+
+
diff --git a/hosting/templates/emails/new_booked_vm.txt b/hosting/templates/emails/new_booked_vm.txt
index 2785e686..3f32d12a 100644
--- a/hosting/templates/emails/new_booked_vm.txt
+++ b/hosting/templates/emails/new_booked_vm.txt
@@ -1,12 +1,139 @@
-
-
-
+
+
+
-
+
+
+Oxygen Invoice
-
-
-NEW VM BOOKED
-
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Your virtual machine {{vm.name}} subscription has been charged,
+
+ We are going to contact you as soon your virtual machine has been activated.
+
+ You can view your invoice clicking on the button below.
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+
-
\ No newline at end of file
+
+
diff --git a/hosting/templates/emails/vm_charged.html b/hosting/templates/emails/vm_charged.html
new file mode 100644
index 00000000..3f0f5f8f
--- /dev/null
+++ b/hosting/templates/emails/vm_charged.html
@@ -0,0 +1,135 @@
+
+
+
+
+
+
+Oxygen Invoice
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Your virtual machine {{vm.name}} subscription has been charged, you can view your invoice clicking on the button below.
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+
+
+
+
diff --git a/hosting/templates/emails/vm_charged.txt b/hosting/templates/emails/vm_charged.txt
new file mode 100644
index 00000000..3f0f5f8f
--- /dev/null
+++ b/hosting/templates/emails/vm_charged.txt
@@ -0,0 +1,135 @@
+
+
+
+
+
+
+Oxygen Invoice
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+ Your virtual machine {{vm.name}} subscription has been charged, you can view your invoice clicking on the button below.
+ |
+
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+
+
+ |
+
+
+
+
+
diff --git a/hosting/templates/hosting/includes/_pricing.html b/hosting/templates/hosting/includes/_pricing.html
index 2f8033bc..c61c27dc 100644
--- a/hosting/templates/hosting/includes/_pricing.html
+++ b/hosting/templates/hosting/includes/_pricing.html
@@ -47,7 +47,7 @@