def school_list(): city = request.values.get('city',None) query = m.session.query(School) if city: query = query.outerjoin(City,School.city_id == City.id).filter(City.name == city) schools = query.order_by(desc(School.name)).all() schools = map(lambda x:x.tojson(),schools) return f.succeed(schools)
def upload_html5(): if request.method == 'POST': file = request.files['pic'] print file if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(const.UPLOAD_FOLDER, filename)) return f.succeed({'status':'done'})
def school_list(): city = request.values.get('city', None) query = m.session.query(School) if city: query = query.outerjoin( City, School.city_id == City.id).filter(City.name == city) schools = query.order_by(desc(School.name)).all() schools = map(lambda x: x.tojson(), schools) return f.succeed(schools)
def upload_attachment(): file = request.files.get('file') if not file: name = request.args.get('name') file = FileStorage(request.stream, filename=name, name=name, headers=request.headers) if file: fh = FileHelper(file) fh.save() if fh.savepath: return f.succeed({'filepath':fh.savepath}) return f.failed(*const.UPLOAD_FAIL)
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 upload_attachment(): file = request.files.get('file') if not file: name = request.args.get('name') file = FileStorage(request.stream, filename=name, name=name, headers=request.headers) if file: fh = FileHelper(file) fh.save() if fh.savepath: return f.succeed({'filepath': fh.savepath}) return f.failed(*const.UPLOAD_FAIL)
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())
def glodon_svg_prop(): geom_id = request.values.get('geom_id',None) return f.succeed({'geom_id':geom_id,'random':''.join([choice(string.digits) for i in range(0,9)])})
def city_list(): cities = m.session.query(City).all() cities = map(lambda x: x.tojson(), cities) return f.succeed(cities)
def delete_attachment(): filepath = request.form.get('filepath',None) if not filepath: return f.failed(*const.INVALID_PARAMS) os.remove(filepath) return f.succeed('ok')
def city_list(): cities = m.session.query(City).all() cities = map(lambda x:x.tojson(),cities) return f.succeed(cities)
def delete_attachment(): filepath = request.form.get('filepath', None) if not filepath: return f.failed(*const.INVALID_PARAMS) os.remove(filepath) return f.succeed('ok')