def products(request): categories = Category.query(Category.available == True, Category.only_end_products == True).order(Category.title).fetch() if request.user and request.user.is_admin: products_obj = Product.query().order(-Product.rating).fetch(20) else: products_obj = Product.query().filter(Product.available == True).order(-Product.rating).fetch(20) return render_to_response('shop/products.html', {'products':products_obj, 'categories':categories})
def products_dates_json(request): date1 = request.values.get("from_date") date2 = request.values.get('to_date') if date1 is None: ApiException('Invalid request: parameter "from_date" not found.') date1 = datetime.strptime(date1, '%Y-%m-%d') if date2 is None: date2 = datetime.now() else: date2 = datetime.strptime(date2, '%Y-%m-%d') ApiException(date2) is_new = request.values.get('only_new') if is_new is None: products_q = Product.query( Product.timestamp_edit >= date1, Product.timestamp_edit <= date2).fetch(keys_only=True) else: products_q = Product.query( Product.timestamp_add >= date1, Product.timestamp_add <= date2).fetch(keys_only=True) res = { 'success': True, 'result': [key.id() for key in products_q] } return render_json_response(res)
def constructor(request): categories = Category.query(Category.available == True, Category.only_end_products == False).order(Category.title) products_obj = None if categories.count(): if request.user and request.user.is_admin: products_obj = Product.query(Product.category==categories.get().key).order(-Product.rating).fetch(20) else: products_obj = Product.query(Product.category==categories.get().key).filter(Product.available == True).order(-Product.rating).fetch(20) return render_to_response('shop/constructor.html', {'products':products_obj, 'categories':categories.fetch()})
def get_category(request, id): cat_obj = Category.get_by_id(id) if not cat_obj: return redirect(url_for('shop/index')) categories = Category.query(Category.available == True, Category.only_end_products == True).fetch() if request.user and request.user.is_admin: products_obj = Product.query().filter(Product.category == cat_obj.key).order(-Product.rating).fetch() else: products_obj = Product.query().filter(Product.category == cat_obj.key).filter(Product.available == True).order(-Product.rating).fetch() return render_to_response('shop/category.html', {'category':cat_obj, 'products':products_obj, 'categories':categories})
def products_count_json(request): available = request.values.get('available', None) if available is None: count = Product.query().count() else: if available.lower() == 'true': count = Product.query(Product.available == True).count() else: count = Product.query(Product.available == False).count() return render_json_response({ 'success': True, 'result': count })
def filter_brand(request): is_available = bool(request.values.get('available', False)) brand_key = request.values.get('brand') if brand_key: brand = Brand.get_by_id(int(brand_key)) products = Product.query().filter(Product.brand == brand.key).filter(Product.available == is_available) else: products = Product.query().filter(Product.brand == None).filter(Product.available == is_available) return render_to_response('shop/admin/product_filter.html', { 'products':products, 'available':is_available })
def get_products(request): products = memcache.get("json_products") if not products: products = Product.query().fetch() products = [product.to_json() for product in products] memcache.add("json_products", products, 600) return render_json_response(products)
def products_json(request): available = request.values.get('available', None) if available is None: products_q = Product.query() else: if available.lower() == 'true': products_q = Product.query(Product.available == True) else: products_q = Product.query(Product.available == False) is_1c = request.values.get('id_1c') if is_1c: products = [product.id_1c for product in products_q.fetch(projection=[Product.id_1c])] else: products = [key.id() for key in products_q.fetch(keys_only=True)] return render_json_response({ 'success': True, 'result': products })
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 filter_category(request): is_available = request.values.get('available', '0') is_available = is_available.lower() in ["1", "true", "yes"] category_id = request.values.get('category') if category_id: category = Category.get_by_id(int(category_id)) if is_available: products = category.get_available_products() else: products = category.get_not_available_products() else: if is_available: products = Product.query().filter(Product.available == True).filter(Product.category == None) else: products = Product.query().filter(Product.available != True).filter(Product.category == None) return render_to_response('shop/admin/product_filter.html', { 'products':products, 'available':is_available })
def product_json(request): key_id = request.values.get('id') id_1c = request.values.get('id_1c') if not key_id and not id_1c: raise ApiException('Invalid request: "id" or "id_1c" params not found.') if key_id is not None and id_1c is not None: raise ApiException('Invalid request: "id" and "id_1c" together.') product = None if key_id: product = Product.get_by_id(int(key_id)) if id_1c: product = Product.query(Product.id_1c == id_1c).get() if not product: if key_id: raise ApiException('Product with "%s" == %s not found' % ('id', key_id), status=404) raise ApiException('Product with "%s" == %s not found' % ('id_1c', id_1c), status=404) return render_json_response({ 'success': True, 'result': product.to_json_api() })
def is_product_exist_id_1c(id_1c): product = Product.query().filter(Product.id_1c == id_1c) if product.count(): return True return False
def get_not_end(request, id): cat_obj = Category.get_by_id(id) categories = Category.query(Category.available == True, Category.only_end_products == False).order(Category.title).fetch() products_obj = Product.query().filter(Product.category == cat_obj.key).filter(Product.available == True).order(-Product.rating).fetch() return render_to_response('shop/not_end.html', {'category':cat_obj, 'products':products_obj, 'categories':categories})
def not_end(request): categories = Category.query(Category.available == True, Category.only_end_products == False).order(Category.title) products_obj = None if categories.count(): products_obj = Product.query(Product.category==categories.get().key).order(-Product.rating).fetch(21) return render_to_response('shop/not_end.html', {'products':products_obj, 'categories':categories})
def collection(request): categories = Category.query(Category.available == True, Category.only_end_products == True).order(Category.title) products = Product.query().order(-Product.rating).fetch(21) return render_to_response('page/collection.html', {'products':products, 'categories':categories})
def get_category(request, id): cat_obj = Category.get_by_id(id) categories = Category.query().filter(Category.available == True, Category.only_end_products == True).order(Category.title) products = Product.query().filter(Product.category == cat_obj.key).filter(Product.available == True) return render_to_response('page/collection.html', {'category':cat_obj, 'products':products, 'categories':categories})
def products_json(request): return render_json_response( [product.to_json() for product in Product.query()])