def get(self, request): if not request.user.is_super: return HttpResponse('你不是管理员...') # 查询订单信息,并分页 order_list = models.Order.objects.filter(seller=request.user) param = self.request.GET.copy() now_num = param.get('page') page_view = page(order_list.count(), request.path, url_params=param, now_page=now_num, each_count=5) order_list = order_list.order_by( 'is_deliver', 'is_pay')[page_view.start():page_view.end()].values( 'customer__username', 'goods__name', 'goods__goodsimg__img', 'goods__price', 'count', 'is_pay', 'pay', 'is_deliver', 'end_address', 'pk', 'order_time', 'goods__price', 'is_collect') pay_choices = models.Order.pay_choices for item in order_list: if item.get('pay'): item['pay'] = pay_choices[item['pay'] - 1][1] else: item['pay'] = '未付款' return render( request, 'index/super_order_list.html', { 'order_list': order_list, 'pay_choices': models.Order.pay_choices, 'page': page_view.page_option() })
def get(self, request): # 浏览商品 goods_list = models.Goods.objects.all() param = self.request.GET.copy() now_num = param.get('page') page_view = page(goods_list.count(), request.path, url_params=param, now_page=now_num, each_count=5) goods_list = goods_list[page_view.start():page_view.end()].values( 'pk', 'name', 'price') return render(request, 'index/super_goods_list.html', { 'goodslist': goods_list, 'page': page_view.page_option() })
def get(self, request): # 显示评论列表 comm_list = models.Comment.objects.all() param = self.request.GET.copy() now_num = param.get('page') page_view = page(comm_list.count(), request.path, url_params=param, now_page=now_num, each_count=5) comm_list = comm_list[page_view.start():page_view.end()].values( 'goods__name', 'pk', 'text', 'create_time', 'user__username') return render(request, 'index/super_comment_list.html', { 'comm_list': comm_list, 'page': page_view.page_option() })
def get(self, request): ''' 显示用户 :param request: :return: ''' userlist = models.UserInfo.objects.filter(is_super=False).all() param = self.request.GET.copy() now_num = param.get('page') page_view = page(userlist.count(), request.path, url_params=param, now_page=now_num, each_count=5) userlist = userlist[page_view.start():page_view.end()].values( 'pk', 'username', 'address', 'email', 'phone') return render(request, 'index/super_user_list.html', { 'userlist': userlist, 'page': page_view.page_option() })
def get(self, request): comm_list = models.Comment.objects.filter(user=request.user) # 获取分页信息 param = self.request.GET.copy() now_num = param.get('page') page_view = page(comm_list.count(), request.path, url_params=param, now_page=now_num, each_count=5) cart_list = models.ShoppingCart.objects.filter(user=request.user) comm_list = comm_list[page_view.start():page_view.end()].values( 'goods__name', 'pk', 'text', 'create_time') return render( request, 'index/user_center_comm.html', { 'comm_list': comm_list, 'shopping_car_count': len(cart_list), 'page': page_view.page_option() })
def get(self, request): # 查看订单信息 orders = models.Order.objects.filter( customer=request.user).order_by('is_pay') # 获取分页信息 param = self.request.GET.copy() now_num = param.get('page') page_view = page(orders.count(), request.path, url_params=param, now_page=now_num, each_count=2) cart_list = models.ShoppingCart.objects.filter(user=request.user) orders_list = orders[page_view.start():page_view.end()].values( 'order_time', 'pk', 'is_pay', 'count', 'goods__goodsimg__img', 'goods__price', 'goods__name', 'pay', 'is_deliver', 'is_collect') return render( request, 'index/user_center_order.html', { 'orders_list': orders_list, 'shopping_car_count': len(cart_list), 'page': page_view.page_option() })
def post(self, request): res = {'code': None, 'msg': None} article_id = request.POST.get('article_id') obj = models.Comment.objects.filter(goods_id=article_id).order_by('pk') # 获取分页信息 param = self.request.POST.copy() now_num = param.get('page') page_view = page(obj.count(), request.path, now_page=now_num, each_count=3) orders_list = list(obj[page_view.start():page_view.end()].values_list( 'pk', 'goods', 'user__username', 'text', 'create_time', 'parent_comment')) if int(now_num) * 3 > obj.count(): now_page = obj.count() // 3 else: now_page = page_view.now_page return JsonResponse({'data': orders_list, 'page': now_page})
def get(self, request): price_flag = None f = '' param = self.request.GET.copy() # 默认按钮 d = self.request.GET.copy() d['order'] = '' d = d.urlencode() data = request.GET # 获取用户要查看的商品列别 c = data.get('class') # 获取用户搜索的商品名称 search = data.get('goods_name') # 获取用户要的排列方式 order = data.get('order') if c: # 判断用户是否提交商品类别 如果提交了 则按照类别来显示 goods_list = models.Goods.objects.filter(goodsclass_id=c).values( 'pk', 'name', 'price', 'stock', 'goodsimg__img', 'goods_details', 'goodsclass', 'goodsclass__title') if search: # 判断用户是否提交商品名称 如果提交了 则按照名称来显示 goods_list = models.Goods.objects.filter( name__contains=search).values('pk', 'name', 'price', 'stock', 'goodsimg__img', 'goods_details', 'goodsclass', 'goodsclass__title') if not c and not search: # 如果没有类别 也没有名称,那么默认显示全部商品 goods_list = models.Goods.objects.all().values( 'pk', 'name', 'price', 'stock', 'goodsimg__img', 'goods_details', 'goodsclass', 'goodsclass__title') if order == '1' or order == 1: # 排序方式,如果为1 价格升序 如果为0 价格降序 price_flag = 'active' f = '^' param['order'] = 0 goods_list = goods_list.order_by('price') order = '0' elif order == '0' or order == 0: f = 'ˇ' param['order'] = 1 price_flag = 'active' goods_list = goods_list.order_by('-price') order = '1' # 获取所有商品,用来随机显示新品推荐 goods_all = models.Goods.objects.all().values('pk', 'name', 'goodsimg__img', 'goods_details', 'goodsclass__title', 'price') if c: # 再次判断用户是否有提交类别,如果有按照类别来随机显示新品推荐 goods_all = goods_all.filter(goodsclass_id=c) # 获取商品类别,用户页面显示 goodsclass = models.GoodsClass.objects.all() shopping_car = [] # 如果用户登录了,那么获取购书车信息 if request.user.is_authenticated: shopping_car = models.ShoppingCart.objects.filter( user=request.user) # 获取分页信息 now_num = param.get('page') page_view = page(goods_list.count(), request.path, url_params=param, now_page=now_num, each_count=15) goods_list = goods_list[page_view.start():page_view.end()] goods_c = goods_all # 显示新品推荐 if len(goods_all) > 2: goods_c = [i for i in goods_all] goods_c = random.sample(goods_c, 2) url_p = param.urlencode() return render( request, 'index/list.html', { 'd': d, 'f': f, 'price_flag': price_flag, 'goods_list': goods_list, 'goodsclass': goodsclass, 'shopping_car_count': len(shopping_car), 'page': page_view.page_option(), 'goods_c': goods_c, 'order': order, 'p': url_p })