コード例 #1
0
ファイル: class.py プロジェクト: ownyang/Spark
def create(para):
    classTime = datetime.datetime.strptime(para["classTime"], "%Y-%m-%d")

    r = model.Class.Class(classTime=classTime)

    if "volunteerId" in para:
        r["volunteerId"] = para["volunteerId"]

    if "createTime" in para:
        r["createTime"] = para["createTime"]

    r["isFeedback"] = 0
    r["classBehavior"] = ""
    r["classContent"] = ""
    r["improvements"] = ""
    r["changes"] = ""
    r["notes"] = ""

    try:
        db.session.add(r)
        db.session.commit()
        return 0, 'sucess', []
    except Exception as e:
        db.session.rollback()
        print(e)
        mylogger.info(e)
        return 500, 'db fail', []
コード例 #2
0
def add(para):
    wxOpenId = str(para["wxOpenId"])
    name = para["name"]
    r = model.Student.Student(wxOpenId=wxOpenId, name=name)
    fields = r.getFields()
    for f in fields:
        if f in para:
            r[f] = para[f]
    try:
        db.session.add(r)
        db.session.commit()
        p = {"wxOpenId": wxOpenId, "role": "student"}
        handler.user.update(p)
        return 0, 'sucess', []
    except Exception as e:
        db.session.rollback()
        print(e)
        mylogger.info(e)
        return 500, 'db fail', []
コード例 #3
0
def update(para):
    id = para["id"]

    req = db.session.query(model.Volunteer.Volunteer).filter_by(id=id)

    update = {}
    v = req.first()
    if v is None:
        return 404, 'id not exist', []
    fields = v.getFields()
    for field in fields:
        if field in para and field not in ("id", "wxOpenId"):
            update[field] = para[field]
    try:
        req.update(update)
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        print(e)
        mylogger.info(e)
        return 500, "db fail", []

    return 0, 'sucess', None
コード例 #4
0
ファイル: class.py プロジェクト: ownyang/Spark
def feedback(para):
    studentId = para["studentId"]
    classId = para["classId"]

    req = db.session.query(model.ClassStudent.ClassStudent).filter_by(
        classId=classId).filter_by(studentId=studentId)

    update = {}
    v = req.first()
    if v is None:
        return 404, 'id not exist', []
    fields = v.getFields()
    for field in fields:
        if field in para and field not in ("studentId", "classId"):
            update[field] = para[field]
    try:
        req.update(update)
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        mylogger.info(e)
        return 500, "db fail", []

    return 0, 'sucess', None
コード例 #5
0
ファイル: class.py プロジェクト: ownyang/Spark
def get(para):
    cond = " 1 = 1"
    if "id" in para:
        id = int(para['id'])
        cond = cond + " and id={0}".format(id)
    if "volunteerId" in para:
        volunteerId = int(para['volunteerId'])
        cond = cond + " and volunteerId={0}".format(volunteerId)
    if "begin" in para:
        begin = mydb.escape_string(para['begin'])
        cond = cond + " and classTime >= '{0}'".format(begin)
    if "end" in para:
        end = mydb.escape_string(para['end'])
        cond = cond + " and classTime <= '{0}'".format(end)
    sql = "select id,  volunteerId, classTime, isFeedback, classBehavior, classContent, improvements, changes, notes from tClass where " + cond + " order by classTime desc "
    mylogger.info(sql)

    if "limit" in para:
        offset = int(para['offset']) if 'offset' in para else 0
        limit = int(para['limit'])
        sql = sql + " limit {0}, {1}".format(offset, limit)

    try:
        volIds = []
        cur = db.session.execute(sql)
        res = cur.fetchall()
        l = []
        mylogger.info(res)
        for i in res:
            r = {}
            id = r["id"] = i["id"]
            #r["name"] = i["name"]
            r["volunteerId"] = i["volunteerId"]
            r["classTime"] = i["classTime"].strftime("%Y-%m-%d")
            r["isFeedback"] = i['isFeedback']
            r["classBehavior"] = i["classBehavior"]
            r["classContent"] = i["classContent"]
            r["improvements"] = i["improvements"]
            r["changes"] = i["changes"]
            r["notes"] = i["notes"]
            r["volunteerName"] = ""
            r["volunteerOpenId"] = ""
            l.append(r)
            if i['volunteerId'] and i['volunteerId'] > 0:
                volIds.append(i['volunteerId'])

        #get volunteer info
        code, volInfos = model.Volunteer.Volunteer.getInfoById(volIds)
        if code == 0 and len(volInfos.keys()) > 0:
            for i in l:
                if i["volunteerId"] in volInfos:
                    volId = i["volunteerId"]
                    i['volunteerOpenId'] = volInfos[volId]["wxOpenId"]
                    i['volunteerName'] = volInfos[volId]["name"]
        '''
        #get student info
        for i in l:
            res=db.session.query(model.ClassStudent.ClassStudent).filter_by(classId=id).all()
            sids=[]
            for j in res:
                sids.append(j['studentId'])
            if len(sids)>0:
                code, sinfos=model.Student.Student.getInfoById(sids)
            if code==0 and len(sids) > 0 and sInfos and  len(sInfos.keys())>0:
                for j in sids:
                    sid=j
                    if sid in sinfos:
                        i['studentName']=sinfos[sid]['name']
        '''
    except Exception as e:
        db.session.rollback()
        raise e
    db.session.commit()

    return 0, 'ok', l