Ejemplo n.º 1
0
def new_question(question, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(question)
    db_session.commit()

    return QUESTION_ADD_OK
Ejemplo 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
Ejemplo n.º 3
0
def new_tag_follow(tag_follow):
    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
Ejemplo n.º 4
0
def edit_question(question, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(question)
    db_session.commit()

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

    db_session.add(resource)
    db_session.commit()

    return RESOURCE_ADD_OK
Ejemplo 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
Ejemplo n.º 7
0
def new_answer(resourceanswer):
    db_session.add(resourceanswer)

    resource = db_session.query(Resource).get(resourceanswer.resource_id)
    resource.answer_count += 1
    
    db_session.commit()
    return ANSWER_ADD_OK
Ejemplo n.º 8
0
def new_tag(tag):
    try:
        db_session.add(tag)
        db_session.commit()
        return TAG_ADD_OK
    except:
        db_session.rollback()
        return TAG_DUPLICATE    
Ejemplo n.º 9
0
def new_question(question, tags):
    db_session.begin()
    new_tags(tags)

    db_session.add(question)
    db_session.commit()

    return QUESTION_ADD_OK
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo n.º 13
0
def edit_user(user):
    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
Ejemplo n.º 14
0
def register_user(user):
    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
Ejemplo n.º 15
0
def new_resource_download(rd):
    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
Ejemplo n.º 16
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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo 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
Ejemplo n.º 21
0
def new_resource_mark(resource_mark):
    au = db_session.query(Resource_Mark).filter_by(resource_id=resource_mark.resource_id, 
                                                   user_id=resource_mark.user_id).first()
    if au:
        if resource_mark.mark_type == 'good' :
            return ANSWER_GOOD_DUPLICATE
        if resource_mark.mark_type == 'bad' :
            return ANSWER_BAD_DUPLICATE

    db_session.add(resource_mark)

    resorce = db_session.query(Resource).get(resource_mark.resource_id)
    if resource_mark.mark_type == 'good' :
        resorce.score += 1
        resorce.good += 1
        db_session.commit()
        return ANSWER_GOOD_ADD_OK
    elif resource_mark.mark_type == 'bad' :
        resorce.score -= 1
        resorce.bad += 1
        db_session.commit()
        return ANSWER_BAD_ADD_OK
Ejemplo n.º 22
0
def new_tag_edit(tag_edit):
    db_session.add(tag_edit)
    db_session.commit()
    return TAG_EDIT_ADD_OK
Ejemplo n.º 23
0
def new_comment(comment):
    db_session.begin()
    db_session.add(comment)
    db_session.commit()
    return COMMENT_ADD_OK
Ejemplo n.º 24
0
def new_comment(comment):
    db_session.begin()
    db_session.add(comment)
    db_session.commit()
    return COMMENT_ADD_OK
Ejemplo n.º 25
0
def new_resource_edit(resource_edit):
    db_session.add(resource_edit)
    db_session.commit()
    return RESOURCE_EDIT_ADD_OK
Ejemplo n.º 26
0
def new_remind(remind):
    db_session.begin()
    db_session.add(remind)
    db_session.commit()
    return REMIND_ADD_OK
Ejemplo n.º 27
0
def edit_res_remind(res_remind):
    db_session.add(res_remind)
    db_session.commit()
    return REMIND_EDIT_OK
Ejemplo n.º 28
0
def new_tag_edit(tag_edit):
    db_session.begin()
    db_session.add(tag_edit)
    db_session.commit()
    return TAG_EDIT_ADD_OK
Ejemplo n.º 29
0
def edit_tag(tag):
    db_session.begin()
    db_session.add(tag)
    db_session.commit()
    return TAG_EDIT_OK
Ejemplo n.º 30
0
def edit_tag(tag):
    db_session.add(tag)
    db_session.commit()
    return TAG_EDIT_OK
Ejemplo n.º 31
0
def edit_remind(remind):
    db_session.begin()
    db_session.add(remind)
    db_session.commit()
    return REMIND_EDIT_OK
Ejemplo 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
Ejemplo n.º 33
0
def new_question_edit(question_edit):
    db_session.begin()
    db_session.add(question_edit)
    db_session.commit()
    return QUESTION_EDIT_ADD_OK
Ejemplo n.º 34
0
def new_res_remind(res_remind):
    db_session.add(res_remind)
    db_session.commit()
    return REMIND_ADD_OK