Ejemplo n.º 1
0
class DomainPricesSerializer(serializers.Serializer):
    default_currency = CurrencySerializer(read_only=True)
    price_types = serializers.DictField()
    price_cycles_list = PriceCyclesSerializer(many=True)
    price_cycles_by_currency = serializers.SerializerMethodField()
    price_cycles_by_type = serializers.SerializerMethodField()
    default_price_cycles = serializers.SerializerMethodField()

    @staticmethod
    def get_default_price_cycles(instance):
        default_price_cycles = {}
        for (index, price_cycles) in enumerate(instance.price_cycles_list):
            if price_cycles.currency.is_default:
                default_price_cycles[price_cycles.price_type] = index
        return default_price_cycles

    @staticmethod
    def get_price_cycles_by_currency(instance):
        price_cycles_by_currency = OrderedDict()
        for currency in Currency.objects.order_by('-is_default').all():
            price_cycles_by_currency[currency.code] = OrderedDict()
            price_cycles_by_currency[currency.code][PriceType.register] = None
            price_cycles_by_currency[currency.code][PriceType.transfer] = None
            price_cycles_by_currency[currency.code][PriceType.renew] = None

        for index, price_cycles in enumerate(instance.price_cycles_list):
            price_cycles_by_currency[price_cycles.currency.code][price_cycles.price_type] = index

        return price_cycles_by_currency

    @staticmethod
    def get_price_cycles_by_type(instance):
        price_cycles_by_type = OrderedDict()
        price_cycles_by_type[PriceType.register] = OrderedDict()
        price_cycles_by_type[PriceType.transfer] = OrderedDict()
        price_cycles_by_type[PriceType.renew] = OrderedDict()
        for currency in Currency.objects.order_by('-is_default').all():
            price_cycles_by_type[PriceType.register][currency.code] = None
            price_cycles_by_type[PriceType.transfer][currency.code] = None
            price_cycles_by_type[PriceType.renew][currency.code] = None

        for index, price_cycles in enumerate(instance.price_cycles_list):
            price_cycles_by_type[price_cycles.price_type][price_cycles.currency.code] = index

        return price_cycles_by_type

    def update(self, instance, validated_data):
        pass

    def create(self, validated_data):
        pass

    def save_prices(self, tld: TLD):
        price_cycles_list = self.validated_data['price_cycles_list']
        price_cycles_object_list = [PriceCycles(**price_cycles) for price_cycles in price_cycles_list]
        tld.save_prices(price_cycles_object_list)
Ejemplo n.º 2
0
class AdminPricingPlanCreateOptionsSerializer(serializers.Serializer):
    currencies = CurrencySerializer(many=True, read_only=True)
    non_default_plans = AdminPricingPlanMinSerializer(many=True,
                                                      read_only=True)

    def update(self, instance, validated_data):
        pass

    def create(self, validated_data):
        pass
Ejemplo n.º 3
0
 def create_options(self, request):
     options = dict()
     options['products'] = [{
         'id': pack.id,
         'name': pack.name,
         'description': pack.description
     } for pack in Product.objects.all()]
     if not options['products']:
         raise ObjectNotFound('No products exist')
     options['cycles'] = CyclePeriods.choices
     options['currencies'] = CurrencySerializer(
         instance=Currency.objects.all(), many=True).data
     if not options['currencies']:
         raise ObjectNotFound('No currencies exist')
     options['statuses'] = PublicStatuses.choices
     return Response({'create_options': options})
Ejemplo n.º 4
0
class AddonPriceCyclesSerializer(serializers.Serializer):
    currency = CurrencySerializer(read_only=True)
    price_type = serializers.CharField()
    price_type_display = serializers.SerializerMethodField()
    prices_per_years = serializers.ListField()
    currency_code = serializers.CharField()
    relative_prices = serializers.BooleanField()

    @staticmethod
    def get_price_type_display(instance):
        return AddonPriceType.price_type_map[instance.price_type]

    def create(self, validated_data):
        pass

    def update(self, instance, validated_data):
        pass
Ejemplo n.º 5
0
 def get_client_currency(obj):
     return CurrencySerializer().to_representation(
         instance=obj.active_service.client.currency)