Example #1
0
def rel_create():
    if request.method == "POST" and request.form['user_id'] and request.form['username']:
        user = db_session.query(User).filter_by(username=request.form['username']).first() 
        if user is None:
            return jsonify(error=1, code='empty', message='用户名不存在')
        user_relations = db_session.query(UserRelation).filter_by(from_user_id=request.form['user_id']).filter_by(to_user_id=user.id).first()
        if user_relations is None:
            from_user = db_session.query(User).get(request.form['user_id'])
            rel = UserRelation(from_user_id=request.form['user_id'], to_user_id=user.id, status=0, from_user_name=from_user.username, to_user_name=request.form['username'])
            db_session.add(rel)
            db_session.commit()
            return jsonify(error=0, code='success', from_user_id=rel.from_user_id, to_user_id=rel.to_user_id, status=rel.status)

        return jsonify(error=0, code='success', from_user_id=request.form['user_id'], to_user_id=user_relations.to_user_id, status=user_relations.status)
    return jsonify(error=1, code='failed', message='参数传递不正确')
Example #2
0
def rel_get():
    if request.method == 'POST':
        if request.form.has_key('user_id') and request.form.has_key('status'):
            #rows = db_session.query(UserRelation).filter(or_(UserRelation.from_user_id==request.form['user_id'],UserRelation.to_user_id==request.form['user_id'])).filter_by(status=request.form['status']).all()
            rows = db_session.query(UserRelation,User).filter(User.id==UserRelation.to_user_id).filter(and_(UserRelation.from_user_id==request.form['user_id'],UserRelation.status==request.form['status'])).all()
            data = [ dict(user.to_json().items() + user_rel.to_json().items())  for user_rel, user in rows]
            rows2 = db_session.query(UserRelation,User).filter(User.id==UserRelation.from_user_id).filter(and_(UserRelation.to_user_id==request.form['user_id'],UserRelation.status==request.form['status'])).all()
            data_to = [ dict(user.to_json().items() + user_rel.to_json().items())  for user_rel, user in rows2]
            return jsonify(error=0, data=data, data_to=data_to)

        if request.form.has_key('to_user_id') and request.form.has_key('status'):
            rows = db_session.query(UserRelation).filter_by(to_user_id=request.form['to_user_id']).filter_by(status=request.form['status']).all() 
        elif request.form.has_key('from_user_id') and request.form.has_key('status'):
            rows = db_session.query(UserRelation).filter_by(from_user_id=request.form['from_user_id']).filter_by(status=request.form['status']).all() 

        data = [row.to_json() for row in rows]
        return jsonify(error=0, data=data)
Example #3
0
def task_delete():
    if request.method == 'POST' and request.form['id'] and request.form['user_id']:
        task = db_session.query(Task).get(request.form['id']) 
        if task and task.user_id == int(request.form['user_id']) :
            db_session.delete(task)
            db_session.commit()
            return jsonify(error=0, code='success', message='删除成功', id=task.id)

    return jsonify(error=1, code='failed', message='删除失败')
Example #4
0
def rel_update():
    if request.method == 'POST' and request.form['id'] and request.form['user_id']:
        rel = db_session.query(UserRelation).get(request.form['id'])
        if rel and rel.to_user_id == int(request.form['user_id']):
            if request.form.has_key('status'):
                rel.status = request.form['status']
            db_session.commit()
            return jsonify(error=0, code='success', from_user_id=rel.from_user_id, to_user_id=rel.to_user_id, status=rel.status)
    
    return jsonify(error=1, code='failed', message='参数传递不正确')
Example #5
0
def task_update():
    if request.method == 'POST' and request.form['id']:
        task = db_session.query(Task).get(request.form['id']) 
        if task:
            if request.form.has_key('status') : 
                task.status = request.form['status']
            if request.form.has_key('title'):
                task.title = request.form['title']
            if request.form.has_key('note'):
                task.note = request.form['note']
            if request.form.has_key('priority'):
                task.priority = request.form['priority']
            if request.form.has_key('end_time'):
                task.end_time = request.form['end_time']
            if request.form.has_key('to_user_id'):
                task.to_user_id = request.form['to_user_id']
            if request.form.has_key('description'):
                task.description = request.form['description']
            db_session.commit()
            return jsonify(error=0, code='success', message='修改成功', id=task.id)
    
    return jsonify(error=1, code='failed', message='修改失败')