Ejemplo n.º 1
0
def index():
    """
    关键词管理首页, 列举站点级别的关键词, 并支持简单查询和翻页.
    """
    s = request.args.get('status', u'bare,processed,repeated')
    k = request.args.get('keyword', '')
    o = request.args.get('owner', '')
    p = int(request.args.get('page', '1'))
    start = (p - 1) * PAGE_COUNT

    condition = {'level': KeywordLevel.SITE}
    if k:
        condition['name'] = k.strip()
    if o:
        condition['owner'] = o.strip()
    status = s.split(u',')
    if status:
        condition['status'] = {'$in': status}

    count = Keyword.count(condition)
    cursor = Keyword.find(condition, skip=start, limit=PAGE_COUNT, sort=[('baiduIndex', pymongo.DESCENDING)])
    keywords = []
    for c in cursor:
        set_index(c)
        keywords.append(c)
    pagination = Pagination(p, PAGE_COUNT, count)
    return render_template('seo/index.html', keywords=keywords, pagination=pagination)
Ejemplo n.º 2
0
def longtail(keyword_id):
    """
    获取指定站点关键字下的长尾关键字.
    """
    keyword = Keyword.find_one({'_id': keyword_id})
    if not keyword:
        abort(404)

    s = request.args.get('status', u'bare,processed,repeated')
    p = int(request.args.get('page', '1'))
    start = (p - 1) * PAGE_COUNT
    condition = {'level': KeywordLevel.LONG_TAIL, 'parentId': keyword_id}
    status = s.split(u',')
    if status:
        condition['status'] = {'$in': status}

    count = Keyword.count(condition)
    cursor = Keyword.find(condition, skip=start, limit=PAGE_COUNT, sort=[('baiduIndex', pymongo.DESCENDING)])
    keywords = []
    for c in cursor:
        keywords.append(c)
    pagination = Pagination(p, PAGE_COUNT, count)

    return render_template('seo/longtail.html', keyword=keyword, keywords=keywords, pagination=pagination)