Added the logic to handle orders manually

This commit is contained in:
M.Ravi 2017-06-06 03:09:34 +05:30
parent d7625712f1
commit b68f116931

View file

@ -7,6 +7,8 @@ from django.core.urlresolvers import reverse_lazy, reverse
from utils.mailer import BaseEmail from utils.mailer import BaseEmail
from django.shortcuts import render from django.shortcuts import render
from django.shortcuts import redirect from django.shortcuts import redirect
from django import forms
from django.core.exceptions import ValidationError
from opennebula_api.models import OpenNebulaManager from opennebula_api.models import OpenNebulaManager
from opennebula_api.serializers import VirtualMachineTemplateSerializer from opennebula_api.serializers import VirtualMachineTemplateSerializer
@ -43,25 +45,59 @@ class PricingView(TemplateView):
memory = request.POST.get('ram') memory = request.POST.get('ram')
storage = request.POST.get('storage') storage = request.POST.get('storage')
price = request.POST.get('total') price = request.POST.get('total')
template_id = int(request.POST.get('config')) template_id = int(request.POST.get('config'))
manager = OpenNebulaManager() manager = OpenNebulaManager()
template = manager.get_template(template_id) vm_template_name = (manager.get_template(template_id)).get_name()
request.session['template'] = VirtualMachineTemplateSerializer(template).data name = request.POST.get('name')
email = request.POST.get('email')
if not request.user.is_authenticated(): name_field = forms.CharField()
request.session['next'] = reverse('hosting:payment') email_field = forms.EmailField()
try:
request.session['specs'] = { name = name_field.clean(name)
'cpu':cores, except ValidationError as err:
'memory': memory, messages.error( request,
'disk_size': storage, '%(value) is not a proper name.'.format(name)
'price': price, )
context = {
'error' : 'name'
} }
return render(request, self.template_name, context)
return redirect(reverse('hosting:payment')) try:
email = email_field.clean(email)
except ValidationError as err:
messages.error( request,
'%(value) is not a proper email.'.format(email)
)
context = {
'error' : 'email'
}
return render(request, self.template_name, context)
# We have valid email and name of the customer, hence send an
# email to the admin
context = {
'name': name,
'email': email,
'cores': cores,
'memory': memory,
'storage': storage,
'price': price,
'template': vm_template_name,
}
email_data = {
'subject': 'New Order Received',
'to': 'info@ungleich.ch',
'context': context,
'template_name': 'new_order_notification',
'template_path': 'datacenterlight/emails/'
}
email = BaseEmail(**email_data)
email.send()
return render(self.request, 'datacenterlight/success.html', {})
class BetaAccessView(FormView): class BetaAccessView(FormView):