uncloud/uncloud_service/models.py

65 lines
2.0 KiB
Python
Raw Normal View History

import uuid
from django.db import models
2020-04-17 08:08:33 +00:00
from uncloud_pay.models import Product, RecurringPeriod, AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS
from uncloud_vm.models import VMProduct, VMDiskImageProduct
2020-04-17 08:08:33 +00:00
from django.core.validators import MinValueValidator
class MatrixServiceProduct(Product):
monthly_managment_fee = 20
description = "Managed Matrix HomeServer"
# Specific to Matrix-as-a-Service
vm = models.ForeignKey(
VMProduct, on_delete=models.CASCADE
)
domain = models.CharField(max_length=255, default='domain.tld')
# Default recurring price is PER_MONT, see Product class.
def recurring_price(self, recurring_period=RecurringPeriod.PER_30D):
return self.monthly_managment_fee
@staticmethod
def base_image():
# TODO: find a way to safely reference debian 10 image.
return VMDiskImageProduct.objects.get(uuid="93e564c5-adb3-4741-941f-718f76075f02")
2020-03-03 09:51:16 +00:00
@staticmethod
def allowed_recurring_periods():
return list(filter(
lambda pair: pair[0] in [RecurringPeriod.PER_30D],
2020-03-03 09:51:16 +00:00
RecurringPeriod.choices))
@property
def one_time_price(self):
2020-03-03 09:51:16 +00:00
return 30
2020-04-17 08:08:33 +00:00
class GenericServiceProduct(Product):
custom_description = models.TextField()
custom_recurring_price = models.DecimalField(default=0.0,
max_digits=AMOUNT_MAX_DIGITS,
decimal_places=AMOUNT_DECIMALS,
validators=[MinValueValidator(0)])
custom_one_time_price = models.DecimalField(default=0.0,
max_digits=AMOUNT_MAX_DIGITS,
decimal_places=AMOUNT_DECIMALS,
validators=[MinValueValidator(0)])
@property
def recurring_price(self):
# FIXME: handle recurring_period somehow.
2020-04-17 08:08:33 +00:00
return self.custom_recurring_price
@property
def description(self):
return self.custom_description
@property
def one_time_price(self):
return self.custom_one_time_price
@staticmethod
def allowed_recurring_periods():
return RecurringPeriod.choices