コード例 #1
0
ファイル: __init__.py プロジェクト: michaelliao/brighterpage
def edit_category():
    cat = Categories.get_by_id(ctx.request['_id'])
    return dict( \
        form_title='Edit Category', \
        form_action='/api/categories/%s/update' % cat._id, \
        name = cat.name, \
        description = cat.description)
コード例 #2
0
def edit_category():
    cat = Categories.get_by_id(ctx.request['_id'])
    return dict( \
        form_title='Edit Category', \
        form_action='/api/categories/%s/update' % cat._id, \
        name = cat.name, \
        description = cat.description)
コード例 #3
0
ファイル: __init__.py プロジェクト: michaelliao/brighterpage
def web_get_article(aid):
    article = Articles.get_by_id(aid)
    if article is None or article.draft:
        raise notfound
    article.reads = counters.incr(aid)
    article.content = texts.md2html(texts.get(article.content_id))
    category = Categories.get_by_id(article.category_id)
    return dict(article=article, category=category, comments=comments.get_comments(aid))
コード例 #4
0
def api_delete_category(cid):
    cat = Categories.get_by_id(cid)
    if cat is None:
        raise APIValueError('_id', 'category not found.')
    if len(Articles.select('where category_id=?', cat._id)) > 0:
        raise APIValueError('_id', 'cannot delete non-empty categories.')
    cat.delete()
    _clear_categories_cache()
    return dict(result=True)
コード例 #5
0
ファイル: __init__.py プロジェクト: michaelliao/brighterpage
def api_delete_category(cid):
    cat = Categories.get_by_id(cid)
    if cat is None:
        raise APIValueError('_id', 'category not found.')
    if len(Articles.select('where category_id=?', cat._id)) > 0:
        raise APIValueError('_id', 'cannot delete non-empty categories.')
    cat.delete()
    _clear_categories_cache()
    return dict(result=True)
コード例 #6
0
ファイル: __init__.py プロジェクト: michaelliao/brighterpage
def web_category(cid):
    category = Categories.get_by_id(cid)
    if category is None:
        raise notfound()
    page, articles = page_select(Articles, 'where category_id=? and publish_time<?', 'where category_id=? and publish_time<? order by publish_time desc', cid, time.time())
    reads = counters.counts((a._id for a in articles))
    for a, r in zip(articles, reads):
        a.reads = r
    return dict(category=category, page=page, articles=articles)
コード例 #7
0
def web_get_article(aid):
    article = Articles.get_by_id(aid)
    if article is None or article.draft:
        raise notfound
    article.reads = counters.incr(aid)
    article.content = texts.md2html(texts.get(article.content_id))
    category = Categories.get_by_id(article.category_id)
    return dict(article=article,
                category=category,
                comments=comments.get_comments(aid))
コード例 #8
0
def web_category(cid):
    category = Categories.get_by_id(cid)
    if category is None:
        raise notfound()
    page, articles = page_select(
        Articles, 'where category_id=? and publish_time<?',
        'where category_id=? and publish_time<? order by publish_time desc',
        cid, time.time())
    reads = counters.counts((a._id for a in articles))
    for a, r in zip(articles, reads):
        a.reads = r
    return dict(category=category, page=page, articles=articles)
コード例 #9
0
def api_update_category(cid):
    cat = Categories.get_by_id(cid)
    if cat is None:
        raise APIValueError('_id', 'category not found.')
    i = ctx.request.input()
    update = False
    if 'name' in i:
        cat.name = assert_not_empty(i.name.strip(), 'name')
        update = True
    if 'description' in i:
        cat.description = i.description.strip()
        update = True
    if update:
        cat.update()
        _clear_categories_cache()
    return dict(result=True)
コード例 #10
0
ファイル: __init__.py プロジェクト: michaelliao/brighterpage
def api_update_category(cid):
    cat = Categories.get_by_id(cid)
    if cat is None:
        raise APIValueError('_id', 'category not found.')
    i = ctx.request.input()
    update = False
    if 'name' in i:
        cat.name = assert_not_empty(i.name.strip(), 'name')
        update = True
    if 'description' in i:
        cat.description = i.description.strip()
        update = True
    if update:
        cat.update()
        _clear_categories_cache()
    return dict(result=True)
コード例 #11
0
def _check_category_id(cat_id):
    if cat_id:
        cat = Categories.get_by_id(cat_id)
        if cat:
            return cat_id
    raise APIValueError('category_id', 'Invalid category id.')
コード例 #12
0
ファイル: __init__.py プロジェクト: michaelliao/brighterpage
def _check_category_id(cat_id):
    if cat_id:
        cat = Categories.get_by_id(cat_id)
        if cat:
            return cat_id
    raise APIValueError('category_id', 'Invalid category id.')