def edit(): """ 新建/编辑资源 name 文件名 file_id 上传的文件ID type 文件类型 :return: """ name = request.form.get('name') type = request.form.get('type') file_id = request.form.get('file_id') if not name or not type or not file_id: return res(code=Errors.PARAMS_REQUIRED) if type not in Resource.RESOURCE_TYPE: return res(code=Errors.UPLOAD_FORMAT_LIMITATION) r = Resource.objects(file_id=file_id).first() if not r: r = Resource() r.name = name r.type = type r.file_id = file_id r.save() return res(data=r.as_dict())
def create_resource(tower, lat, lon, quantity): for i in range(quantity): resource = ResourceGenerator(lat, lon) resource_db = Resource(type=str(resource.type), lat=resource.lat, lon=resource.lon, quantity=resource.quantity, name=str(resource.name), description=str(resource.description), tower_id=tower) resource_db.save() message = resource.name + " appeared (lat: " + str( resource.lat / 100000) + ", lon: " + str( resource.lon / 100000) + ") quantity: " + str( resource.quantity) send_message(resource.name + " appeared") socketio.emit('resource_spawned', { 'point': { 'lat': (resource.lat / 100000), 'lon': (resource.lon / 100000) }, 'id': str(resource_db.id), 'towerid': str(tower), 'label': resource.type[0].capitalize(), 'description': resource.description, 'title': resource.name, 'quantity': quantity }, namespace='/main')
def post(self): data = Resources.parser.parse_args() try: s3 = boto3.resource( 's3', aws_access_key_id=current_app.config['ACCESS_KEY'], aws_secret_access_key=current_app.config['SECRET_ACCESS_KEY']) image = data['image'] program_id = data['program_id'] upload_file_bucket = "precisionteachingonline" resource = ResourceModel(None, image.filename, program_id) resource.save() upload_file_key = str(resource.id) + image.filename s3.Bucket(upload_file_bucket).put_object(Key=upload_file_key, Body=data['image']) return "OK" except Exception as err: print(str(err)) return str(err)