Ejemplo n.º 1
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)
Ejemplo n.º 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)
Ejemplo n.º 3
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))
Ejemplo n.º 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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 10
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)
Ejemplo n.º 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.')
Ejemplo n.º 12
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.')