Beispiel #1
0
def cart(request):
    cart = TradeCart.get(request)
    cart_items = cart.items.all()

    if request.method == 'POST':
        for item in cart_items:
            q = str2int(request.POST.get('i-%d' % item.id))
            if q:
                item.quantity = q
                item.save()
            else:
                item.delete()
        cart._recalc_size()
        cart.save()
        if not request.is_ajax():
            return redirect(reverse('trade:address'))


    total_amount = sum([item.quantity * item.user_session_price for item in cart_items])
    ctx = {
        'cart': cart,
        'cart_items': cart.get_items(),
        'total_quantity': cart.size,
        'total_amount': total_amount,
    }
    if request.is_ajax():
        return render_to_response('trade/partials/cart_grid.html', ctx, RequestContext(request))
    return ctx
Beispiel #2
0
def print_sl(request):
    profile = request.user.get_profile()
    cart = TradeCart.get(request)

    if not cart.size:
        if not settings.DEBUG:
            return redirect(reverse('trade:cart'))
        else:
            order = (TradeOrder.objects.filter(user=request.user) or (None, ))[0]
            if not order:
                return redirect(reverse('trade:cart'))
    else:
        if not profile.has_shipping_address():
            return redirect(reverse('trade:address'))
        if ('trade_postal_carrier' not in request.session) or (request.session['trade_postal_carrier'] not in POSTAL_CARRIERS):
            return redirect(reverse('trade:carrier'))

        order = TradeOrder.create(request, cart)

    try:
        order.send_order_confirmation()
    except Exception, e:
        debug(e)
Beispiel #3
0
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()],
    }
Beispiel #4
0
 def __get__(self, request, obj_type=None):
     if not hasattr(request, '_cached_trade_cart'):
         request._cached_trade_cart = TradeCart.get(request)
     return request._cached_cart
Beispiel #5
0
def add(request, id):
    item = get_object_or_404(Item, id=id)
    if not request.is_ajax():
        return redirect(item.get_absolute_url())

    if request.method == 'POST':
        dest_wizard = False
        form = AddItemCompletenessForm(request.POST)
        if form.is_valid():
            is_complete = form.cleaned_data['completeness'] == 'cg'

            is_valid_choice = True
            if not is_complete:
                if not request.user.is_authenticated():
                    is_valid_choice = False
                elif not request.user.get_profile().has_game_perks():
                    is_valid_choice = False

            if is_valid_choice:
                if request.POST.get('submit') == 'list':
                    # add to list
                    TradeListItem.add(request, item, is_complete)
                    if request.user.is_authenticated():
                        return JsonResponse({'redirect_to': reverse('trade:list')})
                    else:
                        request.session['entry_point'] = ProfileEntryPoint.Trade
                        return JsonResponse({'goto_url': reverse('members:create_account')})
                else:
                    # add to cart
                    if not item.trade_flag:
                        return redirect(item.get_absolute_url())
                    cart = TradeCart.get(request)
                    cart.push_item(request, item, inc_quantity=1, is_complete=is_complete)
                    if request.user.is_authenticated():
                        dest = reverse('trade:cart')
                    else:
                        request.session['entry_point'] = ProfileEntryPoint.Trade
                        return JsonResponse({'goto_url': reverse('members:create_account')})
#                        dest_wizard = True
#                        dest = reverse('trade:login')

                template = 'trade/check_upc.html'
                form = CheckUPCForm()
            else:
                template = 'trade/add.dialog.html'
                dest = None
        else:
            template = 'trade/add.dialog.html'
            dest = None

        ctx = {
            'form': form,
            'item': item,
            'dest': dest,
            'dest_wizard': dest_wizard,
        }

        res = {}
        res['form'] = loader.render_to_string(template, ctx, RequestContext(request))
        return JsonResponse(res)

    form = AddItemCompletenessForm()
    return render_to_response('trade/add.dialog.html',
                          {'form': form, 'item': item, },
                          context_instance=RequestContext(request))