Order = get_model('order', 'Order') OrderLine = get_model('order', 'Line') OrderLineAttribute = get_model('order', 'LineAttribute') __all__ = ('CheckoutView', 'OrderList', 'OrderDetail', 'OrderLineList', 'OrderLineDetail', 'OrderLineAttributeDetail') (OrderSerializer, CheckoutSerializer, OrderLineSerializer, OrderLineAttributeSerializer ) \ = get_api_classes('oscarapi.serializers.checkout', ( 'OrderSerializer', 'CheckoutSerializer', 'OrderLineSerializer', 'OrderLineAttributeSerializer' )) class OrderList(generics.ListAPIView): serializer_class = OrderSerializer permission_classes = (IsOwner, ) def get_queryset(self): qs = Order.objects.all() return qs.filter(user=self.request.user) class OrderDetail(generics.RetrieveAPIView):
Line = get_model('basket', 'Line') Repository = get_class('shipping.repository', 'Repository') # basket serializers (BasketSerializer, BasketLineSerializer, LineSerializer, LineAttributeSerializer, VoucherAddSerializer, VoucherSerializer ) \ = get_api_classes('oscarapi.serializers.basket', ( 'BasketSerializer', 'BasketLineSerializer', 'LineSerializer', 'LineAttributeSerializer', 'VoucherAddSerializer', 'VoucherSerializer' )) # product serializers (ProductSerializer, AddProductSerializer ) \ = get_api_classes('oscarapi.serializers.product', ( 'ProductSerializer', 'AddProductSerializer' ))
api_root = get_api_class('oscarapi.views', 'api_root') # basket views (BasketView, AddProductView, AddVoucherView, shipping_methods, LineList, LineDetail, BasketLineDetail ) \ = get_api_classes('oscarapi.views.basket', ( 'BasketView', 'AddProductView', 'AddVoucherView', 'shipping_methods', 'LineList', 'LineDetail', 'BasketLineDetail' )) # basic views (LineAttributeList, LineAttributeDetail, ProductList, ProductDetail, ProductPrice, ProductAvailability, StockRecordList, StockRecordDetail, OptionList, OptionDetail,
__all__ = ( 'CheckoutView', 'OrderList', 'OrderDetail', 'OrderLineList', 'OrderLineDetail', 'OrderLineAttributeDetail' ) (OrderSerializer, CheckoutSerializer, OrderLineSerializer, OrderLineAttributeSerializer ) \ = get_api_classes('oscarapi.serializers.checkout', ( 'OrderSerializer', 'CheckoutSerializer', 'OrderLineSerializer', 'OrderLineAttributeSerializer' )) class OrderList(generics.ListAPIView): serializer_class = OrderSerializer permission_classes = (IsOwner,) def get_queryset(self): qs = Order.objects.all() return qs.filter(user=self.request.user) class OrderDetail(generics.RetrieveAPIView):
from oscarapi.utils import login_and_upgrade_session from oscarapi.basket import operations from oscar.core.loading import get_model from oscarapi.loading import get_api_classes __all__ = ('LoginView', ) Basket = get_model('basket', 'Basket') (UserSerializer, LoginSerializer ) \ = get_api_classes('oscarapi.serializers.login', ( 'UserSerializer', 'LoginSerializer' )) class LoginView(APIView): """ Api for logging in users. DELETE: Log the user out by destroying the session. Anonymous users will have their cart destroyed as well, because there is no way to reach it anymoore POST(username, password): 1. The user will be authenticated. The next steps will only be
Basket = get_model('basket', 'Basket') LineAttribute = get_model('basket', 'LineAttribute') Product = get_model('catalogue', 'Product') StockRecord = get_model('partner', 'StockRecord') Option = get_model('catalogue', 'Option') User = auth.get_user_model() Country = get_model('address', 'Country') Partner = get_model('partner', 'Partner') # checkout serializers (CountrySerializer, PriceSerializer ) \ = get_api_classes('oscarapi.serializers.checkout', ( 'CountrySerializer', 'PriceSerializer' )) # basket serializers (BasketSerializer, LineAttributeSerializer, StockRecordSerializer ) \ = get_api_classes('oscarapi.serializers.basket', ( 'BasketSerializer', 'LineAttributeSerializer', 'StockRecordSerializer' ))
from oscarapi.utils import login_and_upgrade_session from oscarapi.basket import operations from oscar.core.loading import get_model from oscarapi.loading import get_api_classes __all__ = ('LoginView',) Basket = get_model('basket', 'Basket') (UserSerializer, LoginSerializer ) \ = get_api_classes('oscarapi.serializers.login', ( 'UserSerializer', 'LoginSerializer' )) class LoginView(APIView): """ Api for logging in users. DELETE: Log the user out by destroying the session. Anonymous users will have their cart destroyed as well, because there is no way to reach it anymoore POST(username, password): 1. The user will be authenticated. The next steps will only be
def test_loading_class_defined_in_local_module(self): with override_settings(INSTALLED_APPS=self.installed_apps): (BasketLineSerializer,) = get_api_classes('oscarapi.serializers.basket', ('BasketLineSerializer',)) self.assertEqual('test_apps.apps.oscarapi.serializers.basket', BasketLineSerializer.__module__)
def test_loading_class_from_module_not_defined_in_local_app(self): with override_settings(INSTALLED_APPS=self.installed_apps): (PriceSerializer,) = get_api_classes('oscarapi.serializers.checkout', ('PriceSerializer',)) self.assertEqual('oscarapi.serializers.checkout', PriceSerializer.__module__)
def test_raise_exception_when_bad_appname_used(self): with self.assertRaises(AppNotFoundError): get_api_classes('fridge.models', ('ApiKey', 'ApiKey2'))
def test_load_oscar_classes_correctly(self): HeaderSessionMiddleware, ApiGatewayMiddleWare = get_api_classes('oscarapi.middleware', ('HeaderSessionMiddleware', 'ApiGatewayMiddleWare')) self.assertEqual('oscarapi.middleware', HeaderSessionMiddleware.__module__) self.assertEqual('oscarapi.middleware', ApiGatewayMiddleWare.__module__)