Added serializer to VM model, Rewrite django hosting view , Created price selection templates , Added price selector with automatic price change
This commit is contained in:
parent
3015399692
commit
cb51e08cef
7 changed files with 412 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core import serializers
|
||||
import json
|
||||
|
||||
|
||||
class RailsBetaUser(models.Model):
|
||||
|
@ -37,5 +38,20 @@ class VirtualMachineType(models.Model):
|
|||
def __str__(self):
|
||||
return "%s" % (self.get_hosting_company_display())
|
||||
|
||||
@classmethod
|
||||
def get_serialized_vm_types(cls):
|
||||
return [vm.get_serialized_data()
|
||||
for vm in cls.objects.all()]
|
||||
# return serializers.serialize("json",)
|
||||
|
||||
def get_serialized_data(self):
|
||||
return serializers("json", self)
|
||||
return {
|
||||
'description': self.description,
|
||||
'base_price': self.base_price,
|
||||
'core_price': self.core_price,
|
||||
'disk_size_price': self.disk_size_price,
|
||||
'memory_price': self.memory_price,
|
||||
'hosting_company_name': self.get_hosting_company_display(),
|
||||
'hosting_company': self.hosting_company,
|
||||
'id': self.id,
|
||||
}
|
||||
|
|
95
hosting/static/hosting/css/pricing.css
Normal file
95
hosting/static/hosting/css/pricing.css
Normal file
|
@ -0,0 +1,95 @@
|
|||
.pricing {
|
||||
text-align: center;
|
||||
border: 1px solid #f0f0f0;
|
||||
color: #777;
|
||||
font-size: 14px;
|
||||
padding-left: 0;
|
||||
margin-bottom: 30px;
|
||||
font-family: 'Lato';
|
||||
}
|
||||
.pricing img {
|
||||
display: block;
|
||||
margin: auto;
|
||||
width: 32px;
|
||||
}
|
||||
.pricing li:first-child,
|
||||
.pricing li:last-child {
|
||||
padding: 20px 13px;
|
||||
}
|
||||
.pricing li {
|
||||
list-style: none;
|
||||
padding: 13px;
|
||||
}
|
||||
.pricing li + li {
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
.pricing big {
|
||||
font-size: 32px;
|
||||
}
|
||||
.pricing h3 {
|
||||
margin-bottom: 0;
|
||||
font-size: 36px;
|
||||
}
|
||||
.pricing span {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
font-weight: normal;
|
||||
}
|
||||
.pricing li:nth-last-child(2) {
|
||||
padding: 30px 13px;
|
||||
}
|
||||
.pricing button {
|
||||
width: auto;
|
||||
margin: auto;
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
border-radius: 50px;
|
||||
color: #fff;
|
||||
padding: 9px 24px;
|
||||
background: #aaa;
|
||||
opacity: 1;
|
||||
transition: opacity .2s ease;
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
.pricing button:hover {
|
||||
opacity: .9;
|
||||
}
|
||||
.pricing button:active {
|
||||
box-shadow: inset 0px 2px 2px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
/* pricing color */
|
||||
.p-green big,
|
||||
.p-green h3 {
|
||||
color: #4c7737;
|
||||
}
|
||||
.p-green button {
|
||||
background: #4c7737;
|
||||
}
|
||||
.p-yel big,
|
||||
.p-yel h3 {
|
||||
color: #ffbb42;
|
||||
}
|
||||
.p-yel button {
|
||||
background: #ffbb42;
|
||||
}
|
||||
.p-red big,
|
||||
.p-red h3 {
|
||||
color: #e13c4c;
|
||||
}
|
||||
|
||||
.pricing .short-input{
|
||||
min-width: 0;
|
||||
width: 90px;
|
||||
}
|
||||
|
||||
.p-red button {
|
||||
background: #e13c4c;
|
||||
}
|
||||
.p-blue big,
|
||||
.p-blue h3 {
|
||||
color: #3f4bb8;
|
||||
}
|
||||
.p-blue button {
|
||||
background: #3f4bb8;
|
||||
}
|
58
hosting/static/hosting/js/pricing.js
Normal file
58
hosting/static/hosting/js/pricing.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
$( document ).ready(function() {
|
||||
|
||||
//we need to load first VMTypesData from base.html django template
|
||||
var pricingData = window.VMTypesData;
|
||||
|
||||
|
||||
// Function to calculate the price given a vm type
|
||||
function calculate_price(vm_type){
|
||||
|
||||
var ID_SELECTOR = "#";
|
||||
var CURRENCY = "$";
|
||||
var final_price_selector = ID_SELECTOR.concat(vm_type.concat('-final-price'));
|
||||
var core_selector = ID_SELECTOR.concat(vm_type.concat('-cores'));
|
||||
var memory_selector = ID_SELECTOR.concat(vm_type.concat('-memory'));
|
||||
var disk_size_selector = ID_SELECTOR.concat(vm_type.concat('-disk_space'));
|
||||
|
||||
//Get vm type prices
|
||||
var cores = $(core_selector).val();
|
||||
var memory = $(memory_selector).val();
|
||||
var disk_size = $(disk_size_selector).val();
|
||||
var pricingData = eval(window.VMTypesData);
|
||||
var company_prices = _.head(_.filter(pricingData, {hosting_company: vm_type}));
|
||||
|
||||
//Calculate final price
|
||||
var price = company_prices.base_price;
|
||||
price += company_prices.core_price*cores;
|
||||
price += company_prices.memory_price*memory;
|
||||
price += company_prices.disk_size_price*disk_size;
|
||||
|
||||
console.log(final_price_selector);
|
||||
$(final_price_selector).text(price.toString().concat(CURRENCY));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Listener function
|
||||
function change_attribute(e){
|
||||
|
||||
var vm_type = this.getAttribute('data-vm-type');
|
||||
calculate_price(vm_type);
|
||||
}
|
||||
|
||||
|
||||
//Listeners
|
||||
$('.cores-selector').on('change',change_attribute);
|
||||
|
||||
$('.memory-selector').on('change',change_attribute);
|
||||
|
||||
$('.disk-space-selector').on('change',change_attribute);
|
||||
|
||||
console.log("mirame",window.VMTypesData);
|
||||
|
||||
|
||||
});
|
|
@ -13,12 +13,17 @@
|
|||
|
||||
<title>{{ domain }} - {{ hosting }} hosting as easy as possible</title>
|
||||
|
||||
|
||||
<!-- Bootstrap Core CSS -->
|
||||
<link href="{% static 'hosting/css/bootstrap.min.css' %}" rel="stylesheet">
|
||||
|
||||
<link href="{% static 'hosting/css/pricing.css' %}" rel="stylesheet">
|
||||
|
||||
|
||||
<!-- Custom CSS -->
|
||||
<link href="{% static 'hosting/css/landing-page.css' %}" rel="stylesheet">
|
||||
|
||||
|
||||
<!-- Custom Fonts -->
|
||||
<link href='http://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
|
||||
<link href="{% static 'hosting/font-awesome/css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
|
||||
|
@ -215,7 +220,9 @@
|
|||
<!-- Page Features -->
|
||||
<div class="row text-center">
|
||||
|
||||
<div class="col-md-3 col-sm-6 hero-feature">
|
||||
{% include "hosting/pricing.html" %}
|
||||
|
||||
<!-- <div class="col-md-3 col-sm-6 hero-feature">
|
||||
<div class="thumbnail">
|
||||
<img class="relsonsive" src="{% static 'hosting/img/economy.jpg' %}" alt="">
|
||||
<div class="caption">
|
||||
|
@ -276,7 +283,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
-->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
</div>
|
||||
|
@ -384,9 +391,24 @@
|
|||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Pricing data -->
|
||||
{% if vm_types %}
|
||||
<script type="text/javascript">
|
||||
(function () {window.VMTypesData = "{{vm_types|safe}}";})();
|
||||
</script>
|
||||
{%endif%}
|
||||
|
||||
|
||||
<!-- Lodash -->
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.11.1/lodash.min.js"></script>
|
||||
|
||||
<!-- jQuery -->
|
||||
<script src="{% static 'hosting/js/jquery.js' %}"></script>
|
||||
|
||||
<!-- Pricing -->
|
||||
<script src="{% static 'hosting/js/pricing.js' %}"></script>
|
||||
|
||||
|
||||
<!-- Bootstrap Core JavaScript -->
|
||||
<script src="{% static 'hosting/js/bootstrap.min.js' %}"></script>
|
||||
|
||||
|
|
186
hosting/templates/hosting/pricing.html
Normal file
186
hosting/templates/hosting/pricing.html
Normal file
|
@ -0,0 +1,186 @@
|
|||
<div class="row white">
|
||||
<div class="block">
|
||||
|
||||
{% for vm in vm_types %}
|
||||
<div class="row well pricing">
|
||||
<form class="form-inline p-green" role="form">
|
||||
<div class="btn-group col-md-3">
|
||||
<div class="form-group">
|
||||
|
||||
<big>
|
||||
{{vm.hosting_company_name}}
|
||||
</big>
|
||||
|
||||
<p>
|
||||
{{vm.description}}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group col-md-2">
|
||||
<div class="form-group">
|
||||
<label for="cores">Cores:</label>
|
||||
<select class="form-control" id="cores">
|
||||
{% with ''|center:10 as range %}
|
||||
{% for _ in range %}
|
||||
<option>{{ forloop.counter }}</option>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group col-md-2">
|
||||
<label for="memory">Memory: </label>
|
||||
<div class="form-group">
|
||||
|
||||
<select class="form-control short-input" id="memory">
|
||||
{% with ''|center:50 as range %}
|
||||
{% for _ in range %}
|
||||
<option>{{ forloop.counter }}</option>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
</select>
|
||||
<span>GiB</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-md-2">
|
||||
<label for="Disk Size">Disk Size: </label>
|
||||
<input class="form-control short-input" type="number" id="disk_space" min="0" value="0"/>
|
||||
<span>GiB</span>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<h3>$199</h3>
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<button type="submit" class="btn btn-default">Buy it</button>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- <button type="submit" class="btn btn-default">Submit</button> -->
|
||||
|
||||
|
||||
</form>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% for vm in vm_types %}
|
||||
<div class="col-xs-12 col-sm-6 col-md-3">
|
||||
<form class="form-inline">
|
||||
<ul class="pricing {% cycle 'p-green' 'p-yel' 'p-red' 'p-blue' %}">
|
||||
<li style="height:200px;">
|
||||
<!-- <img src="http://bread.pp.ua/n/settings_g.svg" alt=""> -->
|
||||
<h3 >{{vm.hosting_company_name}}</h3>
|
||||
</li>
|
||||
<li>
|
||||
<!-- Single button -->
|
||||
<div class="btn-group">
|
||||
<div class="form-group">
|
||||
<label for="cores">Cores: </label>
|
||||
<select class="form-control cores-selector" id="{{vm.hosting_company}}-cores" data-vm-type="{{vm.hosting_company}}">
|
||||
{% with ''|center:10 as range %}
|
||||
{% for _ in range %}
|
||||
<option>{{ forloop.counter }}</option>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</li>
|
||||
<li class="row">
|
||||
<div class="btn-group">
|
||||
<div class="form-group">
|
||||
<label for="memory">Memory: </label>
|
||||
<select class="form-control memory-selector" id="{{vm.hosting_company}}-memory" data-vm-type="{{vm.hosting_company}}">
|
||||
{% with ''|center:50 as range %}
|
||||
{% for _ in range %}
|
||||
<option>{{ forloop.counter }}</option>
|
||||
{% endfor %}
|
||||
{% endwith %}
|
||||
</select>
|
||||
<span>GiB</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<li class="row">
|
||||
<div class="form-group">
|
||||
<label for="Disk Size">Disk Size: </label>
|
||||
<input class="form-control short-input disk-space-selector" type="number" id="{{vm.hosting_company}}-disk_space" min="1" value="1" data-vm-type="{{vm.hosting_company}}"/>
|
||||
<span>GiB</span>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<h3 id="{{vm.hosting_company}}-final-price">select</h3>
|
||||
<span>per month</span>
|
||||
</li>
|
||||
<li>
|
||||
<button>Buy it</button>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
<!--
|
||||
<div class="col-xs-12 col-sm-6 col-md-3">
|
||||
<ul class="pricing p-yel">
|
||||
<li>
|
||||
<img src="http://bread.pp.ua/n/settings_y.svg" alt="">
|
||||
<big>Good</big>
|
||||
</li>
|
||||
<li>Responsive Design</li>
|
||||
<li>Color Customization</li>
|
||||
<li>HTML5 & CSS3</li>
|
||||
<li>Styled elements</li>
|
||||
<li>
|
||||
<h3>$299</h3>
|
||||
<span>per month</span>
|
||||
</li>
|
||||
<li>
|
||||
<button>Join Now</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-6 col-md-3">
|
||||
<ul class="pricing p-red">
|
||||
<li>
|
||||
<img src="http://bread.pp.ua/n/settings_r.svg" alt="">
|
||||
<big>Ultima</big>
|
||||
</li>
|
||||
<li>Responsive Design</li>
|
||||
<li>Color Customization</li>
|
||||
<li>HTML5 & CSS3</li>
|
||||
<li>Styled elements</li>
|
||||
<li>
|
||||
<h3>$399</h3>
|
||||
<span>per month</span>
|
||||
</li>
|
||||
<li>
|
||||
<button>Join Now</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-12 col-sm-6 col-md-3">
|
||||
<ul class="pricing p-blue">
|
||||
<li>
|
||||
<img src="http://bread.pp.ua/n/settings_b.svg" alt="">
|
||||
<big>Vip</big>
|
||||
</li>
|
||||
<li>Responsive Design</li>
|
||||
<li>Color Customization</li>
|
||||
<li>HTML5 & CSS3</li>
|
||||
<li>Styled elements</li>
|
||||
<li>
|
||||
<h3>$799</h3>
|
||||
<span>per month</span>
|
||||
</li>
|
||||
<li>
|
||||
<button>Join Now</button>
|
||||
</li>
|
||||
</ul>
|
||||
</div> -->
|
||||
|
||||
|
||||
</div><!-- /block -->
|
||||
</div><!-- /row -->
|
|
@ -1,10 +1,12 @@
|
|||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
from .views import VMPricingView, DjangoHostingView
|
||||
|
||||
urlpatterns = [
|
||||
url(r'beta$', views.beta, name='beta'),
|
||||
url(r'django$', views.djangohosting, name='djangohosting'),
|
||||
url(r'pricing/?$', VMPricingView.as_view(), name='pricing'),
|
||||
url(r'django/?$', DjangoHostingView.as_view(), name='djangohosting'),
|
||||
url(r'nodejs$', views.nodejshosting, name='nodejshosting'),
|
||||
url(r'rails$', views.railshosting, name='railshosting'),
|
||||
]
|
||||
|
|
|
@ -7,8 +7,36 @@ from django.core.urlresolvers import reverse
|
|||
|
||||
from django.core.mail import send_mail
|
||||
from django.core.mail import mail_managers
|
||||
from django.views.generic import View, DetailView
|
||||
|
||||
|
||||
from .models import RailsBetaUser, VirtualMachineType
|
||||
|
||||
|
||||
class VMPricingView(View):
|
||||
template_name = "hosting/pricing.html"
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return render(request, self.template_name, request)
|
||||
|
||||
|
||||
class DjangoHostingView(View):
|
||||
template_name = "hosting/django.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {}
|
||||
context["hosting"] = "django"
|
||||
context["hosting_long"] = "Django"
|
||||
context["domain"] = "django-hosting.ch"
|
||||
context["google_analytics"] = "UA-62285904-6"
|
||||
context["email"] = "info@django-hosting.ch"
|
||||
context["vm_types"] = VirtualMachineType.get_serialized_vm_types()
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
context = self.get_context_data()
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
from .models import RailsBetaUser
|
||||
|
||||
class RailsBetaUserForm(ModelForm):
|
||||
required_css_class = 'form-control'
|
||||
|
|
Loading…
Reference in a new issue