| 
									
										
										
										
											2016-04-22 08:36:38 -05:00
										 |  |  | from django.shortcuts import redirect | 
					
						
							| 
									
										
										
										
											2018-04-07 12:51:40 +02:00
										 |  |  | from django.conf import settings | 
					
						
							| 
									
										
										
										
											2016-04-22 08:36:38 -05:00
										 |  |  | from django.core.urlresolvers import reverse | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-13 00:31:29 -05:00
										 |  |  | from opennebula_api.serializers import VirtualMachineTemplateSerializer | 
					
						
							|  |  |  | from opennebula_api.models import OpenNebulaManager | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-21 22:01:26 -05:00
										 |  |  | from .models import HostingPlan | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-22 08:36:38 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | class ProcessVMSelectionMixin(object): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def post(self, request, *args, **kwargs): | 
					
						
							| 
									
										
										
										
											2017-05-13 00:31:29 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |         template_id = int(request.POST.get('vm_template_id')) | 
					
						
							| 
									
										
										
										
											2017-05-21 22:01:26 -05:00
										 |  |  |         configuration_id = int(request.POST.get('configuration')) | 
					
						
							| 
									
										
										
										
											2017-05-13 00:31:29 -05:00
										 |  |  |         template = OpenNebulaManager().get_template(template_id) | 
					
						
							|  |  |  |         data = VirtualMachineTemplateSerializer(template).data | 
					
						
							| 
									
										
										
										
											2017-05-21 22:01:26 -05:00
										 |  |  |         configuration = HostingPlan.objects.get(id=configuration_id) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-13 00:31:29 -05:00
										 |  |  |         request.session['template'] = data | 
					
						
							| 
									
										
										
										
											2017-05-21 22:01:26 -05:00
										 |  |  |         request.session['specs'] = configuration.serialize() | 
					
						
							| 
									
										
										
										
											2017-05-13 00:31:29 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-22 08:36:38 -05:00
										 |  |  |         if not request.user.is_authenticated(): | 
					
						
							| 
									
										
										
										
											2016-04-30 13:55:55 -05:00
										 |  |  |             request.session['next'] = reverse('hosting:payment') | 
					
						
							| 
									
										
										
										
											2016-04-22 08:36:38 -05:00
										 |  |  |             return redirect(reverse('hosting:login')) | 
					
						
							|  |  |  |         return redirect(reverse('hosting:payment')) | 
					
						
							| 
									
										
										
										
											2018-04-07 12:51:40 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class HostingContextMixin(object): | 
					
						
							|  |  |  |     def get_context_data(self, **kwargs): | 
					
						
							|  |  |  |         context = super().get_context_data(**kwargs) | 
					
						
							|  |  |  |         context['MULTISITE_CMS_FALLBACK'] = settings.MULTISITE_CMS_FALLBACK | 
					
						
							|  |  |  |         return context |