cleaned code
This commit is contained in:
		
					parent
					
						
							
								8980f6b2fc
							
						
					
				
			
			
				commit
				
					
						07dc04018f
					
				
			
		
					 3 changed files with 44 additions and 28 deletions
				
			
		| 
						 | 
					@ -1,19 +1,19 @@
 | 
				
			||||||
from django.shortcuts import redirect
 | 
					from django.shortcuts import redirect
 | 
				
			||||||
from django.core.urlresolvers import reverse
 | 
					from django.core.urlresolvers import reverse
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from opennebula_api.serializers import VirtualMachineTemplateSerializer
 | 
				
			||||||
 | 
					from opennebula_api.models import OpenNebulaManager
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ProcessVMSelectionMixin(object):
 | 
					class ProcessVMSelectionMixin(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def post(self, request, *args, **kwargs):
 | 
					    def post(self, request, *args, **kwargs):
 | 
				
			||||||
        #configuration = request.POST.get('configuration')
 | 
					
 | 
				
			||||||
        #configuration_display = dict(VirtualMachinePlan.VM_CONFIGURATION).get(configuration)
 | 
					        template_id = int(request.POST.get('vm_template_id'))
 | 
				
			||||||
        vm_template_id = request.POST.get('vm_template_id')
 | 
					        template = OpenNebulaManager().get_template(template_id)
 | 
				
			||||||
        vm_specs.update({
 | 
					        data = VirtualMachineTemplateSerializer(template).data
 | 
				
			||||||
            'configuration_display': configuration_display,
 | 
					        request.session['template'] = data
 | 
				
			||||||
            'configuration': configuration,
 | 
					
 | 
				
			||||||
            'vm_template_id': vm_template_id
 | 
					 | 
				
			||||||
        })
 | 
					 | 
				
			||||||
        request.session['vm_specs'] = vm_specs
 | 
					 | 
				
			||||||
        if not request.user.is_authenticated():
 | 
					        if not request.user.is_authenticated():
 | 
				
			||||||
            request.session['next'] = reverse('hosting:payment')
 | 
					            request.session['next'] = reverse('hosting:payment')
 | 
				
			||||||
            return redirect(reverse('hosting:login'))
 | 
					            return redirect(reverse('hosting:login'))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,7 +24,7 @@
 | 
				
			||||||
                {% csrf_token %}
 | 
					                {% csrf_token %}
 | 
				
			||||||
                <input type="hidden" name="hosting_company" value="{{vm.hosting_company}}">
 | 
					                <input type="hidden" name="hosting_company" value="{{vm.hosting_company}}">
 | 
				
			||||||
                <input type="hidden" name="location_code" value="{{vm.location_code}}">
 | 
					                <input type="hidden" name="location_code" value="{{vm.location_code}}">
 | 
				
			||||||
                <input type="hidden" name="vm_template" value="{{vm.id}}">
 | 
					                <input type="hidden" name="vm_template_id" value="{{vm.id}}">
 | 
				
			||||||
               
 | 
					               
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
| 
						 | 
					@ -53,17 +53,17 @@
 | 
				
			||||||
                      </div>
 | 
					                      </div>
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
                  </li>
 | 
					                  </li>
 | 
				
			||||||
                  <li>
 | 
					<!--                   <li>
 | 
				
			||||||
                  <label for="configuration">Configuration: </label>
 | 
					                  <label for="configuration">Configuration: </label>
 | 
				
			||||||
                        <select class="form-control" name="configuration" id="{{vm.hosting_company}}-configuration" data-vm-type="{{vm.hosting_company}}">
 | 
					                        <select class="form-control" name="configuration" id="{{vm.hosting_company}}-configuration" data-vm-type="{{vm.hosting_company}}">
 | 
				
			||||||
                        {% for key,value in configuration_options.items   %}
 | 
					                        {% for key,value in configuration_options.items   %}
 | 
				
			||||||
                            <option  value="{{key}}">{{ value }}</option>
 | 
					                            <option  value="{{key}}">{{ value }}</option>
 | 
				
			||||||
                        {% endfor %}
 | 
					                        {% endfor %}
 | 
				
			||||||
                        </select>
 | 
					                        </select>
 | 
				
			||||||
                  </li>
 | 
					                  </li> -->
 | 
				
			||||||
                  <li>
 | 
					                  <li>
 | 
				
			||||||
                    <input type="hidden" name="final_price" value="{{vm.final_price|floatformat}}">
 | 
					                    <input type="hidden" name="final_price" value="{{vm.final_price|floatformat}}">
 | 
				
			||||||
                    <h3 id="{{vm.hosting_company}}-final-price">{{vm.final_price|floatformat}}CHF</h3>
 | 
					                    <h3 id="{{vm.hosting_company}}-final-price">{{vm.price|floatformat}} CHF</h3>
 | 
				
			||||||
                    <span>per month</span>
 | 
					                    <span>per month</span>
 | 
				
			||||||
                  </li>
 | 
					                  </li>
 | 
				
			||||||
                  <li>
 | 
					                  <li>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,16 +42,20 @@ class DjangoHostingView(ProcessVMSelectionMixin, View):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_context_data(self, **kwargs):
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
        HOSTING = 'django'
 | 
					        HOSTING = 'django'
 | 
				
			||||||
        configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
 | 
					        templates = OpenNebulaManager().get_templates()
 | 
				
			||||||
 | 
					        data = VirtualMachineTemplateSerializer(templates, many=True).data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            'hosting': HOSTING,
 | 
					            'hosting': HOSTING,
 | 
				
			||||||
            'hosting_long': "Django",
 | 
					            'hosting_long': "Django",
 | 
				
			||||||
            'configuration_detail': configuration_detail,
 | 
					            # 'configuration_detail': configuration_detail,
 | 
				
			||||||
            'domain': "django-hosting.ch",
 | 
					            'domain': "django-hosting.ch",
 | 
				
			||||||
            'google_analytics': "UA-62285904-6",
 | 
					            'google_analytics': "UA-62285904-6",
 | 
				
			||||||
 | 
					            'vm_types': data,
 | 
				
			||||||
            'email': "info@django-hosting.ch",
 | 
					            'email': "info@django-hosting.ch",
 | 
				
			||||||
            'vm_types': VirtualMachineType.get_serialized_vm_types(),
 | 
					            # 'vm_types': VirtualMachineType.get_serialized_vm_types(),
 | 
				
			||||||
            'configuration_options': dict(VirtualMachinePlan.VM_CONFIGURATION)
 | 
					            # 'configuration_options': dict(VirtualMachinePlan.VM_CONFIGURATION)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
| 
						 | 
					@ -68,15 +72,17 @@ class RailsHostingView(ProcessVMSelectionMixin, View):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_context_data(self, **kwargs):
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
        HOSTING = 'rails'
 | 
					        HOSTING = 'rails'
 | 
				
			||||||
        configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
 | 
					
 | 
				
			||||||
 | 
					        templates = OpenNebulaManager().get_templates()
 | 
				
			||||||
 | 
					        data = VirtualMachineTemplateSerializer(templates, many=True).data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            'hosting': HOSTING,
 | 
					            'hosting': HOSTING,
 | 
				
			||||||
            'configuration_detail': configuration_detail,
 | 
					 | 
				
			||||||
            'hosting_long': "Ruby On Rails",
 | 
					            'hosting_long': "Ruby On Rails",
 | 
				
			||||||
            'domain': "rails-hosting.ch",
 | 
					            'domain': "rails-hosting.ch",
 | 
				
			||||||
            'google_analytics': "UA-62285904-5",
 | 
					            'google_analytics': "UA-62285904-5",
 | 
				
			||||||
            'email': "info@rails-hosting.ch",
 | 
					            'email': "info@rails-hosting.ch",
 | 
				
			||||||
            'vm_types': VirtualMachineType.get_serialized_vm_types(),
 | 
					            'vm_types': data,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -91,15 +97,18 @@ class NodeJSHostingView(ProcessVMSelectionMixin, View):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_context_data(self, **kwargs):
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
        HOSTING = 'nodejs'
 | 
					        HOSTING = 'nodejs'
 | 
				
			||||||
        configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
 | 
					        # configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING)
 | 
				
			||||||
 | 
					        templates = OpenNebulaManager().get_templates()
 | 
				
			||||||
 | 
					        data = VirtualMachineTemplateSerializer(templates, many=True).data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            'hosting': "nodejs",
 | 
					            'hosting': HOSTING,
 | 
				
			||||||
            'hosting_long': "NodeJS",
 | 
					            'hosting_long': "NodeJS",
 | 
				
			||||||
            'configuration_detail': configuration_detail,
 | 
					            # 'configuration_detail': configuration_detail,
 | 
				
			||||||
            'domain': "node-hosting.ch",
 | 
					            'domain': "node-hosting.ch",
 | 
				
			||||||
            'google_analytics': "UA-62285904-7",
 | 
					            'google_analytics': "UA-62285904-7",
 | 
				
			||||||
            'email': "info@node-hosting.ch",
 | 
					            'email': "info@node-hosting.ch",
 | 
				
			||||||
            'vm_types': VirtualMachineType.get_serialized_vm_types(),
 | 
					            'vm_types': data,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,11 +123,14 @@ class HostingPricingView(ProcessVMSelectionMixin, View):
 | 
				
			||||||
    template_name = "hosting/hosting_pricing.html"
 | 
					    template_name = "hosting/hosting_pricing.html"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_context_data(self, **kwargs):
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
        configuration_options = dict(VirtualMachinePlan.VM_CONFIGURATION)
 | 
					        # configuration_options = dict(VirtualMachinePlan.VM_CONFIGURATION)
 | 
				
			||||||
 | 
					        templates = OpenNebulaManager().get_templates()
 | 
				
			||||||
 | 
					        data = VirtualMachineTemplateSerializer(templates, many=True).data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            'configuration_options': configuration_options,
 | 
					            # 'configuration_options': configuration_options,
 | 
				
			||||||
            'email': "info@django-hosting.ch",
 | 
					            'email': "info@django-hosting.ch",
 | 
				
			||||||
            'vm_types': VirtualMachineType.get_serialized_vm_types(),
 | 
					            'vm_types': data,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
| 
						 | 
					@ -134,13 +146,17 @@ class IndexView(View):
 | 
				
			||||||
    template_name = "hosting/index.html"
 | 
					    template_name = "hosting/index.html"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_context_data(self, **kwargs):
 | 
					    def get_context_data(self, **kwargs):
 | 
				
			||||||
 | 
					        templates = OpenNebulaManager().get_templates()
 | 
				
			||||||
 | 
					        data = VirtualMachineTemplateSerializer(templates, many=True).data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        context = {
 | 
					        context = {
 | 
				
			||||||
            'hosting': "nodejs",
 | 
					            'hosting': "nodejs",
 | 
				
			||||||
            'hosting_long': "NodeJS",
 | 
					            'hosting_long': "NodeJS",
 | 
				
			||||||
            'domain': "node-hosting.ch",
 | 
					            'domain': "node-hosting.ch",
 | 
				
			||||||
            'google_analytics': "UA-62285904-7",
 | 
					            'google_analytics': "UA-62285904-7",
 | 
				
			||||||
            'email': "info@node-hosting.ch",
 | 
					            'email': "info@node-hosting.ch",
 | 
				
			||||||
            'vm_types': VirtualMachineType.get_serialized_vm_types(),
 | 
					            'vm_types': data
 | 
				
			||||||
 | 
					            # 'vm_types': VirtualMachineType.get_serialized_vm_types(),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return context
 | 
					        return context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue