def school_add(): city_id = request.values.get('cityid',None) name = request.values.get('name',None) if not city_id or not name: return f.failed(*const.INVALID_PARAMS) school = f.load_school_by_name(name,city_id) if school: return f.failed(*const.SCHOOL_EXIST) school = School(city_id = city_id, name = name, created = int(time.time()*1000), updated = int(time.time()*1000)) m.session.add(school) m.session.commit() return f.succeed(school.tojson())
def school_add(): city_id = request.values.get('cityid', None) name = request.values.get('name', None) if not city_id or not name: return f.failed(*const.INVALID_PARAMS) school = f.load_school_by_name(name, city_id) if school: return f.failed(*const.SCHOOL_EXIST) school = School(city_id=city_id, name=name, created=int(time.time() * 1000), updated=int(time.time() * 1000)) m.session.add(school) m.session.commit() return f.succeed(school.tojson())
def school_update(): school_id = request.values.get('schoolid', None) name = request.values.get('name', None) if not school_id or not name: return f.failed(*const.INVALID_PARAMS) school = m.session.query(School).filter(School.id == school_id).first() if not school: return f.failed(*const.SCHOOL_NOT_EXIST) if school.name == name: return f.failed(*const.INVALID_PARAMS) hasSchool = f.load_school_by_name(name, school.city_id) if hasSchool: return f.failed(*const.SCHOOL_NOT_EXIST) school.name = name school.updated = time.time() * 1000 m.session.commit() return f.succeed(school.tojson())
def school_update(): school_id = request.values.get('schoolid',None) name = request.values.get('name',None) if not school_id or not name: return f.failed(*const.INVALID_PARAMS) school = m.session.query(School).filter(School.id == school_id).first() if not school: return f.failed(*const.SCHOOL_NOT_EXIST) if school.name == name: return f.failed(*const.INVALID_PARAMS) hasSchool = f.load_school_by_name(name,school.city_id) if hasSchool: return f.failed(*const.SCHOOL_NOT_EXIST) school.name = name school.updated = time.time()*1000 m.session.commit() return f.succeed(school.tojson())