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)
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)
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))
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)
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)
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)
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))
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)
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)
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)
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.')
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.')