merged master
This commit is contained in:
		
				commit
				
					
						6802e2fdbc
					
				
			
		
					 26 changed files with 294 additions and 395 deletions
				
			
		|  | @ -60,8 +60,9 @@ CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a \ | |||
|                     minutes." | ||||
| 
 | ||||
| 
 | ||||
| class DashboardView(View): | ||||
| class DashboardView(LoginRequiredMixin, View): | ||||
|     template_name = "hosting/dashboard.html" | ||||
|     login_url = reverse_lazy('hosting:login') | ||||
| 
 | ||||
|     def get_context_data(self, **kwargs): | ||||
|         context = {} | ||||
|  | @ -80,8 +81,6 @@ class DjangoHostingView(ProcessVMSelectionMixin, View): | |||
|         templates = OpenNebulaManager().get_templates() | ||||
|         data = VirtualMachineTemplateSerializer(templates, many=True).data | ||||
|         configuration_options = HostingPlan.get_serialized_configs() | ||||
| 
 | ||||
|         # configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) | ||||
|         context = { | ||||
|             'hosting': HOSTING, | ||||
|             'hosting_long': "Django", | ||||
|  | @ -134,7 +133,6 @@ class NodeJSHostingView(ProcessVMSelectionMixin, View): | |||
| 
 | ||||
|     def get_context_data(self, **kwargs): | ||||
|         HOSTING = 'nodejs' | ||||
|         # configuration_detail = dict(VirtualMachinePlan.VM_CONFIGURATION).get(HOSTING) | ||||
|         templates = OpenNebulaManager().get_templates() | ||||
|         configuration_options = HostingPlan.get_serialized_configs() | ||||
| 
 | ||||
|  | @ -249,7 +247,8 @@ class SignupValidateView(TemplateView): | |||
|                  <br />{go_back} {hurl}.'.format( | ||||
|             signup_success_message=_( | ||||
|                 'Thank you for signing up. We have sent an email to you. ' | ||||
|                 'Please follow the instructions in it to activate your account. Once activated, you can login using'), | ||||
|                 'Please follow the instructions in it to activate your ' | ||||
|                 'account. Once activated, you can login using'), | ||||
|             go_back=_('Go back to'), | ||||
|             lurl=login_url, | ||||
|             hurl=home_url | ||||
|  | @ -271,7 +270,8 @@ class SignupValidatedView(SignupValidateView): | |||
|         user = CustomUser.objects.filter( | ||||
|             validation_slug=self.kwargs['validate_slug']).first() | ||||
|         if validated: | ||||
|             message = '{account_activation_string} <br /> {login_string} {lurl}.'.format( | ||||
|             message = ('{account_activation_string} <br />' | ||||
|                        ' {login_string} {lurl}.').format( | ||||
|                 account_activation_string=_( | ||||
|                     "Your account has been activated."), | ||||
|                 login_string=_("You can now"), | ||||
|  | @ -653,10 +653,7 @@ class PaymentVMView(LoginRequiredMixin, FormView): | |||
|                 return HttpResponseRedirect( | ||||
|                     reverse('hosting:payment') + '#payment_error') | ||||
| 
 | ||||
|             # Create Billing Address | ||||
|             billing_address = form.save() | ||||
|             request.session['billing_address_data'] = billing_address_data | ||||
|             request.session['billing_address'] = billing_address.id | ||||
|             request.session['token'] = token | ||||
|             request.session['customer'] = customer.id | ||||
|             return HttpResponseRedirect("{url}?{query_params}".format( | ||||
|  | @ -704,7 +701,13 @@ class OrdersHostingDetailView(LoginRequiredMixin, | |||
|             try: | ||||
|                 vm_detail = VMDetail.objects.get(vm_id=obj.vm_id) | ||||
|                 context['vm'] = vm_detail.__dict__ | ||||
|                 context['vm']['name'] = '{}-{}'.format(context['vm']['configuration'], context['vm']['vm_id']) | ||||
|                 context['vm']['name'] = '{}-{}'.format( | ||||
|                     context['vm']['configuration'], context['vm']['vm_id']) | ||||
|                 context['vm']['price'] = get_vm_price( | ||||
|                     cpu=context['vm']['cores'], | ||||
|                     disk_size=context['vm']['disk_size'], | ||||
|                     memory=context['vm']['memory'] | ||||
|                 ) | ||||
|             except VMDetail.DoesNotExist: | ||||
|                 try: | ||||
|                     manager = OpenNebulaManager( | ||||
|  | @ -767,7 +770,6 @@ class OrdersHostingDetailView(LoginRequiredMixin, | |||
|         stripe_customer_id = request.session.get('customer') | ||||
|         customer = StripeCustomer.objects.filter(id=stripe_customer_id).first() | ||||
|         billing_address_data = request.session.get('billing_address_data') | ||||
|         billing_address_id = request.session.get('billing_address') | ||||
|         vm_template_id = template.get('id', 1) | ||||
| 
 | ||||
|         # Make stripe charge to a customer | ||||
|  | @ -785,8 +787,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, | |||
|         cpu = specs.get('cpu') | ||||
|         memory = specs.get('memory') | ||||
|         disk_size = specs.get('disk_size') | ||||
|         amount_to_be_charged = get_vm_price(cpu=cpu, memory=memory, | ||||
|                                             disk_size=disk_size) | ||||
|         amount_to_be_charged = specs.get('price') | ||||
|         plan_name = StripeUtils.get_stripe_plan_name(cpu=cpu, | ||||
|                                                      memory=memory, | ||||
|                                                      disk_size=disk_size) | ||||
|  | @ -805,12 +806,24 @@ class OrdersHostingDetailView(LoginRequiredMixin, | |||
|                 'response_object').stripe_plan_id}]) | ||||
|         stripe_subscription_obj = subscription_result.get('response_object') | ||||
|         # Check if the subscription was approved and is active | ||||
|         if stripe_subscription_obj is None or stripe_subscription_obj.status != 'active': | ||||
|         if (stripe_subscription_obj is None or | ||||
|                 stripe_subscription_obj.status != 'active'): | ||||
|             msg = subscription_result.get('error') | ||||
|             messages.add_message(self.request, messages.ERROR, msg, | ||||
|                                  extra_tags='failed_payment') | ||||
|             return HttpResponseRedirect( | ||||
|                 reverse('hosting:payment') + '#payment_error') | ||||
|             response = { | ||||
|                 'status': False, | ||||
|                 'redirect': "{url}#{section}".format( | ||||
|                     url=reverse('hosting:payment'), | ||||
|                     section='payment_error'), | ||||
|                 'msg_title': str(_('Error.')), | ||||
|                 'msg_body': str( | ||||
|                     _('There was a payment related error.' | ||||
|                       ' On close of this popup, you will be redirected back to' | ||||
|                       ' the payment page.')) | ||||
|             } | ||||
|             return HttpResponse(json.dumps(response), | ||||
|                                 content_type="application/json") | ||||
|         user = { | ||||
|             'name': self.request.user.name, | ||||
|             'email': self.request.user.email, | ||||
|  | @ -821,8 +834,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, | |||
|         } | ||||
|         create_vm_task.delay(vm_template_id, user, specs, template, | ||||
|                              stripe_customer_id, billing_address_data, | ||||
|                              billing_address_id, | ||||
|                              stripe_subscription_obj, card_details_dict) | ||||
|                              stripe_subscription_obj.id, card_details_dict) | ||||
| 
 | ||||
|         for session_var in ['specs', 'template', 'billing_address', | ||||
|                             'billing_address_data', | ||||
|  | @ -1025,6 +1037,7 @@ class VirtualMachineView(LoginRequiredMixin, View): | |||
|                 return redirect(reverse('hosting:virtual_machines')) | ||||
|         elif self.request.is_ajax(): | ||||
|             return HttpResponse() | ||||
|         context = None | ||||
|         try: | ||||
|             serializer = VirtualMachineSerializer(vm) | ||||
|             context = { | ||||
|  | @ -1034,7 +1047,11 @@ class VirtualMachineView(LoginRequiredMixin, View): | |||
|             } | ||||
|         except Exception as ex: | ||||
|             logger.debug("Exception generated {}".format(str(ex))) | ||||
|             pass | ||||
|             messages.error(self.request, | ||||
|                            _('We could not find the requested VM. Please ' | ||||
|                              'contact Data Center Light Support.') | ||||
|                            ) | ||||
|             return redirect(reverse('hosting:virtual_machines')) | ||||
| 
 | ||||
|         return render(request, self.template_name, context) | ||||
| 
 | ||||
|  | @ -1144,3 +1161,15 @@ class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, | |||
|             bill.total_price += vm['price'] | ||||
|         context['vms'] = vms | ||||
|         return context | ||||
| 
 | ||||
| 
 | ||||
| def forbidden_view(request, exception=None, reason=''): | ||||
|     """ | ||||
|     Handle 403 error | ||||
|     """ | ||||
|     logger.error(str(exception) if exception else None) | ||||
|     logger.error('Reason = {reason}'.format(reason=reason)) | ||||
|     err_msg = _('There was an error processing your request. Please try ' | ||||
|                 'again.') | ||||
|     messages.add_message(request, messages.ERROR, err_msg) | ||||
|     return HttpResponseRedirect(request.get_full_path()) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue