def delete_blog(blog_id): """Delete blog. :param id: blog id. """ blog = api_blog.get(blog_id) if blog.user != current_user: return jsonres(rv=None, metacode=403, msg=u'这不是您的,你不能删除', code=403) api_blog.delete(api_blog.get_or_404(blog_id)) return jsonres()
def create_dongtan(): """""" blog_form = BlogForm(**request.json) blog_form.csrf_enabled = False del blog_form.captcha if blog_form.validate_on_submit(): blog = api_blog.create(user=current_user, **request.json) return jsonres(rv=dict(id=blog.id, title=blog.title, content=blog.content)) return jsonres(metacode=400, code=400, msg=blog_form.errors)
def delete_blogs(): """Delete blog. :param id: blog id. """ delIds = request.json for delId in delIds: blog = api_blog.get(delId) if blog.user != current_user: return jsonres(metacode=403, msg=u'有不是您的,不能删除', code=403) return jsonres()
def change_blog(blog_id): """Edit the blog. :param id: blog id. """ blog = api_blog.get(blog_id) if blog.user != current_user: return jsonres(rv=None, metacode=403, msg=u'这不是您的,你不能修改', code=403) blog_form = BlogUpdateForm() #json方式,不能验证csrf_token blog_form.csrf_enabled = False if blog_form.validate_on_submit(): api_blog.update(blog, **blog_form.data) return jsonres() #构造表单验证错误,返回 return jsonres(msg=blog_form.errors, metacode=400, code=400)
def handle_error(e): """Handler server errors for flask. """ # 500的系统错误需要回滚db,不然数据库状态不对 if e == 500: db.session.rollback() # 这个表示内容的是问题的,但是返回正常的协议。 return jsonres(rv=None, metacode=e.code, msg=str.format("{}: {}", e.name, e.description), code=e.code)
def list_dongtan(blogs_matrix=dict()): page = int(request.args.get('page', 1)); if page == None or page <= 0: page = 1 blogs = api_blog.get_latest_page_filterby(page=page, per_page=10, category_id=int(blogs_matrix.get('category', 0))) pageInfo = paginationInfo(blogs) #这个用在动弹里的 if blogs_matrix.get('showcontent'): blogdatas = [dict(id=blog.id, title=blog.title, content=blog.content, userid = blog.user_id, useravatar = blog.user.avatar or url_for('static', filename='/image/'), username = blog.user.validname(), create_at=mkmillseconds(blog.create_at)) for blog in blogs.items] else: blogdatas = [dict(id=blog.id, title=blog.title, create_at=mkmillseconds(blog.create_at)) for blog in blogs.items] return jsonres(rv=dict(pageInfo=pageInfo, datas=blogdatas))
def detail_blog(blog_id): blog = api_blog.get_or_404(blog_id) return jsonres(rv=dict(id=blog.id, title=blog.title, content=blog.content, create_at=mkmillseconds(blog.create_at)))
def delete_garage(): garage = apiGarageRent.get_or_404(id) apiGarageRent.delete(garage) return jsonres()
def close_garage(): """关闭发布 修改close状态而已""" garage = apiGarageRent.get_or_404(id) apiGarageRent.update(garage, close=True) return jsonres()
def create_garage(): form = GarageForm() if form.validate_on_submit(): apiGarageRent.create(publisher=current_user, **form.data) return jsonres() return jsonres(success=False, msg=u'创建失败')
def list_garage(): page = int(request.args.get('page', 1)) garages = apiGarageRent.get_lastest_page(page) page_info = paginationInfo(garages) carpools = [_garage_json(garage) for garage in garages.items] return jsonres(rv=dict(datas=carpools, pageInfo=page_info))