Пример #1
0
def list_promotion_items(promo_slug):
    paged = parse_int(get_args('paged'), 1, 1)
    perpage = parse_int(get_args('perpage'), 60, 1)

    promo = current_app.mongodb.Promotion.find_one_by_slug(promo_slug)
    if not promo:
        raise StorePromoNotFound

    if not promo['favorite_id']:
        return []

    # use default store for now
    store = current_app.mongodb.Store.find_one_default()
    taoke = connect_taoke(store)
    try:
        items = taoke.list_favorite_items(favorite_id=promo['favorite_id'],
                                          paged=paged,
                                          perpage=perpage)
    except Exception as e:
        raise StorePromoItemsError(e)

    results_count = len(items)

    return attach_extend([output_promo_item(item) for item in items],
                         {'_more': results_count >= perpage})
Пример #2
0
def list_promotions():
    paged = parse_int(get_args('paged'), 1, 1)
    perpage = parse_int(get_args('perpage'), 60, 1)

    promotions = current_app.mongodb.Promotion.find_activated()
    p = make_paginator(promotions, paged, perpage)
    return attach_extend([output_promo(promo) for promo in promotions], {
        '_more': p.has_next,
        '_count': p.count
    })
Пример #3
0
def list_activities():
    paged = parse_int(get_args('paged'), 1, 1)
    perpage = parse_int(get_args('perpage'), 60, 1)

    activitys = current_app.mongodb.Activity.find_activated()
    p = make_paginator(activitys, paged, perpage)
    return attach_extend([output_activity(activity) for activity in activitys],
                         {
                             '_more': p.has_next,
                             '_count': p.count
                         })
Пример #4
0
def list_shortcuts():
    paged = parse_int(get_args('paged'), 1, 1)
    perpage = parse_int(get_args('perpage'), 60, 1)

    shortcuts = current_app.mongodb.Shortcut.find_activated()
    p = make_paginator(shortcuts, paged, perpage)
    return attach_extend([output_shortcut(shortcut) for shortcut in shortcuts],
                         {
                             '_more': p.has_next,
                             '_count': p.count
                         })
Пример #5
0
def list_activity_items(activity_slug):
    paged = parse_int(get_args('paged'), 1, 1)
    perpage = parse_int(get_args('perpage'), 60, 1)
    timestamp = parse_int(get_args('timestamp'))

    items = current_app.mongodb.\
        Commodity.find_by_activity(activity_slug, timestamp)
    p = make_paginator(items, paged, perpage)
    return attach_extend([output_activity_commodity(item) for item in items], {
        '_more': p.has_next,
        '_count': p.count
    })
Пример #6
0
def list_commodities():
    paged = parse_int(get_args('paged'), 1, 1)
    perpage = parse_int(get_args('perpage'), 12, 1)
    timestamp = parse_int(get_args('timestamp'))
    categories = get_args('categories')
    is_newest = get_args('newest')

    store = g.store
    if is_newest and not categories:
        categories = store['cat_ids']

    cids = _convert_categories(categories)

    items = current_app.mongodb.\
        Commodity.find_live(cids, timestamp, store['sort_type'])
    p = make_paginator(items, paged, perpage)

    return attach_extend(
        [output_commodity(item) for item in items],
        {'_more': p.has_next, '_count': p.count}
    )
Пример #7
0
def search_commodities():
    paged = get_param('paged', Struct.Int, default=1)
    perpage = get_param('perpage', Struct.Int, default=60)
    keywords = get_param('keywords', Struct.List, default=[])
    timestamp = parse_int(get_args('timestamp'))
    categories = get_args('categories')

    store = g.store

    cids = _convert_categories(categories)

    paged = parse_int(paged, 1, 1)
    perpage = parse_int(perpage, 1, 1)

    if not keywords:
        return []
    items = current_app.mongodb.\
        Commodity.search(keywords, cids, timestamp, store['sort_type'])
    p = make_paginator(items, paged, perpage)

    return attach_extend(
        [output_commodity(item) for item in items],
        {'_more': p.has_next, '_count': p.count}
    )