frontend price calculator
This commit is contained in:
parent
4f9a39fd36
commit
475a4643fd
4 changed files with 617 additions and 64 deletions
|
@ -1,9 +1,11 @@
|
|||
import re
|
||||
import yaml
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.template.loader import render_to_string
|
||||
from hub.services.models import (
|
||||
ServiceOffering,
|
||||
|
@ -17,6 +19,17 @@ from collections import defaultdict
|
|||
from markdownify import markdownify
|
||||
|
||||
|
||||
def decimal_to_float(obj):
|
||||
"""Convert Decimal objects to float for JSON serialization"""
|
||||
if isinstance(obj, Decimal):
|
||||
return float(obj)
|
||||
elif isinstance(obj, dict):
|
||||
return {key: decimal_to_float(value) for key, value in obj.items()}
|
||||
elif isinstance(obj, list):
|
||||
return [decimal_to_float(item) for item in obj]
|
||||
return obj
|
||||
|
||||
|
||||
def natural_sort_key(name):
|
||||
"""Extract numeric part from compute plan name for natural sorting"""
|
||||
match = re.search(r"compute-std-(\d+)", name)
|
||||
|
@ -84,6 +97,17 @@ def offering_detail(request, provider_slug, service_slug):
|
|||
service__slug=service_slug,
|
||||
)
|
||||
|
||||
# Check if JSON pricing data is requested
|
||||
if request.GET.get("pricing") == "json":
|
||||
pricing_data = None
|
||||
if offering.msp == "VS":
|
||||
pricing_data = generate_pricing_data(offering)
|
||||
if pricing_data:
|
||||
# Convert Decimal objects to float for JSON serialization
|
||||
pricing_data = decimal_to_float(pricing_data)
|
||||
|
||||
return JsonResponse(pricing_data or {})
|
||||
|
||||
# Check if Exoscale marketplace YAML is requested
|
||||
if request.GET.get("exo_marketplace") == "true":
|
||||
return generate_exoscale_marketplace_yaml(offering)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue