Pass context params to various landing templates
This commit is contained in:
		
					parent
					
						
							
								957cec00a0
							
						
					
				
			
			
				commit
				
					
						23bd0fa147
					
				
			
		
					 1 changed files with 32 additions and 8 deletions
				
			
		|  | @ -19,11 +19,11 @@ from hosting.models import HostingOrder | |||
| from membership.models import CustomUser, StripeCustomer | ||||
| from opennebula_api.serializers import VMTemplateSerializer | ||||
| from utils.forms import BillingAddressForm, BillingAddressFormSignup | ||||
| from utils.hosting_utils import get_vm_price | ||||
| from utils.hosting_utils import get_vm_price, get_vm_price_with_vat | ||||
| from utils.stripe_utils import StripeUtils | ||||
| from utils.tasks import send_plain_email_task | ||||
| from .forms import ContactForm | ||||
| from .models import VMTemplate | ||||
| from .models import VMTemplate, VMPricing | ||||
| from .utils import get_cms_integration | ||||
| 
 | ||||
| logger = logging.getLogger(__name__) | ||||
|  | @ -93,7 +93,8 @@ class IndexView(CreateView): | |||
| 
 | ||||
|     @cache_control(no_cache=True, must_revalidate=True, no_store=True) | ||||
|     def get(self, request, *args, **kwargs): | ||||
|         for session_var in ['specs', 'user', 'billing_address_data']: | ||||
|         for session_var in ['specs', 'user', 'billing_address_data', | ||||
|                             'pricing_name']: | ||||
|             if session_var in request.session: | ||||
|                 del request.session[session_var] | ||||
|         return HttpResponseRedirect(reverse('datacenterlight:cms_index')) | ||||
|  | @ -106,13 +107,30 @@ class IndexView(CreateView): | |||
|         storage = request.POST.get('storage') | ||||
|         storage_field = forms.IntegerField(validators=[self.validate_storage]) | ||||
|         template_id = int(request.POST.get('config')) | ||||
|         vm_pricing_name = request.POST.get('pricing_name') | ||||
|         pricing_name = request.POST.get('pricing_name') | ||||
|         vm_pricing = VMPricing.get_vm_pricing_by_name(pricing_name) | ||||
| 
 | ||||
|         template = VMTemplate.objects.filter( | ||||
|             opennebula_vm_template_id=template_id | ||||
|         ).first() | ||||
|         template_data = VMTemplateSerializer(template).data | ||||
|         referer_url = request.META['HTTP_REFERER'] | ||||
| 
 | ||||
|         if vm_pricing is None: | ||||
|             vm_pricing_name_msg = _( | ||||
|                 "Incorrect pricing name. Please contact support" | ||||
|                 "{support_email}".format( | ||||
|                     support_email=settings.DCL_SUPPORT_FROM_ADDRESS | ||||
|                 ) | ||||
|             ) | ||||
|             messages.add_message( | ||||
|                 self.request, messages.ERROR, vm_pricing_name_msg, | ||||
|                 extra_tags='pricing' | ||||
|             ) | ||||
|             return HttpResponseRedirect(referer_url + "#order_form") | ||||
|         else: | ||||
|             vm_pricing_name = vm_pricing.name | ||||
| 
 | ||||
|         try: | ||||
|             cores = cores_field.clean(cores) | ||||
|         except ValidationError as err: | ||||
|  | @ -140,7 +158,7 @@ class IndexView(CreateView): | |||
|             ) | ||||
|             return HttpResponseRedirect(referer_url + "#order_form") | ||||
| 
 | ||||
|         amount_to_be_charged = get_vm_price( | ||||
|         amount_to_be_charged, vat = get_vm_price_with_vat( | ||||
|             cpu=cores, | ||||
|             memory=memory, | ||||
|             disk_size=storage, | ||||
|  | @ -150,7 +168,10 @@ class IndexView(CreateView): | |||
|             'cpu': cores, | ||||
|             'memory': memory, | ||||
|             'disk_size': storage, | ||||
|             'price': amount_to_be_charged | ||||
|             'price': amount_to_be_charged, | ||||
|             'vat': vat, | ||||
|             'total_price': amount_to_be_charged + vat, | ||||
|             'pricing_name': vm_pricing_name | ||||
|         } | ||||
|         request.session['specs'] = specs | ||||
|         request.session['template'] = template_data | ||||
|  | @ -224,7 +245,10 @@ class PaymentOrderView(FormView): | |||
|             'site_url': reverse('datacenterlight:index'), | ||||
|             'login_form': HostingUserLoginForm(prefix='login_form'), | ||||
|             'billing_address_form': billing_address_form, | ||||
|             'cms_integration': get_cms_integration('default') | ||||
|             'cms_integration': get_cms_integration('default'), | ||||
|             'vm_pricing': VMPricing.get_vm_pricing_by_name( | ||||
|                 self.request.session['specs']['pricing_name'] | ||||
|             ) | ||||
|         }) | ||||
|         return context | ||||
| 
 | ||||
|  | @ -493,7 +517,7 @@ class OrderConfirmationView(DetailView): | |||
|                              stripe_subscription_obj.id, card_details_dict) | ||||
|         for session_var in ['specs', 'template', 'billing_address', | ||||
|                             'billing_address_data', | ||||
|                             'token', 'customer']: | ||||
|                             'token', 'customer', 'pricing_name']: | ||||
|             if session_var in request.session: | ||||
|                 del request.session[session_var] | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue