def api_create_page(): i = ctx.request.input(alias='', name='', tags='', draft='', content='') alias = assert_not_empty(i.alias, 'alias').lower() if _RE_ALIAS.match(alias) is None: raise APIValueError('alias', 'Invalid alias.') if Pages.select_one('where alias=?', alias): raise APIValueError('alias', 'Alias already exist.') name = assert_not_empty(i.name, 'name') content = assert_not_empty(i.content, 'content') draft = i.draft.lower() == 'true' page_id = db.next_id() page = Pages( \ _id = page_id, \ alias = alias, \ content_id = texts.set(page_id, content), \ draft = draft, \ name = name, \ tags = texts.format_tags(i.tags) \ ).insert() return dict(_id=page._id)
def get_page(alias): page = Pages.select_one('where alias=?', alias) if page is None: raise notfound() page.content = texts.md2html(texts.get(page.content_id)) return dict(page=page)