示例#1
0
def account_renew(request, username):
    user = request.user
    try:
        account = Account.objects.get(user=user, username=username)
        order = Order()
        order.user = user
        order.username = account.username
        order.password = account.password
        order.cycle = account.cycle
        order.plan = account.plan
        if promotion_is_valid(user, account.promotion, order.plan):
            promotion = Promotion.objects.get(code=account.promotion,
                                              plan=order.plan)
            order.price = int(
                account.cycle.quota /
                30) * account.cycle.discount * account.plan.discount * (
                    account.plan.price - promotion.price) * promotion.discount
            order.promotion = promotion.code
            order.discount = account.cycle.discount * account.plan.discount * promotion.discount
        else:
            order.price = int(
                account.cycle.quota / 30
            ) * account.cycle.discount * account.plan.discount * account.plan.price
            order.discount = account.cycle.discount * account.plan.discount
        order.save()
        send_order_mail(user, order)
        return HttpResponseRedirect("/home/order/")
    except Exception:
        return HttpResponseRedirect("/home/account/")
示例#2
0
def order(request):
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            order = Order()
            order.user = request.user
            order.username = cd['username']
            order.password = cd['password']
            cycle = Cycle.objects.get(name=cd['cycle'])
            plan = Plan.objects.get(name=cd['plan'])
            code = cd['promotion']
            order.cycle = cycle
            order.plan = plan
            if promotion_is_valid(request.user, code, plan):
                promotion = Promotion.objects.get(code=code, plan=plan)
                order.price = int(
                    cycle.quota / 30) * cycle.discount * plan.discount * (
                        plan.price - promotion.price) * promotion.discount
                order.promotion = promotion.code
                order.discount = cycle.discount * plan.discount * promotion.discount
            else:
                order.price = int(
                    cycle.quota /
                    30) * cycle.discount * plan.price * plan.discount
                order.discount = cycle.discount * plan.discount
            order.save()
            send_order_mail(request.user, order)
            return HttpResponseRedirect("/home/order/")
        else:
            c = {
                'form': form,
                'user': request.user,
                'message_count': message_count(request.user),
                'ticket_count': ticket_count(request.user),
                'active': 'order'
            }
            c.update(csrf(request))
            return render_to_response("order.html", c)
    else:
        form = OrderForm()
        c = {
            'form': form,
            'user': request.user,
            'message_count': message_count(request.user),
            'ticket_count': ticket_count(request.user),
            'active': 'order'
        }
        c.update(csrf(request))
        return render_to_response("order.html", c)
示例#3
0
def order(request):
  if request.method == 'POST':
      form = OrderForm(request.POST)
      if form.is_valid():
	cd = form.cleaned_data
	order = Order()
	order.user = request.user
	order.username = cd['username']
	order.password = cd['password']
	cycle = Cycle.objects.get(name=cd['cycle'])
	plan = Plan.objects.get(name=cd['plan'])
        code = cd['promotion']
	order.cycle = cycle
	order.plan = plan
        if promotion_is_valid(request.user,code,plan):
            promotion = Promotion.objects.get(code=code,plan=plan)
            order.price = int(cycle.quota/30) * cycle.discount * plan.discount * ( plan.price - promotion.price ) * promotion.discount
            order.promotion = promotion.code
            order.discount = cycle.discount * plan.discount * promotion.discount
        else:
            order.price = int(cycle.quota/30) * cycle.discount * plan.price * plan.discount
            order.discount = cycle.discount * plan.discount
	order.save()
	send_order_mail(request.user,order)
	return HttpResponseRedirect("/home/order/")
      else:
        c = {'form':form,
            'user':request.user,
            'message_count':message_count(request.user),
            'ticket_count':ticket_count(request.user),
            'active':'order'}
        c.update(csrf(request))
	return render_to_response("order.html",c)
  else:	
      form = OrderForm()
      c = {'form':form,
           'user':request.user,
            'message_count':message_count(request.user),
            'ticket_count':ticket_count(request.user),
           'active':'order'}
      c.update(csrf(request))
      return render_to_response("order.html",c)
示例#4
0
def account_renew(request,username):
  user = request.user
  try:
    account = Account.objects.get(user=user,username=username)
    order = Order()
    order.user = user
    order.username = account.username
    order.password = account.password
    order.cycle = account.cycle
    order.plan = account.plan
    if promotion_is_valid(user,account.promotion,order.plan):
        promotion = Promotion.objects.get(code=account.promotion,plan=order.plan)
        order.price = int(account.cycle.quota/30) * account.cycle.discount * account.plan.discount * ( account.plan.price - promotion.price ) * promotion.discount
        order.promotion = promotion.code
        order.discount = account.cycle.discount * account.plan.discount * promotion.discount
    else:
        order.price = int(account.cycle.quota/30) * account.cycle.discount * account.plan.discount * account.plan.price
        order.discount = account.cycle.discount * account.plan.discount
    order.save()
    send_order_mail(user,order)
    return HttpResponseRedirect("/home/order/")
  except Exception:
    return HttpResponseRedirect("/home/account/")