def _pre_view( self_obj, request, shop_name, *args, **kwargs ): self_obj._shop = get_shop_by_name( request.session, shop_name ) if self_obj._shop.is_removed: return page403Or404( request ) self_obj._shop_face = ShopFace.objects.get( shop = self_obj._shop ) self_obj._shop_id = get_shop_id_by_name( request.session, shop_name ) return super( cls, self_obj ).pre_view( request, shop_name, *args, **kwargs )
def view( self, request, shop_name, product_id ): req_get = request.GET product = Product.objects.get( id = int( product_id ) ) shop_id = get_shop_id_by_name( request.session, shop_name ) if product.shop.id != shop_id: raise ProductNotInThisShopError( "Product with id {0} not found in shop {1}".format( product_id, self._shop_name ) ) cart = Cart( request.session) in_cart = str( product.id ) in cart.as_dict() location = Location( request.session, 'shop' ) if location.is_set(): back = location.get() else: back = None return super( ProductView, self ).view( request, shop_name, { 'back': back, 'product': product, 'in_cart': in_cart, 'opt': req_get[ 'opt' ] if 'opt' in req_get else None } )