Пример #1
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))
Пример #2
0
 def __get__(self, request, obj_type=None):
     if not hasattr(request, '_cached_buy_list'):
         request._cached_buy_list = BuyList.get(request=request)
     return request._cached_buy_list