def save_article(cls, form): from models.chapter import Chapter article = Article.upsert({ 'chapter_id': int(form.get('chapter_id')), }, { 'title': form.get('title'), 'content': form.get('content'), }) Chapter.upsert({ 'id': article.chapter_id, }, { 'article_id': article.id, })
def add(): form = request.form if validate_legitimacy(form, request.cookies): query_form = { 'id': int(form.get('id')) } update_form = { 'subject_id': int(form.get('subject_id', -1)), 'name': form.get('name', ''), 'article_id': int(form.get('article_id')) if form.get('article_id') != '' else -1, } Chapter.upsert(query_form, update_form) return redirect(url_for('.index')) else: abort(403)