def edit_question_tags(qid, tags): db_session.begin() new_tags(tags) db_session.query(Question_Tag).filter_by(question_id=qid).delete() db_session.add_all([Question_Tag(qid, tag) for tag in tags]) db_session.commit() return QUESTION_TAG_EDIT_OK
def new_resource(resource, tags): db_session.begin() new_tags(tags) db_session.add(resource) db_session.commit() return RESOURCE_ADD_OK
def edit_question(question, tags): db_session.begin() new_tags(tags) db_session.add(question) db_session.commit() return QUESTION_EDIT_OK
def new_question(question, tags): db_session.begin() new_tags(tags) db_session.add(question) db_session.commit() return QUESTION_ADD_OK
def edit_question_tags(qid, tags): db_session.begin() new_tags(tags) db_session.query(Question_Tag).filter_by(question_id=qid).delete() db_session.add_all([Question_Tag(qid,tag) for tag in tags]) db_session.commit() return QUESTION_TAG_EDIT_OK
def new_tag_follow(tag_follow): db_session.begin() tf = db_session.query(Tag_Follow).filter_by(user_id=tag_follow.user_id, tag=tag_follow.tag).first() if tf: return TAG_FOLLOW_DUPLICATE db_session.add(tag_follow) db_session.commit() return TAG_FOLLOW_ADD_OK
def new_answer(answer): db_session.begin() db_session.add(answer) question = db_session.query(Question).get(answer.question_id) question.answer_count += 1 db_session.commit() return ANSWER_ADD_OK
def edit_user(user): db_session.begin() u = get_user_by_email(user.email) if u and u.id != user.id: return USER_EMAIL_DUPLICATE u = get_user_by_name(user.nickname) if u and u.id != user.id: return USER_NICKNAME_DUPLICATE db_session.add(user) db_session.commit() return USER_EDIT_OK
def register_user(user): db_session.begin() if get_user_by_email(user.email): return USER_DUPLICATE if get_user_by_name(user.nickname): return USER_DUPLICATE db_session.add(user) db_session.commit() login_user(user, remember=True) return USER_REGISTER_OK
def new_resource_download(rd): db_session.begin() download = db_session.query(Resource_Download).filter_by( resource_id=rd.resource_id, user_id=rd.user_id).first() if download: return RESOURCE_DOWNLOAD_DUPLICATE db_session.add(rd) resource = db_session.query(Resource).get(rd.resource_id) resource.download_count += 1 db_session.commit() return RESOURCE_DOWNLOAD_ADD_OK
def new_resource_download(rd): db_session.begin() download = db_session.query(Resource_Download).filter_by(resource_id=rd.resource_id, user_id=rd.user_id).first() if download: return RESOURCE_DOWNLOAD_DUPLICATE db_session.add(rd) resource = db_session.query(Resource).get(rd.resource_id) resource.download_count += 1 db_session.commit() return RESOURCE_DOWNLOAD_ADD_OK
def new_answer_up(answer_up): db_session.begin() au = db_session.query(Answer_Up).filter_by(answer_id=answer_up.answer_id, user_id=answer_up.user_id).first() if au: return ANSWER_UP_DUPLICATE db_session.add(answer_up) anwser = db_session.query(Answer).get(answer_up.answer_id) anwser.up += 1 db_session.commit() return ANSWER_UP_ADD_OK
def new_answer_up(answer_up): db_session.begin() au = db_session.query(Answer_Up).filter_by( answer_id=answer_up.answer_id, user_id=answer_up.user_id).first() if au: return ANSWER_UP_DUPLICATE db_session.add(answer_up) anwser = db_session.query(Answer).get(answer_up.answer_id) anwser.up += 1 db_session.commit() return ANSWER_UP_ADD_OK
def new_question_edit(question_edit): db_session.begin() db_session.add(question_edit) db_session.commit() return QUESTION_EDIT_ADD_OK
def new_comment(comment): db_session.begin() db_session.add(comment) db_session.commit() return COMMENT_ADD_OK
def del_tag_follow(tag_follow): db_session.begin() db_session.query(Tag_Follow).filter_by(user_id=tag_follow.user_id, tag=tag_follow.tag).delete() db_session.commit() return TAG_FOLLOW_DEL_OK
def new_tag_edit(tag_edit): db_session.begin() db_session.add(tag_edit) db_session.commit() return TAG_EDIT_ADD_OK
def edit_tag(tag): db_session.begin() db_session.add(tag) db_session.commit() return TAG_EDIT_OK
def edit_remind(remind): db_session.begin() db_session.add(remind) db_session.commit() return REMIND_EDIT_OK
def new_remind(remind): db_session.begin() db_session.add(remind) db_session.commit() return REMIND_ADD_OK
def del_tag_follow(tag_follow): db_session.begin() db_session.query(Tag_Follow).filter_by(user_id=tag_follow.user_id,tag=tag_follow.tag).delete() db_session.commit() return TAG_FOLLOW_DEL_OK