def magazines_id(id): try: magazine = Magazine.get(Magazine.id == id) except Magazine.DoesNotExist: return error('magazine does not exist', 404) return ok(dump_magazine(magazine))
def magazines_public(mid): try: magazine = Magazine.get(Magazine.id == mid) except Magazine.DoesNotExist: return error('magazine does not exist', 404) return render_template('magazine.html', magazine=dump_magazine(magazine))
def magazines_new(): json_data = request.get_json() title = json_data.get('title') if not all((title, )): return error('没有提供所有参数') magazine = Magazine.create_magazine(title=title) return ok(dump_magazine(magazine, mode='only_id'))
def magazines_id_delete(id): try: magazine = Magazine.get(Magazine.id == id) except Magazine.DoesNotExist: return error('magazine does not exist', 404) if magazine.posts.count(): return error('杂志中有文章,确定删除请先删除杂志中的内容') magazine.delete_instance() return ok()
def magazines_new(): json_data = request.get_json() title = json_data.get('title') if not all((title,)): return error('没有提供所有参数') magazine = Magazine.create_magazine( title=title) return ok(dump_magazine(magazine, mode='only_id'))
def magazines_id_update(id): try: magazine = Magazine.get(Magazine.id == id) except Magazine.DoesNotExist: return error('magazine does not exist', 404) json_data = request.get_json() title = json_data.get('title') if not all((title, )): return error('没有提供所有参数') magazine.update_magazine(title=title) return ok()
def magazines_id_update(id): try: magazine = Magazine.get(Magazine.id == id) except Magazine.DoesNotExist: return error('magazine does not exist', 404) json_data = request.get_json() title = json_data.get('title') if not all((title,)): return error('没有提供所有参数') magazine.update_magazine(title=title) return ok()
def dump_magazine_all(): magazines_data = [] magazines = Magazine.all() for magazine in magazines: magazines_data.append(dump_magazine(magazine)) return magazines_data