Esempio n. 1
0
def update(request, id):
    if not request.is_ajax():
        return redirect('cart:index')
    item = request.cart.items.filter(id=id)
    if item.count() == 0:
        raise Http404()
    item = item[0]

    if request.method == 'POST':
        res = {}
        form = AddItemConditionForm(request.POST)
        if form.is_valid():
            is_new = item.item.is_prereleased_game() or form.cleaned_data['condition'] == 'new'
            item.is_new = is_new
            item.user_session_price = item.item.retail_price_new if is_new else item.item.retail_price_used
            item.save()
            res['redirect_to'] = reverse('cart:index')
        else:
            res['form'] = loader.render_to_string('cart/update-cart.dialog.html',
                                                  {'form': form, 'item': item.item, 'cart_item': item },
                                                  RequestContext(request))
        return JsonResponse(res)


    form = AddItemConditionForm()
    return render_to_response('cart/update-cart.dialog.html',
                          {'form': form, 'item': item.item, 'cart_item': item },
                          context_instance=RequestContext(request))
Esempio n. 2
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':
        submit = request.POST.get('submit', 'cart')
        res = {}
        form = AddItemConditionForm(request.POST)
        if form.is_valid():
            is_new = item.is_prereleased_game() or form.cleaned_data['condition'] == 'new'
            if submit == 'cart':
                request.cart.push_item(request, item, inc_quantity=1, is_new=is_new)
                res['redirect_to'] = reverse('cart:index')
            else:
                buy_alert = submit == 'buy-alert'
                BuyList.add_to_list(request, item, is_new, buy_alert=buy_alert)
                if request.user.is_authenticated():
                    res['redirect_to'] = reverse('members:buy_list')
                else:
                    request.session['entry_point'] = ProfileEntryPoint.Buy
                    res['redirect_to'] = reverse('members:create_account')
        else:
            res['form'] = loader.render_to_string('cart/add.dialog.html',
                                                  {'form': form, 'item': item, },
                                                  RequestContext(request))
        return JsonResponse(res)

    form = AddItemConditionForm()
    return render_to_response('cart/add.dialog.html',
                          {'form': form, 'item': item, 'check_used_by_default': request.GET.get('is_pre_owned'),},
                          context_instance=RequestContext(request))