Пример #1
0
    def post(self, *args, **kwargs):

        cart_object = get_or_create_cart(self.request)
        f = CartForm(self.request.POST,instance=cart_object)
        if f.is_valid():
            f.save()
            #Message only for EU cart clickers
            if cart_object.is_eu_cart:
                messages.add_message(self.request,messages.INFO, _('Remember that you need to have valid EU VAT number to claim 0% EU VAT rate'),extra_tags='basket_only')
        else:
            messages.add_message(self.request,messages.ERROR, _('Error changing VAT rate.'),extra_tags='basket_only')

        return redirect(self.request.POST.get('next'))
Пример #2
0
def save(request):
    obj = None
    sid = request.POST.get('id')
    try:
        if sid:
            obj = Cart.objects.get(id=sid)
            if obj.sync_flag == 1:
                result = {
                    "ret": 10000,
                    "status": "failed",
                    "msg": "任务已分配,无法进行修改!"
                }
                return HttpResponse(json.dumps(result),
                                    content_type="application/json")
    except Cart.DoesNotExist:
        pass
    if obj:
        form = CartForm(request.POST or None, instance=obj)
    else:
        option = request.POST.get("option")
        total = request.POST.get('total')
        if int(option):
            accounts = Account.objects.filter(delflag=0,
                                              tag_id=request.POST.get('tag'),
                                              createuser_id=5)
            if accounts.count() == 0:
                result = {
                    "ret": 10000,
                    "status": "failed",
                    "msg": "当前系统下没有买手号,请联系客服!"
                }
                return HttpResponse(json.dumps(result),
                                    content_type="application/json")
            integral = 150
        else:
            accounts = Account.objects.filter(delflag=0,
                                              tag_id=request.POST.get('tag'),
                                              createuser_id=request.user.id)
            if accounts.count() == 0:
                result = {
                    "ret": 10000,
                    "status": "failed",
                    "msg": "当前账号下没有买手号!"
                }
                return HttpResponse(json.dumps(result),
                                    content_type="application/json")
            discount = request.user.user_profile.discount
            integral = int(30 * (discount / 100.0))
        total_integral = integral * int(total)
        if Profile.objects.get(
                user_id=request.user.id).integral < total_integral:
            result = {"ret": 10000, "status": "failed", "msg": "当前账号积分不足!"}
            return HttpResponse(json.dumps(result),
                                content_type="application/json")
        form = CartForm(request.POST or None)
    if form.is_valid():
        instance = form.save(commit=False)
        if sid:
            instance.updateuser = request.user

        else:
            instance.createuser = request.user
        instance.save()
        result = {"ret": 0, "status": "success"}
        return HttpResponse(json.dumps(result),
                            content_type="application/json")
    else:
        msg = []
        if form.errors:
            for k, v in form.errors.iteritems():
                msg.append(v[0])
        return HttpResponse(json.dumps({
            "ret": 10000,
            "status": "error",
            "msg": '\n'.join(msg)
        }),
                            content_type="application/json")