Pass context params to various landing templates

This commit is contained in:
PCoder 2018-04-15 21:03:31 +02:00
parent 957cec00a0
commit 23bd0fa147

View file

@ -19,11 +19,11 @@ from hosting.models import HostingOrder
from membership.models import CustomUser, StripeCustomer from membership.models import CustomUser, StripeCustomer
from opennebula_api.serializers import VMTemplateSerializer from opennebula_api.serializers import VMTemplateSerializer
from utils.forms import BillingAddressForm, BillingAddressFormSignup 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.stripe_utils import StripeUtils
from utils.tasks import send_plain_email_task from utils.tasks import send_plain_email_task
from .forms import ContactForm from .forms import ContactForm
from .models import VMTemplate from .models import VMTemplate, VMPricing
from .utils import get_cms_integration from .utils import get_cms_integration
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -93,7 +93,8 @@ class IndexView(CreateView):
@cache_control(no_cache=True, must_revalidate=True, no_store=True) @cache_control(no_cache=True, must_revalidate=True, no_store=True)
def get(self, request, *args, **kwargs): 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: if session_var in request.session:
del request.session[session_var] del request.session[session_var]
return HttpResponseRedirect(reverse('datacenterlight:cms_index')) return HttpResponseRedirect(reverse('datacenterlight:cms_index'))
@ -106,13 +107,30 @@ class IndexView(CreateView):
storage = request.POST.get('storage') storage = request.POST.get('storage')
storage_field = forms.IntegerField(validators=[self.validate_storage]) storage_field = forms.IntegerField(validators=[self.validate_storage])
template_id = int(request.POST.get('config')) 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( template = VMTemplate.objects.filter(
opennebula_vm_template_id=template_id opennebula_vm_template_id=template_id
).first() ).first()
template_data = VMTemplateSerializer(template).data template_data = VMTemplateSerializer(template).data
referer_url = request.META['HTTP_REFERER'] 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: try:
cores = cores_field.clean(cores) cores = cores_field.clean(cores)
except ValidationError as err: except ValidationError as err:
@ -140,7 +158,7 @@ class IndexView(CreateView):
) )
return HttpResponseRedirect(referer_url + "#order_form") 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, cpu=cores,
memory=memory, memory=memory,
disk_size=storage, disk_size=storage,
@ -150,7 +168,10 @@ class IndexView(CreateView):
'cpu': cores, 'cpu': cores,
'memory': memory, 'memory': memory,
'disk_size': storage, '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['specs'] = specs
request.session['template'] = template_data request.session['template'] = template_data
@ -224,7 +245,10 @@ class PaymentOrderView(FormView):
'site_url': reverse('datacenterlight:index'), 'site_url': reverse('datacenterlight:index'),
'login_form': HostingUserLoginForm(prefix='login_form'), 'login_form': HostingUserLoginForm(prefix='login_form'),
'billing_address_form': billing_address_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 return context
@ -493,7 +517,7 @@ class OrderConfirmationView(DetailView):
stripe_subscription_obj.id, card_details_dict) stripe_subscription_obj.id, card_details_dict)
for session_var in ['specs', 'template', 'billing_address', for session_var in ['specs', 'template', 'billing_address',
'billing_address_data', 'billing_address_data',
'token', 'customer']: 'token', 'customer', 'pricing_name']:
if session_var in request.session: if session_var in request.session:
del request.session[session_var] del request.session[session_var]