Exemplo n.º 1
0
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
Exemplo n.º 2
0
def new_resource(resource, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(resource)
    db_session.commit()

    return RESOURCE_ADD_OK
Exemplo n.º 3
0
def edit_question(question, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(question)
    db_session.commit()

    return QUESTION_EDIT_OK
Exemplo n.º 4
0
def new_resource(resource, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(resource)
    db_session.commit()

    return RESOURCE_ADD_OK
Exemplo n.º 5
0
def new_question(question, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(question)
    db_session.commit()

    return QUESTION_ADD_OK
Exemplo n.º 6
0
def edit_question(question, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(question)
    db_session.commit()

    return QUESTION_EDIT_OK
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def new_question(question, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(question)
    db_session.commit()

    return QUESTION_ADD_OK
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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
Exemplo n.º 11
0
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
Exemplo n.º 12
0
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
Exemplo n.º 13
0
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
Exemplo n.º 14
0
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
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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
Exemplo n.º 17
0
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
Exemplo n.º 18
0
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
Exemplo n.º 19
0
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
Exemplo n.º 20
0
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
Exemplo n.º 21
0
def new_question_edit(question_edit):
    db_session.begin()
    db_session.add(question_edit)
    db_session.commit()
    return QUESTION_EDIT_ADD_OK
Exemplo n.º 22
0
def new_comment(comment):
    db_session.begin()
    db_session.add(comment)
    db_session.commit()
    return COMMENT_ADD_OK
Exemplo n.º 23
0
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
Exemplo n.º 24
0
def new_tag_edit(tag_edit):
    db_session.begin()
    db_session.add(tag_edit)
    db_session.commit()
    return TAG_EDIT_ADD_OK
Exemplo n.º 25
0
def new_comment(comment):
    db_session.begin()
    db_session.add(comment)
    db_session.commit()
    return COMMENT_ADD_OK
Exemplo n.º 26
0
def edit_tag(tag):
    db_session.begin()
    db_session.add(tag)
    db_session.commit()
    return TAG_EDIT_OK
Exemplo n.º 27
0
def edit_remind(remind):
    db_session.begin()
    db_session.add(remind)
    db_session.commit()
    return REMIND_EDIT_OK
Exemplo n.º 28
0
def new_remind(remind):
    db_session.begin()
    db_session.add(remind)
    db_session.commit()
    return REMIND_ADD_OK
Exemplo n.º 29
0
def edit_tag(tag):
    db_session.begin()
    db_session.add(tag)
    db_session.commit()
    return TAG_EDIT_OK
Exemplo n.º 30
0
def new_tag_edit(tag_edit):
    db_session.begin()
    db_session.add(tag_edit)
    db_session.commit()
    return TAG_EDIT_ADD_OK
Exemplo n.º 31
0
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
Exemplo n.º 32
0
def new_question_edit(question_edit):
    db_session.begin()
    db_session.add(question_edit)
    db_session.commit()
    return QUESTION_EDIT_ADD_OK