Ejemplo n.º 1
0
Archivo: views.py Proyecto: scotfu/M
def loginview(request):
    if request.method == 'POST':
        form=LoginForm(request.POST)
        session_cart=getCart(request)
        try:
            next= request.POST['next']
        except:
            next='/'
        if form.is_valid():
            username=form.cleaned_data['username']
            password=form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    login(request, user)
                    user_cart=getCart(request)
                    cartMerge(user_cart, session_cart)
                    request.session['cart']={}
                    return HttpResponseRedirect(next)
    else:
        if '_auth_user_id' in request.session:
            return HttpResponseRedirect('/')
        else:
            form=LoginForm()
            try:
                next= request.GET['next']
            except:
                next='/'
    return render_to_response('login_form.html',
            {'form': form,
            'next': next},
             context_instance=RequestContext(request))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: scotfu/M
def order(request):
    cart=getCart(request)
    user=request.user
    item_set=cart.cartitem_set.all()
#检查contains_digital
    is_only_digital=only_digital(item_set)
    if item_set.count()>0:
        price=0
        if is_only_digital:
            order=Order.objects.create(user=user,
                 is_only_digital=is_only_digital, address_id=0,
                 price=price, finished=True, finished_date=datetime.now())
        else:
            try:
                address=Address.objects.filter(user=user,
                    pk=request.GET['address_id'])[0]
            except:
                address=Address.objects.filter(user=user)[0]
            order=Order.objects.create(user=user, address=address,
            is_only_digital=is_only_digital, price=price)
# 对接购物车和订单
# 检查数量
        for item in item_set:
            amount=item.amount
            if amount<item.album.amount:
                detail=OrderDetail.objects.create(order=order,
                album=item.album,
                amount=amount,
                per_price=item.album.price)
                price+=detail.get_total_price()
            else:
                pass
        order.price=price
        order.save()
        cleanCart(request)
        return HttpResponseRedirect('/order/my_order/')
    else:
        raise Http404