def unions_count_json(request): available = request.values.get('available', None) if available is None: count = Union.query().count() else: if available.lower() == 'true': count = Union.query(Union.available == True).count() else: count = Union.query(Union.available == False).count() return render_json_response({ 'success': True, 'result': count })
def unions_json(request): available = request.values.get('available', None) if available is None: unions_q = Union.query() else: if available.lower() == 'true': unions_q = Union.query(Union.available == True) else: unions_q = Union.query(Union.available == False) unions = [key.id() for key in unions_q.fetch(keys_only=True)] return render_json_response({ 'success': True, 'result': unions })
def index(request): products_obj = Union.query(Union.available == True) if products_obj.count(): products_obj = products_obj.fetch() else: products_obj = [] return render_to_response('shop/index.html', {'products':products_obj})
def index(request): available_product = Product.query(Product.available == True, Product.id_1c != '').get() if not available_product: available_product = Product.query().get() if available_product: available_product = available_product.key.id() else: available_product = 1024 available_union = Union.query(Union.available == True).get() if not available_union: available_union = Union.query().get() if available_union: available_union = available_union.key.id() else: available_union = 1025 return render_to_response('api/v3/index.html', { 'available_product': available_product, 'available_union': available_union })
def get_image(request, id, uid): union = Union.get_by_id(id) if not union: return render_json_response({"api": {"success": False, "msg": "Union %s not found" % id}}, status=400) if request.method == "DELETE": for image in union.images: if image.uid == uid: image.pre_delete() union.images.remove(image) union.put() return render_json_response({"api": {"success": True}})
def union_json(request): key_id = request.values.get('id') if not key_id: raise ApiException('Invalid request: "id" params not found.') union = Union.get_by_id(int(key_id)) if not union: raise ApiException('Union with "%s" == %s not found' % ('id', key_id), status=404) return render_json_response({ 'success': True, 'result': union.to_json_api() })
def cart_item_to_json(item_id, count): cart_item = {} product = Product.get_by_id(item_id) if not product: product = Union.get_by_id(item_id) if product: cart_item['id'] = item_id cart_item['title'] = product.title cart_item['url'] = product.url if product.master_image: cart_item['img_url'] = product.master_image.get_url() else: cart_item['img_url'] = "" cart_item['price'] = product.price cart_item['count'] = count return cart_item
def upload_image(request, id): union = Union.get_by_id(id) if not union: return render_json_response({"api": {"success": False, "msg": "Union %s not found" % id}}, status=400) if request.method == "POST": try: upload_files = get_uploads(request, "file") blob_info = upload_files[0] im = Image.create(blob_info.key(), title=union.title) if not len(union.images): im.is_master = True if im.get_cached_url(): union.images.append(im) union.put() return render_json_response({"api_success": True, "api_msg": "Image uploaded", "image": im.to_json()}) else: return render_json_response({"api_success": False, "api_msg": "Invalid image"}) except Exception, e: return render_json_response({"api_success": False, "api_msg": str(e)}, status=400)
def api_union(request, id): union = Union.get_by_id(id) if not union: return render_json_response({"api": {"success": False, "msg": "Product %s not found" % id}}, status=400) if request.method == "GET": return render_json_response(union.to_json()) if request.method == "PUT": model = simplejson.loads(request.data) if type(model) != dict: return render_json_response( {"api": {"success": False, "msg": "Invalid data", "data": request.data}}, status=500 ) union.title = model.get("title", "") union.uid = model.get("uid", "") union.description = model.get("description", "") union.available = model.get("available", False) union.custom_price = model.get("price", 0.0) products = model.get("products", []) del union.products[:] for product in products: product = Product.get_by_id(product["id"]) if product: union.products.append(product.key) union.put() return render_json_response(union.to_json()) if request.method == "DELETE": for image in union.images: image.pre_delete() union.key.delete() return render_json_response({"api": {"success": True, "msg": "Union %s was deleted" % id}}) return render_json_response( {"api": {"success": False, "msg": "Request method %s not supported" % request.method}}, status=400 )
def get_union(request, id): union = Union.get_by_id(id) products_obj = ndb.get_multi_async(union.products) if not union: return redirect(url_for('page/404')) return render_to_response('shop/union.html', {'union':union, 'products':products_obj})
def api_unions(request): unions = Union.query() return render_json_response([union.to_json() for union in unions])
def index(request): unions = Union.query() return render_to_response("union/admins/index.html", {"unions": unions})
def get_images(request, id): union = Union.get_by_id(id) if not union: return render_json_response({"api": {"success": False, "msg": "Union %s not found" % id}}, status=400) if request.method == "GET": return render_json_response([image.to_json() for image in union.images])