hosting: Overriden get_object method in OrderHostingDetail and cleared

session on completion of creation of VM
This commit is contained in:
M.Ravi 2017-09-09 13:27:17 +02:00
parent c8baf3d4c1
commit e135bc9e8c
2 changed files with 19 additions and 4 deletions

View file

@ -1,6 +1,8 @@
{% extends "hosting/base_short.html" %} {% extends "hosting/base_short.html" %}
{% load staticfiles bootstrap3 %} {% load staticfiles bootstrap3 %}
{% load i18n %} {% load i18n %}
{% load custom_tags %}
{% block content %} {% block content %}
<div class="order-detail-container"> <div class="order-detail-container">

View file

@ -582,12 +582,16 @@ class OrdersHostingDetailView(PermissionRequiredMixin, LoginRequiredMixin,
permission_required = ['view_hostingorder'] permission_required = ['view_hostingorder']
model = HostingOrder model = HostingOrder
def get_object(self):
return HostingOrder.objects.filter(
pk=self.kwargs.get('pk')) if self.kwargs.get('pk') else None
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
# Get context # Get context
context = super(DetailView, self).get_context_data(**kwargs) context = super(DetailView, self).get_context_data(**kwargs)
obj = self.get_object() obj = self.get_object()
owner = self.request.user owner = self.request.user
if 'specs' not in self.request.session or 'user' not in self.request.session: if 'specs' not in self.request.session:
return HttpResponseRedirect( return HttpResponseRedirect(
reverse('hosting:create_virtual_machine')) reverse('hosting:create_virtual_machine'))
if 'token' not in self.request.session: if 'token' not in self.request.session:
@ -610,7 +614,7 @@ class OrdersHostingDetailView(PermissionRequiredMixin, LoginRequiredMixin,
else: else:
context['page_header_text'] = _('Invoice') context['page_header_text'] = _('Invoice')
if obj.vm_id: if obj is not None:
try: try:
manager = OpenNebulaManager(email=owner.email, manager = OpenNebulaManager(email=owner.email,
password=owner.password) password=owner.password)
@ -695,8 +699,17 @@ class OrdersHostingDetailView(PermissionRequiredMixin, LoginRequiredMixin,
stripe_customer_id, billing_address_data, stripe_customer_id, billing_address_data,
billing_address_id, billing_address_id,
stripe_subscription_obj, card_details_dict) stripe_subscription_obj, card_details_dict)
request.session['order_confirmation'] = True
return HttpResponseRedirect(reverse('hosting:my-virtual-machines')) for session_var in ['specs', 'template', 'billing_address',
'billing_address_data',
'token', 'customer']:
if session_var in request.session:
del request.session[session_var]
messages.success(self.request,
"{first_line}".format(
first_line=_(
"Thank you for order! Our team will contact you via email")))
return HttpResponseRedirect(reverse('hosting:virtual_machines'))
class OrdersHostingListView(LoginRequiredMixin, ListView): class OrdersHostingListView(LoginRequiredMixin, ListView):