def view( self, request, status ): orders = [] # place orders in orders app because it is not related with a particular shop (view all orders for current user). shops = Shop.objects.filter( user = request.user ) order_details = OrderDetail.objects.filter( status = status, shop__in = shops ) if request.method == 'POST': action = request.REQUEST[ 'action' ] order_id = request.REQUEST[ 'order_id' ] order_detail = OrderDetail.objects.get( id = order_id ) if action == 'delete': order_detail.delete() elif action == 'change-status': new_status = request.REQUEST[ 'status' ] order_detail.status = new_status order_detail.save() for order_detail in order_details: order_product_counts = OrderProductCount.objects.filter( order_detail = order_detail ) order = Order.get( order_product_counts, order_detail ) orders.append( order ) req = request.REQUEST page = int( req[ 'page' ] ) if 'page' in req else 1 page_orders = ItemPage.get_by_items_list( orders, int( page ) ) return super( OrdersView, self ).view( request, { 'page_orders': page_orders, 'status': status, 'page': page } )
def view(self, request): req = request.REQUEST page = int(req["page"]) if "page" in req else 1 items = UserWishList.objects.filter(users=request.user).order_by("-id") wish_list = ItemPage.get_by_items_list(items, int(page)) return super(MyView, self).view(request, {"wish_list": wish_list, "page": page})
def _view(self_obj, request): req = request.REQUEST page = int(req["page"]) if "page" in req else 1 if request.user.is_authenticated(): items = UserWishList.objects.filter(~Q(users=request.user)).order_by("-id") else: items = UserWishList.objects.all().order_by("-id") wish_list = ItemPage.get_by_items_list(items, int(page)) return super(cls, self_obj).view(request, {"wish_list": wish_list, "page": page})
def view( self, request ): req = request.REQUEST page = int( req[ 'page' ] ) if 'page' in req else 1 opt = req[ 'opt' ] if 'opt' in req else 'all' order_by = None if opt == 'new': items = UserProfile.objects.filter( thumbnail__isnull = False, register_dt__gte = datetime.now() - timedelta( days = 14 ) ).order_by( '-register_dt' ) elif opt == 'last-visit-24-hours': ids = User.objects.filter( last_login__gte = datetime.now() - timedelta( days = 1 ) ).order_by( '-last_login' ).values_list( 'pk' ) items = UserProfile.objects.filter( user__in = ids, thumbnail__isnull = False ) else: items = UserProfile.objects.filter( thumbnail__isnull = False ) page_profiles = ItemPage.get_by_items_list( items, int( page ) ) return super( ListView, self ).view( request, { 'page_profiles': page_profiles, 'page': page, 'opt': opt } )
def view( self, request, shop_name ): Location( request.session, 'shop' ).set( get_shop_location( shop_name, 'cart', request.GET ) ) req = request.REQUEST cart = Cart( request.session ) if request.method == 'POST': cart.remove_item( req[ 'product_id' ] ) page = int( req[ 'page' ] ) if 'page' in req else 1 delivery_cost = get_shop_by_name( request.session, shop_name ).delivery_cost page_products = ItemPage.get_by_items_list( items_list = cart.get(), page = page ) return super( CartView, self ).view( request, shop_name, { 'page_products': page_products, 'is_cart_empty': len( page_products[ 'object_list' ] ) == 0, 'page': int( page ), 'num_products_on_page': NUM_ITEMS_ON_PAGE, 'sum': cart.get_sum_price() + delivery_cost } )