def api_blogs(*,page='1'): print(1) page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') p = Page(num,page_index) if num==0: return dict(page=p,blogs=()) blogs = yield from Blog.findAll(orderBy='created_at desc',limit=(p.offset,p.limit)) return dict(page=p,blogs=blogs)
def api_blogs(*, page='1'): page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') p = Page(num, page_index) if num == 0: return dict(page=p, blogs=()) blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(p.offset, p.limit)) return dict(page=p, blogs=blogs)
def index(*, page='1'): page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') page = Page(num, page_index) if num == 0: blogs = [] else: blogs = yield from Blog.findAll(orderBy='created_at desc', limit=(page.offset, page.limit)) return {'__template__': 'blogs.html', 'page': page, 'blogs': blogs}
def api_create_blog(request, *, name, summary, content): check_admin(request) if not name or not name.strip(): raise APIValueError('name','name cannot be empty') if not summary or not summary.strip(): raise APIValueError('summary','summary cannot be empty') if not content or not content.strip(): raise APIValueError('content','content connot be empty') blog = Blog(user_id = request.__user__.id,user_name = request.__user__.name,user_image = request.__user__.image,name = name.strip(),summary=summary.strip(),content=content.strip()) yield from blog.save() return blog
def index(*,page='1'): page_index = get_page_index(page) num = yield from Blog.findNumber('count(id)') page=Page(num,page_index) if num==0: blogs=[] else: blogs= yield from Blog.findAll(orderBy='created_at desc',limit=(page.offset,page.limit)) return { '__template__':'blogs.html', 'page':page, 'blogs':blogs }
def api_create_blog(request, *, name, summary, content): check_admin(request) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) yield from blog.save() return blog
def api_delete_blog(request, *, id): check_admin(request) blog = yield from Blog.find(id) if blog is None: raise APIResourceNotFoundError('Blog') yield from blog.remove() return dict(id=id)
def get_blog(id): blog = yield from Blog.find(id) comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc') for c in comments: c.html_content = text2html(c.content) blog.html_content = markdown2.markdown(blog.content) return {'__template__': 'blog.html', 'blog': blog, 'comments': comments}
def index(request): summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, ' \ 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' blogs = [ Blog(id='1', name='Test Blog', summary=summary, created_at=time.time() - 120), Blog(id='2', name='Something New', summary=summary, created_at=time.time() - 3600), Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time() - 7200), ] return {'__template__': 'blogs.html', 'blogs': blogs}
def get_blog(id): blog=yield from Blog.find(id) comments=yield from Comment.findAll('blog_id=?',[id],orderBy='created_at desc') for c in comments: c.html_content = text2html(c.content) blog.html_content = markdown2.markdown(blog.content) return { '__template__':'blog.html', 'blog':blog, 'comments':comments }
async def api_create_blog(request, *, name, summary, content): helper.check_user( request.__user__) # request.__user__是从拦截器auth_factory中绑定后传递到此handler helper.check_string(name=name, summary=summary, content=content) blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) await blog.save() return blog
def api_create_comment(id,request,*,content): user = request.__user__ if user is None: raise APIValueError('Please signin first') if not content or not content.strip(): raise APIValueError('Please content first') blog = yield from Blog.find(id) if blog is None: raise APIresourceNotFundError('not find Blog') comment = Comment(blog_id=blog.id,user_id=user.id,user_name=user.name,user_image=user.image,content=content.strip()) yield from comment.save() return comment
def api_create_comment(id, request, *, content): user = request.__user__ if user is None: raise APIPermissionError('Please signin first') if not content or not content.strip(): raise APIValueError('content') blog = yield from Blog.find(id) if blog is None: raise APIResourceNotFoundError('Blog') comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip()) yield from comment.save() return comment
def api_update_blog(id, request, *, name, summary, content): check_admin(request) blog = yield from Blog.find(id) if blog is None: raise APIResourceNotFoundError('Blog') if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty.') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') blog.name = name.strip() blog.summary = summary.strip() blog.content = content.strip() yield from blog.update() return blog
def api_update_blog(id,request,*,name,summary,content): check_admin(request) blog = yield from Blog.find(id) if not name or not name.strip(): raise APIValueError('name','name cannot be empty.') if not summary or not summary.strip(): raise APIValueError('summary','summary cannot be empty') if not content or not content.strip(): raise APIValueError('content','content cannot be empty') blog.name = name.strip() blog.summary = summary.strip() blog.content = content.strip() yield from blog.update() return blog
def api_get_blog(*,id): blog=yield from Blog.find(id) return blog
def api_get_blog(*, id): blog = yield from Blog.find(id) return blog
def api_delete_blog(request, *, id): check_admin(request) blog = yield from Blog.find(id) yield from blog.remove() return dict(id=id)