| 
									
										
										
										
											2018-04-12 08:03:12 +02:00
										 |  |  | import logging | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-20 18:05:20 -05:00
										 |  |  | from django.db import models | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-12 08:03:12 +02:00
										 |  |  | logger = logging.getLogger(__name__) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 23:34:06 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-26 19:38:38 +02:00
										 |  |  | class VMTemplate(models.Model): | 
					
						
							| 
									
										
										
										
											2018-05-24 03:57:01 +05:30
										 |  |  |     PUBLIC = 'public' | 
					
						
							|  |  |  |     IPV6 = 'ipv6only' | 
					
						
							|  |  |  |     VM_TYPE_CHOICES = ( | 
					
						
							|  |  |  |         (PUBLIC, PUBLIC.title()), | 
					
						
							|  |  |  |         (IPV6, IPV6.title()), | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2017-07-26 19:38:38 +02:00
										 |  |  |     name = models.CharField(max_length=50) | 
					
						
							| 
									
										
										
										
											2017-07-26 20:35:12 +02:00
										 |  |  |     opennebula_vm_template_id = models.IntegerField() | 
					
						
							| 
									
										
										
										
											2018-05-24 03:57:01 +05:30
										 |  |  |     vm_type = models.CharField( | 
					
						
							|  |  |  |         max_length=50, choices=VM_TYPE_CHOICES, default=PUBLIC | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __str__(self): | 
					
						
							|  |  |  |         return '%s - %s - %s' % ( | 
					
						
							|  |  |  |             self.opennebula_vm_template_id, self.vm_type, self.name | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-07-26 19:38:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							| 
									
										
										
										
											2018-05-24 03:57:01 +05:30
										 |  |  |     def create(cls, name, opennebula_vm_template_id, vm_type): | 
					
						
							| 
									
										
										
										
											2017-08-27 13:19:05 +05:30
										 |  |  |         vm_template = cls( | 
					
						
							| 
									
										
										
										
											2018-05-24 03:57:01 +05:30
										 |  |  |             name=name, opennebula_vm_template_id=opennebula_vm_template_id, | 
					
						
							|  |  |  |             vm_type=vm_type | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2017-07-26 19:38:38 +02:00
										 |  |  |         return vm_template | 
					
						
							| 
									
										
										
										
											2017-08-17 04:22:23 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-06 00:51:44 +02:00
										 |  |  | class VMPricing(models.Model): | 
					
						
							|  |  |  |     name = models.CharField(max_length=255, unique=True) | 
					
						
							|  |  |  |     vat_inclusive = models.BooleanField(default=True) | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |     vat_percentage = models.DecimalField( | 
					
						
							| 
									
										
										
										
											2018-04-15 23:07:50 +02:00
										 |  |  |         max_digits=7, decimal_places=5, blank=True, default=0 | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  |     cores_unit_price = models.DecimalField( | 
					
						
							| 
									
										
										
										
											2018-04-15 23:07:50 +02:00
										 |  |  |         max_digits=7, decimal_places=5, default=0 | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  |     ram_unit_price = models.DecimalField( | 
					
						
							| 
									
										
										
										
											2018-04-15 23:07:50 +02:00
										 |  |  |         max_digits=7, decimal_places=5, default=0 | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  |     ssd_unit_price = models.DecimalField( | 
					
						
							| 
									
										
										
										
											2018-04-15 23:07:50 +02:00
										 |  |  |         max_digits=7, decimal_places=5, default=0 | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  |     hdd_unit_price = models.DecimalField( | 
					
						
							| 
									
										
										
										
											2018-04-15 23:07:50 +02:00
										 |  |  |         max_digits=7, decimal_places=6, default=0 | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-05-07 05:07:58 +05:30
										 |  |  |     discount_name = models.CharField(max_length=255, null=True, blank=True) | 
					
						
							|  |  |  |     discount_amount = models.DecimalField( | 
					
						
							| 
									
										
										
										
											2018-05-07 06:11:44 +05:30
										 |  |  |         max_digits=6, decimal_places=2, default=0 | 
					
						
							| 
									
										
										
										
											2018-05-07 05:07:58 +05:30
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-04-06 00:51:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def __str__(self): | 
					
						
							| 
									
										
										
										
											2018-05-07 06:11:44 +05:30
										 |  |  |         display_str = self.name + ' => ' + ' - '.join([ | 
					
						
							| 
									
										
										
										
											2018-04-16 00:50:34 +02:00
										 |  |  |             '{}/Core'.format(self.cores_unit_price.normalize()), | 
					
						
							|  |  |  |             '{}/GB RAM'.format(self.ram_unit_price.normalize()), | 
					
						
							|  |  |  |             '{}/GB SSD'.format(self.ssd_unit_price.normalize()), | 
					
						
							|  |  |  |             '{}/GB HDD'.format(self.hdd_unit_price.normalize()), | 
					
						
							|  |  |  |             '{}% VAT'.format(self.vat_percentage.normalize()) | 
					
						
							| 
									
										
										
										
											2018-05-07 05:07:58 +05:30
										 |  |  |             if not self.vat_inclusive else 'VAT-Incl', | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2018-05-07 06:11:44 +05:30
										 |  |  |         if self.discount_amount: | 
					
						
							|  |  |  |             display_str = ' - '.join([ | 
					
						
							|  |  |  |                 display_str, | 
					
						
							|  |  |  |                 '{} {}'.format( | 
					
						
							|  |  |  |                     self.discount_amount, | 
					
						
							|  |  |  |                     self.discount_name if self.discount_name else 'Discount' | 
					
						
							|  |  |  |                 ) | 
					
						
							|  |  |  |             ]) | 
					
						
							|  |  |  |         return display_str | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-15 20:55:39 +02:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def get_vm_pricing_by_name(cls, name): | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             pricing = VMPricing.objects.get(name=name) | 
					
						
							|  |  |  |         except Exception as e: | 
					
						
							|  |  |  |             logger.error( | 
					
						
							|  |  |  |                 "Error getting VMPricing with name {name}. " | 
					
						
							| 
									
										
										
										
											2018-04-16 00:29:43 +02:00
										 |  |  |                 "Details: {details}. Attempting to return default" | 
					
						
							|  |  |  |                 "pricing.".format(name=name, details=str(e)) | 
					
						
							| 
									
										
										
										
											2018-04-15 20:55:39 +02:00
										 |  |  |             ) | 
					
						
							|  |  |  |             pricing = VMPricing.get_default_pricing() | 
					
						
							|  |  |  |         return pricing | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def get_default_pricing(cls): | 
					
						
							|  |  |  |         """ Returns the default pricing or None """ | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             default_pricing = VMPricing.objects.get(name='default') | 
					
						
							| 
									
										
										
										
											2018-04-12 08:03:12 +02:00
										 |  |  |         except Exception as e: | 
					
						
							|  |  |  |             logger.error(str(e)) | 
					
						
							| 
									
										
										
										
											2018-04-09 21:17:48 +02:00
										 |  |  |             default_pricing = None | 
					
						
							|  |  |  |         return default_pricing | 
					
						
							| 
									
										
										
										
											2018-04-06 00:51:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-17 04:22:23 +05:30
										 |  |  | class StripePlan(models.Model): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     A model to store Data Center Light's created Stripe plans | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2017-08-22 01:55:45 +05:30
										 |  |  |     stripe_plan_id = models.CharField(max_length=256, null=True) | 
					
						
							| 
									
										
										
										
											2019-04-20 11:53:47 +02:00
										 |  |  |     stripe_plan_name = models.CharField(max_length=512, default="", null=True) | 
					
						
							| 
									
										
										
										
											2019-04-20 12:22:49 +02:00
										 |  |  |     amount = models.PositiveIntegerField(default=0) | 
					
						
							|  |  |  |     interval = models.CharField(max_length=128, default="", null=True) | 
					
						
							| 
									
										
										
										
											2017-08-17 04:22:23 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def create(cls, stripe_plan_id): | 
					
						
							|  |  |  |         stripe_plan = cls(stripe_plan_id=stripe_plan_id) | 
					
						
							|  |  |  |         return stripe_plan | 
					
						
							| 
									
										
										
										
											2017-08-27 13:19:05 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ContactUs(models.Model): | 
					
						
							|  |  |  |     name = models.CharField(max_length=250) | 
					
						
							|  |  |  |     email = models.CharField(max_length=250) | 
					
						
							|  |  |  |     message = models.TextField() | 
					
						
							|  |  |  |     field = models.DateTimeField(auto_now_add=True) | 
					
						
							| 
									
										
										
										
											2018-02-28 04:09:19 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     def __str__(self): | 
					
						
							|  |  |  |         return self.name |