Exemple #1
0
def unbook(request):
    user = request.user
    account = get_object_or_404(Account, name=user.username)
    good = get_object_or_404(Good, name=request.POST['good'])
    if not account.good_set.filter(id=good.id):
        return HttpResponse('<font color="red">你尚未订购,不能退订!</font><br/><a href="/pia/fanfan/gao/profile/">返回控制面板</a>')
    elif datetime.now() > good.deadline - timedelta(0, 3600, 0):
        return HttpResponse('<font color="red">退订时间已过,退订在截止时间前1小时(当天9点)关闭!</font><br/><a href="/pia/fanfan/gao/profile/">返回控制面板</a>')
    else:
        account.good_set.remove(good)
        r = Record(account_from=Account.objects.get(name='admin'),
                   account_to=account,
                   amount=good.price,
                   comment=('unbook: %s' % good))
        r.save()
    return HttpResponseRedirect('/pia/fanfan/gao/profile/')
Exemple #2
0
def book(request):
    user = request.user
    account = get_object_or_404(Account, name=user.username)
    good = get_object_or_404(Good, name=request.POST['good'])
    if account.good_set.filter(id=good.id):
        return HttpResponse('<font color="red">你已经订购,不能重复订购!</font><br/><a href="/pia/fanfan/gao/profile/">返回控制面板</a>')
    elif datetime.now() > good.deadline:
        return HttpResponse('<font color="red">订购时间已过,订购在截至时间后(当天10点)关闭!</font><br/><a href="/pia/fanfan/gao/profile/">返回控制面板</a>')
#    elif account.balance() < good.price:
#        return HttpResponse('<font color="red">余额不足,订购失败!</font><br/><a href="/pia/fanfan/gao/profile/">返回控制面板</a>')
    else:
        account.good_set.add(good)
        r = Record(account_from=account,
                   account_to=Account.objects.get(name='admin'),
                   amount=good.price,
                   comment=('book: %s' % good))
        r.save()
    return HttpResponseRedirect('/pia/fanfan/gao/profile/')