Example #1
0
def change_item(request, id):
    filter = {'pk': id}
    if request.user.is_authenticated():
        filter['user'] = request.user
    else:
        filter['session_id'] = request.current_session_id
    list_item = get_object_or_404(TradeListItem, **filter)
    if not request.is_ajax():
        return redirect(list_item.item.get_absolute_url())

    if request.method == 'POST':
        res = {}

        form = AddItemCompletenessForm(request.POST)
        if form.is_valid():
            list_item.is_complete = form.cleaned_data['completeness'] == 'cg'
            list_item.save()
            res['close'] = True
            res['redirect_to'] = reverse('trade:list')
        else:
            res['form'] = loader.render_to_string('trade/change-item.html',
                                                  {'item': list_item.item, 'list_item': list_item, },
                                                  RequestContext(request))
        return JsonResponse(res)

    form = AddItemCompletenessForm()
    return render_to_response('trade/change-item.html',
                              {'item': list_item.item, 'list_item': list_item, },
                              context_instance=RequestContext(request))
Example #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':
        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))