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 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 edit_resource_tags(rid, tags): new_tags(tags) db_session.query(Resource_Tag).filter_by(resource_id=rid).delete() db_session.add_all([Resource_Tag(rid,tag) for tag in tags]) db_session.commit() return RESOURCE_TAG_EDIT_OK
def new_tags(tags): ts = db_session.query(Tag.tag).filter(Tag.tag.in_(tags)).all() ts = [t[0] for t in ts] db_session.add_all([Tag(t) for t in tags if t not in ts]) return TAG_ADD_OK