示例#1
0
def get_item_card_data():
    """ Returns information for an item card """

    item = db.item(request.args(0))
    if not item:
        raise HTTP(404)

    item_utils.data_for_card(item)

    return json.dumps(item)
示例#2
0
def get_item_card_data():
    """ Returns information for an item card """

    item = db.item(request.args(0))
    if not item:
        raise HTTP(404)

    item_utils.data_for_card(item)

    return json.dumps(item)
def get():
    """ args: [id_offer_group]"""

    offer_group = db.offer_group(request.args(0))
    if not offer_group:
        raise HTTP(404)

    discounts = db((db.discount.id_offer_group == offer_group.id)
                 & (db.discount.is_coupon == False)
                 & (db.discount.code == '')
                 ).select()

    query = (db.item.id < 0)
    for discount in discounts:
        if discount.id_item:
            query |= (db.item.id == discount.id_item.id)
        if discount.id_brand:
            query |= (db.item.id_brand == discount.id_brand.id)
        if discount.id_category:
            query |= (db.item.categories.contains(discount.id_category.id))
    pages, limits = pages_menu(query, request.vars.page, request.vars.ipp, distinct=db.item.name)
    items = db(query).select(limitby=limits)
    items = [item_utils.data_for_card(v) for v in items]
    items_data_script = SCRIPT("var items_data = %s" % json.dumps(items))
    del items

    return locals()
示例#4
0
def get_new_items():
    new_items = db(db.item.is_active == True).iterselect(
        orderby=~db.item.created_on, limitby=(0, 10))

    new_items = [item_utils.data_for_card(v) for v in new_items]

    return dict(items=new_items)
示例#5
0
def browse():
    """ Item browser
        vars: {category, sort, categories, is_service, brand, term}
    """

    term = request.vars.term

    category = db.category(request.vars.category)
    is_service = request.vars.is_service == 'yes'
    brand = db.brand(request.vars.brand)

    title = T('Items')
    if term:
        title = T('Searching items matching "%s"') % term

    query = (db.item.is_active == True)
    orderby = db.item.created_on

    if term:
        query = search_item_query(term, category)
        orderby = ~db.item.name.contains(term)

    if category:
        query &= db.item.categories.contains(category.id)

    if is_service:
        title = T('Services')
        query &= db.item.has_inventory == False
    if brand:
        query &= db.item.id_brand == brand.id

    no_items_msg = T('No items found') + ' '
    if is_service:
        no_items_msg = T('No services found') + ' '
    if brand:
        no_items_msg += T('with brand: %s ') % brand.name
    if category:
        no_items_msg += T('in category: %s') % category.name

    pages, limits = pages_menu(query,
                               request.vars.page,
                               request.vars.ipp,
                               distinct=db.item.name)
    items = db(query).iterselect(limitby=limits, orderby=orderby)
    items = [item_utils.data_for_card(v) for v in items]
    items_data_script = SCRIPT("var items_data = %s" % json.dumps(items))
    del items

    selected_categories = [category.id] if category else []
    categories_data_script = SCRIPT(
        "var categories_tree_data = %s" %
        json_categories_tree(selected_categories=selected_categories))

    filter_data = {"tablename": "item", "sortby": ['base_price', 'name']}
    filter_data = None

    page_title = T('Browse items')
    page_description = T('Browse items catalog')

    return locals()
示例#6
0
def get_some_services():
    records = db(
        (db.item.is_active == True) & (db.item.has_inventory == False)
    ).iterselect(orderby='<random>', limitby=(0, 10))

    services = [item_utils.data_for_card(v) for v in records]

    return dict(items=services)
示例#7
0
def get_new_items():
    new_items = db(
        db.item.is_active == True
    ).iterselect(orderby=~db.item.created_on, limitby=(0, 10))

    new_items = [item_utils.data_for_card(v) for v in new_items]

    return dict(items=new_items)
示例#8
0
def get_some_services():
    records = db((db.item.is_active == True)
                 & (db.item.has_inventory == False)).iterselect(
                     orderby='<random>', limitby=(0, 10))

    services = [item_utils.data_for_card(v) for v in records]

    return dict(items=services)
示例#9
0
def get_affinity_items():
    """ args: item_id """

    item_id = request.args(0)

    records = db((db.item_affinity.id_item1 == item_id)
                 | (db.item_affinity.id_item2 == item_id)).iterselect(
                     orderby=~db.item_affinity.affinity, limitby=(0, 5))

    items = []
    for record in records:
        item_id = long(item_id)

        item = record.id_item1 if record.id_item1.id != item_id else record.id_item2
        items.append(item_utils.data_for_card(item))

    return dict(items=items)
示例#10
0
def get_popular_items():
    """ Returns a list of popular items """

    # best sellers this month
    start_date = date(request.now.year, request.now.month, 1)
    end_date = date(request.now.year, request.now.month + 1, 1)

    values = db((db.bag_item.id_item == db.item.id)
                & (db.bag_item.created_on >= start_date)
                & (db.bag_item.created_on <= end_date)).iterselect(
                    db.item.ALL,
                    db.bag_item.quantity.sum(),
                    groupby=db.item.id,
                    limitby=(0, 10),
                    orderby=~db.bag_item.quantity.sum())
    popular_items = [item_utils.data_for_card(v.item) for v in values]
    random.shuffle(popular_items)

    return dict(items=popular_items)
示例#11
0
def get_popular_items():
    """ Returns a list of popular items """

    # best sellers this month
    start_date = date(request.now.year, request.now.month, 1)
    end_date = start_date + timedelta(days=30)

    values = db(
          (db.bag_item.id_item == db.item.id)
        & (db.bag_item.created_on >= start_date)
        & (db.bag_item.created_on <= end_date)
    ).iterselect(
        db.item.ALL, db.bag_item.quantity.sum(),
        groupby=db.item.id, limitby=(0, 10),
        orderby=~db.bag_item.quantity.sum()
    )
    popular_items = [item_utils.data_for_card(v.item) for v in values]
    random.shuffle(popular_items)

    return dict(items=popular_items)
示例#12
0
def get_affinity_items():
    """ args: item_id """

    item_id = request.args(0)

    records = db(
        (db.item_affinity.id_item1 == item_id) |
        (db.item_affinity.id_item2 == item_id)
    ).iterselect(
        orderby=~db.item_affinity.affinity,
        limitby=(0, 5)
    )


    items = []
    for record in records:
        item_id = long(item_id)

        item = record.id_item1 if record.id_item1.id != item_id else record.id_item2
        items.append(item_utils.data_for_card(item))

    return dict(items=items)
示例#13
0
def browse():
    """ Item browser
        vars: {category, sort, categories, is_service, brand, term}
    """

    term = request.vars.term

    category = db.category(request.vars.category)
    is_service = request.vars.is_service == 'yes'
    brand = db.brand(request.vars.brand)

    title = T('Items')
    if term:
        title = T('Searching items matching "%s"') % term

    query = (db.item.is_active == True)
    orderby = db.item.created_on

    if term:
        query = search_item_query(term, category)
        orderby = db.item.id|~db.item.name.contains(term)

    if category:
        query &= db.item.categories.contains(category.id)

    if is_service:
        title = T('Services')
        query &= db.item.has_inventory == False
    if brand:
        query &= db.item.id_brand == brand.id


    no_items_msg = T('No items found') + ' '
    if is_service:
        no_items_msg = T('No services found') + ' '
    if brand:
        no_items_msg += T('with brand: %s ') % brand.name
    if category:
        no_items_msg += T('in category: %s') % category.name


    pages, limits = pages_menu(query, request.vars.page, request.vars.ipp, distinct=db.item.name)
    items = db(query).iterselect(
        limitby=limits,
        orderby=orderby
    )
    items = [item_utils.data_for_card(v) for v in items]
    items_data_script = SCRIPT("var items_data = %s" % json.dumps(items))
    del items

    selected_categories = [category.id] if category else []
    categories_data_script = SCRIPT("var categories_tree_data = %s" % json_categories_tree(selected_categories=selected_categories))

    filter_data = {
        "tablename": "item",
        "sortby": ['base_price', 'name']
    }
    filter_data = None

    page_title = T('Browse items')
    page_description = T('Browse items catalog')

    return locals()