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 get_points(location): if isinstance(location, str): location = json.loads(location) lat = round(location['lat'] * (1 / step)) lon = round(location['lon'] * (1 / step)) points = [] towers = [] tower_locations = [] for latitude in range(lat - circles, lat + (circles + 1), 1): for longitude in range(lon - circles, lon + (circles + 1), 1): try: tower_location = TowerLocation.objects( lat=latitude, lon=longitude).limit(1).get() tower_locations.append(tower_location.id) except DoesNotExist as e: print(e) for tower in Tower.objects(location__in=tower_locations): towers.append(tower) try: for point in Resource.objects(tower_id__in=list(tower.id for tower in towers)): points.append({ 'location': { 'lat': point.lat / 100000, 'lon': point.lon / 100000 }, 'id': point.get_id(), 'towerid': str(point.tower_id), 'label': point.type[0].capitalize(), 'description': point.description, 'quantity': point.quantity, 'title': point.name }) except DoesNotExist as e: print(e) emit('receive_points', {'points': points})