forked from uncloud/uncloud
75 lines
3.2 KiB
Python
75 lines
3.2 KiB
Python
from django.core.management.base import BaseCommand
|
|
from app.models import *
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Add test data'
|
|
|
|
# def add_arguments(self, parser):
|
|
#parser.add_argument('--username', type=str, required=True)
|
|
|
|
def handle(self, *args, **options):
|
|
currency, created = Currency.objects.get_or_create(defaults=
|
|
{
|
|
"slug": "CHF",
|
|
"name": "Swiss Franc",
|
|
"short_name": "CHF"
|
|
})
|
|
for timeframe in [ (3600, "1 hour", "1-hour"),
|
|
(86400, "1 day", "1-day"),
|
|
(7*86400, "7 days", "7-days"),
|
|
(30*86400, "30 days", "30-days"),
|
|
(365*86400, "365 days", "365 days") ]:
|
|
TimeFrame.objects.get_or_create(slug=timeframe[2],
|
|
defaults=
|
|
{
|
|
"name": timeframe[1],
|
|
"seconds": timeframe[0]
|
|
})
|
|
|
|
for ppt in [
|
|
("1-day", 1, currency),
|
|
("1-day", 2, currency),
|
|
("30-days", 10, currency), # Nextcloud
|
|
("30-days", 15, currency), # Gitea
|
|
("30-days", 35, currency), # Matrix
|
|
("30-days", 29, currency),
|
|
("30-days", 55, currency) ]:
|
|
tf = TimeFrame.objects.get(slug=ppt[0])
|
|
|
|
PricePerTime.objects.get_or_create(timeframe=tf,
|
|
value=ppt[1],
|
|
defaults=
|
|
{
|
|
"currency": currency
|
|
})
|
|
|
|
for res in [
|
|
("cpu-1", "CPU", "Core(s)", None, None),
|
|
("cpu-min-max", "CPU", "Core(s)", 1, 20),
|
|
("ram-1", "RAM", "GB", None, None),
|
|
("ram-min-max", "RAM", "GB", 1, 200),
|
|
("matrix-maintenance", "Matrix Maintenance Fee", "", 1, 1),
|
|
("nextcloud-maintenance", "Nextcloud Maintenance Fee", "", 1, 1),
|
|
("gitea-maintenance", "Gitea Maintenance Fee", "", 1, 1),
|
|
|
|
]:
|
|
Resource.objects.get_or_create(slug=res[0],
|
|
defaults=
|
|
{
|
|
"name": res[1],
|
|
"unit": res[2],
|
|
"minimum_units": res[3],
|
|
"maximum_units": res[4]
|
|
})
|
|
# Link to PPT -- later
|
|
# for ppt_res in res[5]:
|
|
# ppt = PricePerTime.objects.get(
|
|
|
|
|
|
for product in [
|
|
("matrix", "Matrix"),
|
|
("nextcloud", "Nextcloud"),
|
|
("gitea", "Gitea") ]:
|
|
Product.objects.get_or_create(slug=product[0],
|
|
defaults = { "name": product[1] })
|