def core(request): result = {} if not request.user.is_authenticated(): result['login_form'] = AuthenticationByEmailForm.create(request) result['sigup_form'] = SignupForm(request) lists_size = request.buy_list.count() + \ RentList.get(request=request).count() + \ TradeListItem.get(request).count() result['lists_size'] = lists_size return result
def _trade_action(request): if request.is_ajax(): from project.members.context_processors import core list = TradeListItem.get(request) context = { 'trade_list': list, 'trade_list_total': sum([item.get_price() for item in list]) } res = { 'trade_list': { 'size': list.count(), }, 'lists_size': core(request)['lists_size'], 'html': render_to_string('members/lists/trade_list_grid.html', context, RequestContext(request)), } return JsonResponse(res) return redirect('trade:list')
def rent_list(request): rent_plan = MemberRentalPlan.get_current_plan(request.user) rent_list = RentList.get(request=request) if request.user.is_authenticated(): rent_orders = RentOrder.objects.filter(user=request.user).order_by('-id') rent_orders = rent_orders.filter(status__in=[RentOrderStatus.Pending, RentOrderStatus.Prepared, RentOrderStatus.Shipped]) rent_orders = rent_orders.filter(list_item=None) else: rent_orders = None return { 'buy_list': request.buy_list, 'trade_list': TradeListItem.get(request), 'rent_plan': rent_plan, 'rent_list': rent_list, 'rent_orders': rent_orders, 'pending_credits': request.user.get_profile().get_pending_credits(), 'banners': [ListPageBanner.objects.get_random()], }
def buy_list(request): if request.method == 'POST': # add to cart cart = BuyCart.get(request) for item in request.buy_list: if ('item-%d' % item.id) in request.POST: cart.push_item(request, item.item, inc_quantity=1, is_new=item.is_new) item.delete() return redirect(reverse('cart:index')) date_x = datetime.now() - timedelta(30) buy_orders = BuyOrder.objects.filter(user=request.user, create_date__gt=date_x).exclude(status=BuyOrderStatus.Canceled) if request.user.is_authenticated() else None return { 'buy_list': request.buy_list, 'buy_orders': buy_orders, 'trade_list': TradeListItem.get(request), 'rent_list': RentList.get(request=request), 'pending_credits': request.user.get_profile().get_pending_credits(), 'banners': [ListPageBanner.objects.get_random()], }
def list(request): trade_list = TradeListItem.get(request) trade_list_total = sum([item.get_price() for item in trade_list]) if request.method == 'POST': # add to cart cart = TradeCart.get(request) for item in trade_list: if ('item-%d' % item.id) in request.POST: cart.push_item(request, item.item, inc_quantity=1, is_complete=item.is_complete) item.delete() return redirect(reverse('trade:cart')) orders = TradeOrder.objects.filter(user=request.user).extra(where=["exists(select * from trade_tradeorderitem where order_id=trade_tradeorder.id and processed='f')"]) return { 'buy_list': request.buy_list, 'rent_list': RentList.get(request.user, request), 'trade_orders': orders, 'trade_list': trade_list, 'trade_list_total': trade_list_total, 'pending_credits': request.user.get_profile().get_pending_credits(), 'banners': [ListPageBanner.objects.get_random()], }