From 8a1a5ed5c189a2e22169bd647be7b1656a5c0c52 Mon Sep 17 00:00:00 2001 From: Gena Date: Wed, 17 Jun 2015 12:53:09 +0600 Subject: [PATCH] auto --- batiskaf/urls.py | 1 + main/views.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/batiskaf/urls.py b/batiskaf/urls.py index 26dd8f8..51db206 100644 --- a/batiskaf/urls.py +++ b/batiskaf/urls.py @@ -30,6 +30,7 @@ urlpatterns = patterns( name='size_sargan'), url(r'^size/scorpena/$', 'main.views.size_scorpena', name='size_scorpena'), + url(r'^api/item/(?P
.+)/$', 'main.views.temp_count_update', name='temp_count_update'), url(r'^api/', include(router.urls)), url(r'^news/', include('news.urls')), url(r'^get_order_amount/$', 'store.views.get_order_amount'), diff --git a/main/views.py b/main/views.py index a724b7e..e10d8b3 100644 --- a/main/views.py +++ b/main/views.py @@ -1,5 +1,6 @@ +from django.http import JsonResponse from django.shortcuts import render -from store.models import Product, Category +from store.models import Product, Category, ProductVariation def index(request): @@ -41,3 +42,21 @@ def size_sargan(request): def size_omer_sporasub(request): return render(request, 'size/omer_sporasub.jinja') +def temp_count_update(request, article): + retval = dict(error_code=0) + try: + product = ProductVariation.objects.get(article__iexact=article) + count = request.GET.get('count', None) + if count != None: + if int(count) < 0: + count = 0 + product.in_stock = int(count) + product.save() + else: + retval['error_code'] = 1 + except ProductVariation.DoesNotExist: + retval['error_code'] = 1 + except Exception as e: + retval['error_code'] = e + return JsonResponse(retval) +