Ejemplo n.º 1
0
def products_count_json():
    is_available = param('available', bool)
    if is_available is not None and is_available:
        return jsonify_success(
            Product.query(Product.is_available == True).count())
    if is_available is not None and not is_available:
        return jsonify_success(
            Product.query(Product.is_available != True).count())
    return jsonify_success(Product.query().count())
Ejemplo n.º 2
0
def get_to_sync():
    id_1c = param('id_1c')
    if id_1c is not None:
        products = Product.query(Product.to_sync == True).fetch(
            projection=[Product.id_1c])
        return jsonify_success([key.id_1c for key in products])

    products = Product.query(Product.to_sync == True).fetch(keys_only=True)
    return jsonify_success([key.id() for key in products])
Ejemplo n.º 3
0
def index():
    available_product = Product.query(Product.is_available == True,
                                      Product.id_1c != '').get()
    available_category = Category.query().get()
    return render_template('api/v2/index.html',
                           available_product=available_product,
                           available_category=available_category)
Ejemplo n.º 4
0
def product_stat():
    product_count = Product.query().count()
    if product_count:
        product_count = pytils.numeral.get_plural(
            product_count,
            (u"позиции", u"позиций", u"позиций")
        )
    return product_count
Ejemplo n.º 5
0
def last_incoming(page):
    products = Product.query().order(-Product.created)
    products = get_paginator(products, page)
    return flask.render_template(
        'pages/last_incoming.html',
        title=u'Последние поступления',
        products=products
    )
Ejemplo n.º 6
0
def products_json():
    is_available = param('available', bool)
    if is_available is not None:
        if is_available:
            products_q = Product.query(Product.is_available == True)
        else:
            products_q = Product.query(Product.is_available != True)
    else:
        products_q = Product.query()

    is_1c = param('id_1c')
    if is_1c is not None:
        return jsonify_success([
            key.id_1c for key in products_q.fetch(projection=[Product.id_1c])
        ])
    return jsonify_success(
        [key.id() for key in products_q.fetch(keys_only=True)])
Ejemplo n.º 7
0
def catalogue(page):
    products = Product.query() \
        .order(-Product.rating) \
        .order(-Product.leftovers_on_way) \
        .order(-Product.leftovers)
    products = get_paginator(products, page)
    return flask.render_template('pages/catalogue.html',
                                 title=u'Каталог товаров',
                                 products=products)
Ejemplo n.º 8
0
def catalogue(page):
    products = Product.query() \
        .order(-Product.rating) \
        .order(-Product.leftovers_on_way) \
        .order(-Product.leftovers)
    products = get_paginator(products, page)
    return flask.render_template(
        'pages/catalogue.html',
        title=u'Каталог товаров',
        products=products
    )
Ejemplo n.º 9
0
def products_dates_json():
    date1 = param("from_date")
    date2 = param('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 = param('only_new')
    if is_new is None:
        products_q = Product.query(
            Product.modified >= date1,
            Product.modified <= date2).fetch(keys_only=True)
    else:
        products_q = Product.query(
            Product.created >= date1,
            Product.created <= date2).fetch(keys_only=True)
    return jsonify_success([key.id() for key in products_q])
Ejemplo n.º 10
0
def sitemap_xml():
    products = memcache.get('sitemap_xml')
    if not products:
        products = Product.query().fetch(keys_only=True)
        memcache.add('sitemap_xml', products, SITEMAP_XML_TIMEOUT)
    categories = memcache.get('sitemap_xml_categories')
    if not categories:
        categories = Category.query().fetch(keys_only=True)
        memcache.add('sitemap_xml_categories', categories, SITEMAP_XML_TIMEOUT)
    response = flask.make_response(
        flask.render_template('pages/sitemap.xml',
                              products=products,
                              categories=categories))
    response.headers['Content-Type'] = 'text/xml; charset=utf-8'
    return response
Ejemplo n.º 11
0
def product_new():
    if request.method == "POST":
        flag, model = load_data()
        if not flag:
            return model
        id_1c = model.get("id_1c")
        if not id_1c:
            return jsonify({"success": False, "msg": "id_1c field not found."})
        is_exist = Product.query(Product.id_1c == id_1c).count()
        if is_exist:
            return jsonify({"success": False, "msg": "Product with id_1c: %s is exist" % id_1c})
        product = Product()
        if model_populate(model, product):
            product.put()
    return jsonify({"success": True})
Ejemplo n.º 12
0
def sitemap_xml():
    products = memcache.get('sitemap_xml')
    if not products:
        products = Product.query().fetch(keys_only=True)
        memcache.add('sitemap_xml', products, SITEMAP_XML_TIMEOUT)
    categories = memcache.get('sitemap_xml_categories')
    if not categories:
        categories = Category.query().fetch(keys_only=True)
        memcache.add('sitemap_xml_categories', categories, SITEMAP_XML_TIMEOUT)
    response = flask.make_response(
        flask.render_template(
            'pages/sitemap.xml',
            products=products,
            categories=categories)
    )
    response.headers['Content-Type'] = 'text/xml; charset=utf-8'
    return response
Ejemplo n.º 13
0
def product_new():
    if request.method == 'POST':
        flag, model = load_data()
        if not flag:
            return model
        id_1c = model.get('id_1c')
        if not id_1c:
            return jsonify({'success': False, 'msg': 'id_1c field not found.'})
        is_exist = Product.query(Product.id_1c == id_1c).count()
        if is_exist:
            return jsonify({
                'success': False,
                'msg': 'Product with id_1c: %s is exist' % id_1c
            })
        product = Product()
        if model_populate(model, product):
            product.put()
    return jsonify({'success': True})
Ejemplo n.º 14
0
def product_json():
    key_id = param('id')
    id_1c = param('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.retrieve_by_id(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 jsonify_model_db(product)
Ejemplo n.º 15
0
def get_searchable_products():
    products_q = Product.query()
    return products_q.fetch(
        projection=[Product.name, Product.barcode, Product.catalogue_id])
Ejemplo n.º 16
0
def products():
    products_obj = Product.query()
    return jsonify_model_dbs(products_obj)
Ejemplo n.º 17
0
def last_incoming(page):
    products = Product.query().order(-Product.created)
    products = get_paginator(products, page)
    return flask.render_template('pages/last_incoming.html',
                                 title=u'Последние поступления',
                                 products=products)
Ejemplo n.º 18
0
def products():
    products_obj = Product.query()
    return jsonify_model_dbs(products_obj)
Ejemplo n.º 19
0
def product_stat():
    product_count = Product.query().count()
    if product_count:
        product_count = pytils.numeral.get_plural(
            product_count, (u"позиции", u"позиций", u"позиций"))
    return product_count
Ejemplo n.º 20
0
def get_searchable_products():
    products_q = Product.query()
    return products_q.fetch(
        projection=[Product.name, Product.barcode, Product.catalogue_id]
    )