from .exceptions import FieldError logger = logging.getLogger(__name__) Product = get_model("catalogue", "Product") Range = get_model("offer", "Range") ProductAttributeValue = get_model("catalogue", "ProductAttributeValue") ProductImage = get_model("catalogue", "ProductImage") Option = get_model("catalogue", "Option") Partner = get_model("partner", "Partner") ProductClass = get_model("catalogue", "ProductClass") ProductAttribute = get_model("catalogue", "ProductAttribute") Category = get_model("catalogue", "Category") AttributeOption = get_model("catalogue", "AttributeOption") AttributeOptionGroup = get_model("catalogue", "AttributeOptionGroup") AttributeValueField, CategoryField, SingleValueSlugRelatedField = get_api_classes( # pylint: disable=unbalanced-tuple-unpacking "serializers.fields", ["AttributeValueField", "CategoryField", "SingleValueSlugRelatedField"], ) StockRecordSerializer = get_api_class("serializers.basket", "StockRecordSerializer") class AttributeOptionGroupSerializer(OscarHyperlinkedModelSerializer): url = serializers.HyperlinkedIdentityField( view_name="admin-attributeoptiongroup-detail") options = SingleValueSlugRelatedField( many=True, required=True, slug_field="option", queryset=AttributeOption.objects.get_queryset(), )
from oscarapi.utils.loading import get_api_classes, get_api_class create_from_breadcrumbs = get_class("catalogue.categories", "create_from_breadcrumbs") Selector = get_class("partner.strategy", "Selector") ( CategorySerializer, ProductLinkSerializer, ProductSerializer, AvailabilitySerializer, ) = get_api_classes( "serializers.product", [ "CategorySerializer", "ProductLinkSerializer", "ProductSerializer", "AvailabilitySerializer", ], ) PriceSerializer = get_api_class("serializers.checkout", "PriceSerializer") __all__ = ("ProductList", "ProductDetail", "ProductPrice", "ProductAvailability") Product = get_model("catalogue", "Product") Category = get_model("catalogue", "Category") class ProductList(generics.ListAPIView):
from .exceptions import FieldError logger = logging.getLogger(__name__) Product = get_model("catalogue", "Product") Range = get_model("offer", "Range") ProductAttributeValue = get_model("catalogue", "ProductAttributeValue") ProductImage = get_model("catalogue", "ProductImage") Option = get_model("catalogue", "Option") Partner = get_model("partner", "Partner") ProductClass = get_model("catalogue", "ProductClass") ProductAttribute = get_model("catalogue", "ProductAttribute") Category = get_model("catalogue", "Category") AttributeOption = get_model("catalogue", "AttributeOption") AttributeOptionGroup = get_model("catalogue", "AttributeOptionGroup") AttributeValueField, CategoryField, SingleValueSlugRelatedField = get_api_classes( "serializers.fields", ["AttributeValueField", "CategoryField", "SingleValueSlugRelatedField"], ) StockRecordSerializer = get_api_class("serializers.basket", "StockRecordSerializer") class AttributeOptionGroupSerializer(OscarHyperlinkedModelSerializer): url = serializers.HyperlinkedIdentityField( view_name="admin-attributeoptiongroup-detail") options = SingleValueSlugRelatedField( many=True, required=True, slug_field="option", queryset=AttributeOption.objects.get_queryset(), )
'OrderTotalCalculator') ShippingAddress = get_model('order', 'ShippingAddress') BillingAddress = get_model('order', 'BillingAddress') Order = get_model('order', 'Order') OrderLine = get_model('order', 'Line') OrderLineAttribute = get_model('order', 'LineAttribute') Basket = get_model('basket', 'Basket') Country = get_model('address', 'Country') Repository = get_class('shipping.repository', 'Repository') UserAddress = get_model('address', 'UserAddress') VoucherSerializer, OfferDiscountSerializer = get_api_classes( "serializers.basket", [ "VoucherSerializer", "OfferDiscountSerializer" ] ) class PriceSerializer(serializers.Serializer): currency = serializers.CharField( max_length=12, default=settings.OSCAR_DEFAULT_CURRENCY, required=False) excl_tax = serializers.DecimalField( decimal_places=2, max_digits=12, required=True) incl_tax = TaxIncludedDecimalField( excl_tax_field='excl_tax', decimal_places=2, max_digits=12, required=False) tax = TaxIncludedDecimalField( excl_tax_value='0.00', decimal_places=2, max_digits=12, required=False)
from rest_framework import serializers from oscarapi.utils.loading import get_api_classes OrderSerializer, OrderLineSerializer, OrderLineAttributeSerializer = get_api_classes( # pylint: disable=unbalanced-tuple-unpacking "serializers.checkout", ["OrderSerializer", "OrderLineSerializer", "OrderLineAttributeSerializer"], ) class AdminOrderSerializer(OrderSerializer): url = serializers.HyperlinkedIdentityField(view_name='admin-order-detail') lines = serializers.HyperlinkedIdentityField( view_name='admin-order-lines-list') class AdminOrderLineAttributeSerializer(OrderLineAttributeSerializer): url = serializers.HyperlinkedIdentityField( view_name='admin-order-lineattributes-detail') class AdminOrderLineSerializer(OrderLineSerializer): url = serializers.HyperlinkedIdentityField( view_name='admin-order-lines-detail') attributes = AdminOrderLineAttributeSerializer(many=True, fields=('url', 'option', 'value'), required=False)
from oscarapi.utils.loading import get_api_classes, get_api_class from oscarapi.utils.models import fake_autocreated create_from_breadcrumbs = get_class("catalogue.categories", "create_from_breadcrumbs") Product = get_model("catalogue", "Product") ProductClass = get_model("catalogue", "ProductClass") ProductAttributeValue = get_model("catalogue", "ProductAttributeValue") Option = get_model("catalogue", "Option") StockRecordSerializer = get_api_class("serializers.basket", "StockRecordSerializer") BaseProductSerializer, BaseCategorySerializer, ProductImageSerializer, ProductAttributeSerializer, OptionSerializer = get_api_classes( # pylint: disable=unbalanced-tuple-unpacking "serializers.product", [ "BaseProductSerializer", "BaseCategorySerializer", "ProductImageSerializer", "ProductAttributeSerializer", "OptionSerializer", ], ) class AdminProductSerializer(BaseProductSerializer): url = serializers.HyperlinkedIdentityField( view_name="admin-product-detail") stockrecords = StockRecordSerializer(many=True, required=False) images = ProductImageSerializer(many=True, required=False) children = serializers.HyperlinkedRelatedField( view_name="admin-product-detail", many=True, required=False,
from rest_framework import generics from rest_framework.response import Response from oscar.core.loading import get_class, get_model from oscarapi.utils.loading import get_api_classes, get_api_class Selector = get_class('partner.strategy', 'Selector') (ProductLinkSerializer, ProductSerializer, AvailabilitySerializer) = get_api_classes( "serializers.product", ["ProductLinkSerializer", "ProductSerializer", "AvailabilitySerializer"]) PriceSerializer = get_api_class("serializers.checkout", "PriceSerializer") __all__ = ( 'ProductList', 'ProductDetail', 'ProductPrice', 'ProductAvailability', ) Product = get_model('catalogue', 'Product') class ProductList(generics.ListAPIView): queryset = Product.objects.all() serializer_class = ProductLinkSerializer def get_queryset(self): """