def employees_id_put(id,body,jwt = None): try: if not Employee.check_valid({'id':id,'login_user':body.get('login_user')}): raise Exception('登录用户(%s)已被使用,请重新指定!'% body.get('login_user')) if type(id)!='int': id=int(id) Employee.check_dateformat(body) Employee.query.filter(Employee.id == id).update(body) except Exception as e: db.session.rollback() return {"error":str(e)}, 422, {"content-type": "chatset=utf8"} data = Employee.query.filter_by(id=id).first_or_404() # data.cids = ',' # for auth in data.company_auths: # data.cids += str(auth.companyid) + ',' return data.to_json(), 201, {"content-type": "chatset=utf8"}
def employees_post(body,jwt = None): try: if not Employee.check_valid({'id':None,'login_user':body.get('login_user')}): raise Exception('登录用户(%s)已被使用,请重新指定!'% body.get('login_user')) Employee.check_dateformat(body) if 'cids' in body: body.pop('cids') if 'departname' in body: body.pop('departname') if 'companyid' in body: body.pop('companyid') if 'departinsideid' in body: body.pop('departinsideid') data = Employee(**body) db.session.add(data) db.session.commit() # data.cids = ',' # for auth in data.company_auths: # data.cids += str(auth.companyid) + ',' except Exception as e: db.session.rollback() return {"error": str(e)}, 422, {"content-type": "chatset=utf8"} return data.to_json(), 201, {"content-type": "chatset=utf8"}