def api_feedback_add_to_note(kind,model,id,username): if request.method == 'POST': account = Account.query.filter_by(username=username).first() target = Feedback.resolve_target(model,id) print "adding feedback [%s] about [%s]" % (kind, target) if target and account: content = request.form.get('content','') table_name = target.__class__.__name__ row_id = id feedback = Feedback(account.id, kind, content, table_name, row_id) db.session.add(feedback) db.session.commit() return success(feedback.to_hash()) return error("something wrong") else: return error("add feedback to note [%s] by [%s], this operation must be done through a post" % (id, username))
def api_feedback_add_to_media(id,username): if request.method == 'POST': media = Media.query.get(id) account = Account.query.filter_by(username=username).first() if media and account and 'content' in request.form: kind = "Comment" content = request.form['content'] table_name = "Media" row_id = id feedback = Feedback(account.id, kind, content, table_name, row_id) db.session.add(feedback) db.session.commit() return success(feedback.to_hash()) return success({'success': False}) else: return error("add feedback to media [%s] by [%s], this operation must be done through a post" % (id, username))