removed redirects form get_context() to get()
This commit is contained in:
parent
2c4390767d
commit
5d8fb71215
1 changed files with 40 additions and 24 deletions
|
@ -652,46 +652,42 @@ class OrdersHostingDetailView(LoginRequiredMixin,
|
||||||
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:
|
|
||||||
return HttpResponseRedirect(
|
|
||||||
reverse('hosting:create_virtual_machine'))
|
|
||||||
if 'token' not in self.request.session:
|
|
||||||
return HttpResponseRedirect(reverse('hosting:payment'))
|
|
||||||
stripe_customer_id = self.request.session.get('customer')
|
stripe_customer_id = self.request.session.get('customer')
|
||||||
customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
|
customer = StripeCustomer.objects.filter(id=stripe_customer_id).first()
|
||||||
stripe_utils = StripeUtils()
|
stripe_utils = StripeUtils()
|
||||||
card_details = stripe_utils.get_card_details(customer.stripe_id,
|
card_details = stripe_utils.get_card_details(
|
||||||
self.request.session.get(
|
customer.stripe_id,
|
||||||
'token'))
|
self.request.session.get('token')
|
||||||
if not card_details.get('response_object'):
|
)
|
||||||
msg = card_details.get('error')
|
|
||||||
messages.add_message(self.request, messages.ERROR, msg,
|
|
||||||
extra_tags='failed_payment')
|
|
||||||
return HttpResponseRedirect(
|
|
||||||
reverse('hosting:payment') + '#payment_error')
|
|
||||||
|
|
||||||
if self.request.GET.get('page', '') == 'payment':
|
if self.request.GET.get('page') == 'payment':
|
||||||
context['page_header_text'] = _('Confirm Order')
|
context['page_header_text'] = _('Confirm Order')
|
||||||
else:
|
else:
|
||||||
context['page_header_text'] = _('Invoice')
|
context['page_header_text'] = _('Invoice')
|
||||||
|
|
||||||
if obj is not None:
|
if obj is not None:
|
||||||
try:
|
try:
|
||||||
manager = OpenNebulaManager(email=owner.email,
|
manager = OpenNebulaManager(
|
||||||
password=owner.password)
|
email=owner.email, password=owner.password
|
||||||
|
)
|
||||||
vm = manager.get_vm(obj.vm_id)
|
vm = manager.get_vm(obj.vm_id)
|
||||||
context['vm'] = VirtualMachineSerializer(vm).data
|
context['vm'] = VirtualMachineSerializer(vm).data
|
||||||
except WrongIdError:
|
except WrongIdError:
|
||||||
messages.error(self.request,
|
messages.error(
|
||||||
'The VM you are looking for is unavailable at the moment. \
|
self.request,
|
||||||
Please contact Data Center Light support.'
|
'The VM you are looking for is unavailable at the moment. \
|
||||||
)
|
Please contact Data Center Light support.'
|
||||||
|
)
|
||||||
self.kwargs['error'] = 'WrongIdError'
|
self.kwargs['error'] = 'WrongIdError'
|
||||||
context['error'] = 'WrongIdError'
|
context['error'] = 'WrongIdError'
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
messages.error(self.request,
|
messages.error(
|
||||||
'In order to create a VM, you need to create/upload your SSH KEY first.'
|
self.request,
|
||||||
)
|
'In order to create a VM, you need to create/upload your SSH KEY first.'
|
||||||
|
)
|
||||||
|
elif not card_details.get('response_object'):
|
||||||
|
context['failed_payment'] = True
|
||||||
|
context['card_details'] = card_details
|
||||||
else:
|
else:
|
||||||
context['site_url'] = reverse('hosting:create_virtual_machine')
|
context['site_url'] = reverse('hosting:create_virtual_machine')
|
||||||
context['cc_last4'] = card_details.get('response_object').get(
|
context['cc_last4'] = card_details.get('response_object').get(
|
||||||
|
@ -701,6 +697,26 @@ class OrdersHostingDetailView(LoginRequiredMixin,
|
||||||
context['vm'] = self.request.session.get('specs')
|
context['vm'] = self.request.session.get('specs')
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
if 'specs' not in self.request.session:
|
||||||
|
return HttpResponseRedirect(
|
||||||
|
reverse('hosting:create_virtual_machine')
|
||||||
|
)
|
||||||
|
if 'token' not in self.request.session:
|
||||||
|
return HttpResponseRedirect(reverse('hosting:payment'))
|
||||||
|
self.object = self.get_object()
|
||||||
|
context = self.get_context_data(object=self.object)
|
||||||
|
if 'failed_payment' in context:
|
||||||
|
msg = context['card_details'].get('error')
|
||||||
|
messages.add_message(
|
||||||
|
self.request, messages.ERROR, msg,
|
||||||
|
extra_tags='failed_payment'
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect(
|
||||||
|
reverse('hosting:payment') + '#payment_error'
|
||||||
|
)
|
||||||
|
return self.render_to_response(context)
|
||||||
|
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
template = request.session.get('template')
|
template = request.session.get('template')
|
||||||
specs = request.session.get('specs')
|
specs = request.session.get('specs')
|
||||||
|
|
Loading…
Reference in a new issue