def index(request): store_links = StoreLink.query(StoreLink.city == "").fetch() store_links_city = StoreLink.query(StoreLink.city != "").order(StoreLink.city) cities = {} for store in store_links_city: stores = cities.get(store.city, []) stores.append(store) cities[store.city] = stores return render_to_response("store_link/index.html", {"store_links": store_links, "cities": cities})
def index(): form = StoreLinkForm() if form.validate_on_submit(): store_link = StoreLink() form.populate_obj(store_link) store_link.put() return redirect(url_for('admin.store_link.index')) store_links = StoreLink.query() return render_template('admin/store_link/index.html', form=form, store_links=store_links)
def to_cart(request, id): store_links = StoreLink.query(StoreLink.city == '') store_links_city = StoreLink.query(StoreLink.city != '').order(StoreLink.city) cities = {} for store in store_links_city: stores = cities.get(store.city, []) stores.append(store) cities[store.city] = stores if request.method == 'POST': if id: cart = request.session.get('cart', {}) if not len(cart): count = 1 cart[id] = {'count': count} request.session['cart'] = cart else: product = cart.get(id, {}) count = product.get('count', 0) + 1 product['count'] = count cart[id] = product request.session['cart'] = cart else: count = 0 return render_to_response( 'shop/add_button.html', { 'count': count, 'store_links': store_links, 'cities': cities }) if request.method == 'GET': cart = request.session.get('cart', {}) product = cart.get(id, {}) count = product.get('count', 0) return render_to_response( 'shop/add_button.html', { 'count': count, 'store_links': store_links, 'cities': cities }) return render_to_response('shop/add_button.html', { 'count': 0, 'store_links': store_links, 'cities': cities })
def index(): posts, posts_count = get_latest_posts() brands, brands_count = brands_stat() categories, categories_count = categories_stat() product_count = product_stat() countries_count = countries_stat() store_links = StoreLink.query() return flask.render_template('pages/index.html', posts=posts, posts_count=posts_count, product_count=product_count, categories=categories, categories_count=categories_count, countries_count=countries_count, brands_count=brands_count, brands=brands, store_links=store_links)
def index(): posts, posts_count = get_latest_posts() brands, brands_count = brands_stat() categories, categories_count = categories_stat() product_count = product_stat() countries_count = countries_stat() store_links = StoreLink.query() return flask.render_template( 'pages/index.html', posts=posts, posts_count=posts_count, product_count=product_count, categories=categories, categories_count=categories_count, countries_count=countries_count, brands_count=brands_count, brands=brands, store_links=store_links )
def get_order_box(key_id): store_links = StoreLink.query() if current_user.id <= 0: return render_template('order/login_require_box.html', store_links=store_links) if not current_user.is_order_box: return render_template('order/customer_require_box.html', store_links=store_links) product = Product.retrieve_by_id(key_id) if not product.is_available: return render_template('order/no_available_box.html', store_links=store_links) cart = session.get('cart', {}) products = cart.get('products', {}) order_product = products.get(key_id, {}) order_product_count = order_product.get('count', 0) order_product_price = order_product.get('price', 0) if request.method == 'POST' and 'order_clear' in request.form: if key_id in products: del products[key_id] cart['products'] = products cart['price'] = cart.get('price', order_product_price) - order_product_price session['count'] = cart.get('count', order_product_count) - order_product_count session['cart'] = cart return redirect(url_for('order.get_order_box', key_id=key_id)) order_product = products.get(key_id, {}) order_product_count = order_product.get('count', 0) order_product_price = order_product.get('price', 0) if order_product_count: form = OrderForm(count=order_product_count) form.count.description=\ u'В предзакаезе %s шт. данного товара на сумму %s рублей. Введите новое количество заказываемого товара.' \ % (order_product_count, order_product_price) change = True else: form = OrderForm() change = False count=0 if form.validate_on_submit(): count = form.count.data if product: price = product.price_trade * count cart['price'] = cart.get('price', order_product_price) - order_product_price + price cart['products_count'] = cart.get('products_count', order_product_count) - order_product_count + count order_product['count'] = order_product_count = count order_product['price'] = order_product_price = order_product['count'] * product.price_trade products[key_id] = order_product cart['products']=products cart['un_products_count'] = len(products) session['cart'] = cart if count: change = True form.count.description=\ u'В предзакаезе %s шт. данного товара на сумму %s рублей. Введите новое количество заказываемого товара.' \ % (order_product_count, order_product_price) return render_template( 'order/order_box.html', form=form, url=url_for('order.get_order_box', key_id=key_id), count=count, change=change, order_product_count=order_product_count, order_product_price=order_product_price, store_links=store_links )
def del_link(key_id): link = StoreLink.retrieve_by_id(key_id) if link and 'delete' in request.form: link.key.delete() return redirect(url_for('admin.store_link.index'))