Move django-based uncloud to top-level
This commit is contained in:
parent
0560063326
commit
95d43f002f
265 changed files with 0 additions and 0 deletions
60
uncloud_service/serializers.py
Normal file
60
uncloud_service/serializers.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
from rest_framework import serializers
|
||||
from .models import *
|
||||
from uncloud_vm.serializers import ManagedVMProductSerializer
|
||||
from uncloud_vm.models import VMProduct
|
||||
from uncloud_pay.models import RecurringPeriod, BillingAddress
|
||||
|
||||
# XXX: the OrderSomethingSomthingProductSerializer classes add a lot of
|
||||
# boilerplate: can we reduce it somehow?
|
||||
|
||||
class MatrixServiceProductSerializer(serializers.ModelSerializer):
|
||||
vm = ManagedVMProductSerializer()
|
||||
|
||||
class Meta:
|
||||
model = MatrixServiceProduct
|
||||
fields = ['uuid', 'order', 'owner', 'status', 'vm', 'domain',
|
||||
'recurring_period']
|
||||
read_only_fields = ['uuid', 'order', 'owner', 'status']
|
||||
|
||||
class OrderMatrixServiceProductSerializer(MatrixServiceProductSerializer):
|
||||
recurring_period = serializers.ChoiceField(
|
||||
choices=MatrixServiceProduct.allowed_recurring_periods())
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(OrderMatrixServiceProductSerializer, self).__init__(*args, **kwargs)
|
||||
self.fields['billing_address'] = serializers.ChoiceField(
|
||||
choices=BillingAddress.get_addresses_for(
|
||||
self.context['request'].user)
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = MatrixServiceProductSerializer.Meta.model
|
||||
fields = MatrixServiceProductSerializer.Meta.fields + [
|
||||
'recurring_period', 'billing_address'
|
||||
]
|
||||
read_only_fields = MatrixServiceProductSerializer.Meta.read_only_fields
|
||||
|
||||
class GenericServiceProductSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = GenericServiceProduct
|
||||
fields = ['uuid', 'order', 'owner', 'status', 'custom_recurring_price',
|
||||
'custom_description', 'custom_one_time_price']
|
||||
read_only_fields = ['uuid', 'order', 'owner', 'status']
|
||||
|
||||
class OrderGenericServiceProductSerializer(GenericServiceProductSerializer):
|
||||
recurring_period = serializers.ChoiceField(
|
||||
choices=GenericServiceProduct.allowed_recurring_periods())
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(OrderGenericServiceProductSerializer, self).__init__(*args, **kwargs)
|
||||
self.fields['billing_address'] = serializers.ChoiceField(
|
||||
choices=BillingAddress.get_addresses_for(
|
||||
self.context['request'].user)
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = GenericServiceProductSerializer.Meta.model
|
||||
fields = GenericServiceProductSerializer.Meta.fields + [
|
||||
'recurring_period', 'billing_address'
|
||||
]
|
||||
read_only_fields = GenericServiceProductSerializer.Meta.read_only_fields
|
||||
Loading…
Add table
Add a link
Reference in a new issue