Exemplo n.º 1
0
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})
Exemplo n.º 2
0
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()})
Exemplo n.º 3
0
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})
Exemplo n.º 4
0
def product(request):
    all_product = Product.available_list()
    all_hide_product = Product.not_available_list()

    available_product_without_properties_count = 0
    for pr in all_product:
        if  not len(pr.properties_):
            available_product_without_properties_count += 1


    unavailable_product_without_properties_count = 0
    for pr in all_hide_product:
        if not len(pr.properties_):
            unavailable_product_without_properties_count += 1

    brand_all_available_product = Product.available_list().filter(Product.brand != None)
    logging.warning(brand_all_available_product.count())
    brand_all_not_available_product = Product.not_available_list().filter(Product.brand != None)

    no_brand_all_available_product_count = Product.available_list().filter(Product.brand == None).count()
    no_brand_all_not_available_product_count = Product.not_available_list().filter(Product.brand == None).count()

    available_brand = {}
    for product_ in brand_all_available_product:
        if not product_.brand in available_brand:
            count = Product.available_list().filter(Product.brand == product_.brand).count()
            available_brand[product_.brand] = count

    not_available_brand = {}
    for product_ in brand_all_not_available_product:
        if not product_.brand in not_available_brand:
            count = Product.not_available_list().filter(Product.brand == product_.brand).count()
            not_available_brand[product_.brand] = count

    categories = Category.query(Category.parent_category == None).order(Category.title)
    properties = ProductProperty.query().order(ProductProperty.title)
    brands = Brand.query().order(Brand.title)

    available_uncategories = all_product
    available_uncategories = available_uncategories.filter(Product.category == None)
    unavailable_uncategories = all_hide_product
    unavailable_uncategories = unavailable_uncategories.filter(Product.category == None)
    return render_to_response('shop/admin/product.html',
        locals()
    )
Exemplo n.º 5
0
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})
Exemplo n.º 6
0
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})
Exemplo n.º 7
0
def categories_json(request):
    categories = [key.id() for key in Category.query().fetch(keys_only=True)]
    return render_json_response({
        'success': True,
        'result': categories
    })
Exemplo n.º 8
0
def categories_count_json(request):
    return render_json_response({
        'success': True,
        'result': Category.query().count()
    })
Exemplo n.º 9
0
def is_category_exist(title):
    category = Category.query().filter(Category.title == title)
    if category.count():
        return True
    return False
Exemplo n.º 10
0
def get_product(request, id):
    product = Product.get_by_id(id)
    if not product:
        return redirect(url_for('page/404'))
    categories = Category.query(Category.available == True, Category.only_end_products == True)
    return render_to_response('shop/product.html', {'product':product, 'categories':categories})
Exemplo n.º 11
0
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})
Exemplo n.º 12
0
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})
Exemplo n.º 13
0
def categories_json(request):
    categories = [category.to_json() for category in Category.query().order(Category.title)]
    return render_json_response(categories)
Exemplo n.º 14
0
def get_categories(request):
    categories = [category.to_json() for category in Category.query()]
    return render_json_response(categories)