示例#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 visit_remove_comment(group_key, comment_id):
    Struct.ObjectId(comment_id, 'comment_id')

    author_id = get_args('author_id')
    author_token = get_args('author_token')

    if not author_id:
        author_id = _get_default_author_id()

    comment = _visit_get_comment(comment_id, group_key)

    if not comment['anonymous']:
        pass
        # todo
        # verify member
    elif author_id != comment['author_id']:
        raise CommentNotAuthor

    comment.delete()

    return {
        "id": comment_id,
        "updated": now(),
        "deleted": 1,
    }
示例#3
0
def visit_remove_comment(group_key, comment_id):
    Struct.ObjectId(comment_id, 'comment_id')

    author_id = get_args('author_id')
    author_token = get_args('author_token')

    if not author_id:
        author_id = _get_default_author_id()

    comment = _visit_get_comment(comment_id, group_key)

    if not comment['anonymous']:
        pass
        # todo
        # verify member
    elif author_id != comment['author_id']:
        raise CommentNotAuthor

    comment.delete()

    return {
        "id": comment_id,
        "updated": now(),
        "deleted": 1,
    }
示例#4
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
    })
示例#5
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
                         })
示例#6
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
                         })
示例#7
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
    })
示例#8
0
def visit_get_comment(group_key, comment_id):
    Struct.ObjectId(comment_id, 'comment_id')

    author_id = get_args('author_id')
    comment = _visit_get_comment(comment_id, group_key)

    return output_comment(comment, author_id)
示例#9
0
def visit_get_comment(group_key, comment_id):
    Struct.ObjectId(comment_id, 'comment_id')

    author_id = get_args('author_id')
    comment = _visit_get_comment(comment_id, group_key)

    return output_comment(comment, author_id)
示例#10
0
def get_view_segments(app_id):
    content_type = get_args('content_type', default='page')
    parent = get_args('parent', default='index')

    app = g.curr_app

    results = query_segments(app, content_type, parent)
    pages = []
    for p in results:
        p_content = p.get('content', u'')
        p = parse_page_metas(p)
        p['content'] = parse_page_content(p_content)
        pages.append(p)

    run_hook('get_pages', pages=pages, current_page_id=None)

    return pages
示例#11
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}
    )
示例#12
0
def get_view_content_list(app_id, type_slug=u'page'):
    perpage = get_args('perpage', default=0)
    paged = get_args('paged', default=0)
    sortby = get_args('sortby', default='', multiple=True)
    priority = get_args('priority', default=True)
    term = get_args('term')
    tag = get_args('tag')

    priority = bool(priority)

    theme_opts = g.curr_app['theme_meta'].get('options', {})

    # set default params
    if not sortby:
        sortby = theme_opts.get('sortby', 'updated')
        if isinstance(sortby, basestring):
            sortby = [sortby]
        elif not isinstance(sortby, list):
            sortby = []

    if not perpage:
        perpage = theme_opts.get('perpage')

    perpage, paged = _safe_paging(perpage, paged)

    # position
    limit = perpage
    offset = max(perpage * (paged - 1), 0)

    # query content files
    results, total_count = query_by_files(content_type=type_slug,
                                          term=term,
                                          tag=tag,
                                          offset=offset,
                                          limit=limit,
                                          sortby=sortby)
    curr_index = offset

    pages = []
    for p in results:
        p = parse_page_metas(p)
        pages.append(p)
    run_hook('get_pages', pages=pages, current_page_id=None)

    max_pages = max(int(math.ceil(total_count / float(perpage))), 1)

    for p in pages:
        _add_cursor(content=p,
                    index=curr_index,
                    perpage=perpage,
                    paged=paged,
                    total_pages=max_pages,
                    total_count=total_count)
        curr_index += 1

    return pages
示例#13
0
def list_item_coupons():
    paged = parse_int(get_args('paged'), 1, 1)
    perpage = parse_int(get_args('perpage'), 60, 1)
    categories = get_args('categories')

    if categories:
        perpage = _safe_perpage(paged, perpage)
    else:
        perpage = _safe_perpage(paged, perpage, limit=10000)

    if perpage <= 0:
        return []

    taoke = connect_taoke()

    try:
        coupons = taoke.list_coupons(categories=categories,
                                     paged=paged,
                                     perpage=perpage)
    except Exception as e:
        current_app.logger.error(StoreCouponError(e))
        coupons = []

    return [output_coupon(coupon) for coupon in coupons]
示例#14
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}
    )
示例#15
0
def index():
    paged = parse_int(get_args('paged'), 1, True)
    last_filename = get_args('last')
    commodities = current_app.mongodb.Commodity.find_all()
    activities = current_app.mongodb.Activity.find_all()

    p = make_paginator(commodities, paged, 60)
    prev_url = url_for(request.endpoint, paged=p.previous_page)
    next_url = url_for(request.endpoint, paged=p.next_page)

    paginator = {
        'next': next_url if p.has_next else None,
        'prev': prev_url if p.has_previous and p.previous_page else None,
        'paged': p.current_page,
        'start': p.start_index,
        'end': p.end_index,
        'count': p.count,
    }
    if last_filename:
        flash('Last file is: {}'.format(last_filename))
    return render_template('commodities.html',
                           commodities=commodities,
                           activities=activities,
                           p=paginator)
示例#16
0
def get_view_category(app_id):
    term_keys = get_args('term_keys', default=False, multiple=True)
    return {
        'category': helper_wrap_category(g.curr_app, term_keys)
    }
示例#17
0
def visit_get_group_comments(group_key):
    author_id = get_args('author_id')
    comments = _visit_get_comments(group_key)

    return [output_comment(comment, author_id) for comment in comments]
示例#18
0
def visit_get_group_comments(group_key):
    author_id = get_args('author_id')
    comments = _visit_get_comments(group_key)

    return [output_comment(comment, author_id) for comment in comments]