|
|
|
@ -9,12 +9,15 @@ class Command(BaseCommand):
|
|
|
|
|
#parser.add_argument('--username', type=str, required=True)
|
|
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
|
# Add CHF as currency
|
|
|
|
|
currency, created = Currency.objects.get_or_create(defaults=
|
|
|
|
|
{
|
|
|
|
|
"slug": "CHF",
|
|
|
|
|
"name": "Swiss Franc",
|
|
|
|
|
"short_name": "CHF"
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
# Add standard timeframes
|
|
|
|
|
for timeframe in [ (3600, "1 hour", "1-hour"),
|
|
|
|
|
(86400, "1 day", "1-day"),
|
|
|
|
|
(7*86400, "7 days", "7-days"),
|
|
|
|
@ -27,9 +30,16 @@ class Command(BaseCommand):
|
|
|
|
|
"seconds": timeframe[0]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
tf_30d = TimeFrame.objects.get(slug='30-days')
|
|
|
|
|
|
|
|
|
|
# Add typical prices per timeframe
|
|
|
|
|
for ppt in [
|
|
|
|
|
("1-day", 1, currency),
|
|
|
|
|
("1-day", 2, currency),
|
|
|
|
|
("30-days", 2, currency), # HDD 100 GB
|
|
|
|
|
("30-days", 3, currency), # CPU
|
|
|
|
|
("30-days", 3.5, currency), # SSD Storage
|
|
|
|
|
("30-days", 4, currency), # RAM
|
|
|
|
|
("30-days", 10, currency), # Nextcloud
|
|
|
|
|
("30-days", 15, currency), # Gitea
|
|
|
|
|
("30-days", 35, currency), # Matrix
|
|
|
|
@ -44,32 +54,57 @@ class Command(BaseCommand):
|
|
|
|
|
"currency": currency
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
# Add typical resources
|
|
|
|
|
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),
|
|
|
|
|
# slug name description min max step-size price per 30days
|
|
|
|
|
("cpu-1", "CPU", "Core(s)", None, None, 0.5, 3),
|
|
|
|
|
("cpu-min-max", "CPU", "Core(s)", 1, 20, 0.5, 3),
|
|
|
|
|
("ram-1", "RAM", "GB", None, None, 0.5, 4),
|
|
|
|
|
("ram-min-max", "RAM", "GB", 1, 200, 0.5, 4),
|
|
|
|
|
("storage-db", "Database-Storage", "GB", 10, None, 10, 3.5),
|
|
|
|
|
("storage-ssd", "SSD-Storage", "GB", 10, None, 10, 3.5),
|
|
|
|
|
("storage-hdd", "HDD-Storage", "GB", 100, None, 100, 2),
|
|
|
|
|
("matrix-maintenance", "Matrix Maintenance Fee", "", 1, 1, None, 35),
|
|
|
|
|
("nextcloud-maintenance", "Nextcloud Maintenance Fee", "", 1, 1, None, 10),
|
|
|
|
|
("gitea-maintenance", "Gitea Maintenance Fee", "", 1, 1, None, 15),
|
|
|
|
|
|
|
|
|
|
]:
|
|
|
|
|
Resource.objects.get_or_create(slug=res[0],
|
|
|
|
|
this_res, created = Resource.objects.get_or_create(slug=res[0],
|
|
|
|
|
defaults=
|
|
|
|
|
{
|
|
|
|
|
"name": res[1],
|
|
|
|
|
"unit": res[2],
|
|
|
|
|
"minimum_units": res[3],
|
|
|
|
|
"maximum_units": res[4]
|
|
|
|
|
"maximum_units": res[4],
|
|
|
|
|
"step_size": res[5]
|
|
|
|
|
})
|
|
|
|
|
# If price is given, assign it
|
|
|
|
|
if res[6]:
|
|
|
|
|
ppt = PricePerTime.objects.get(timeframe=tf_30d, value=res[6])
|
|
|
|
|
this_res.price_per_time.add(ppt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Link resources to prices per time frame
|
|
|
|
|
|
|
|
|
|
# Link to PPT -- later
|
|
|
|
|
# for ppt_res in res[5]:
|
|
|
|
|
# ppt = PricePerTime.objects.get(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Add test products
|
|
|
|
|
for product in [
|
|
|
|
|
("matrix", "Matrix"),
|
|
|
|
|
("nextcloud", "Nextcloud"),
|
|
|
|
|
("gitea", "Gitea") ]:
|
|
|
|
|
Product.objects.get_or_create(slug=product[0],
|
|
|
|
|
p, created = Product.objects.get_or_create(slug=product[0],
|
|
|
|
|
defaults = { "name": product[1] })
|
|
|
|
|
|
|
|
|
|
for req_res in [ "cpu-min-max",
|
|
|
|
|
"ram-min-max",
|
|
|
|
|
"storage-db",
|
|
|
|
|
"storage-hdd" ]:
|
|
|
|
|
print(f"Adding {req_res} to {p}")
|
|
|
|
|
p.resources.add(Resource.objects.get(slug=req_res))
|
|
|
|
|
|
|
|
|
|
p.resources.add(Resource.objects.get(slug=f"{product[0]}-maintenance"))
|
|
|
|
|
# Every test product can be bought for the 30d timeframe
|
|
|
|
|
p.timeframes.add(tf_30d)
|
|
|
|
|