def post(self, request):
if not (request.POST.get('uuid') and
request.POST.get('long') and
request.POST.get('lat') and
request.POST.get('bands')
):
return Response("Missing arguments", status=status.HTTP_406_NOT_ACCEPTABLE)
req_bands = request.POST.get('bands').split(',')
for band in req_bands:
if not (band in BTS.bands):
return Response("Invalid Arguments", status=status.HTTP_400_BAD_REQUEST)
pnt = GEOSGeometry(Point(float(request.POST.get('long')),
float(request.POST.get('lat'))))
with transaction.atomic():
tower = BTS.objects.get(uuid=request.POST.get('uuid'))
nearby_towers = BTS.objects.filter(
location__distance_lt=(pnt,D(km=RANGE))).exclude(uuid=request.POST.get('uuid'))
used_channels = dict.fromkeys(BTS.bands.keys(), set())
for tower in nearby_towers:
if (tower.band): #skip those without set bands
used_channels[tower.band].add(tower.channel)
free_channels = dict.fromkeys(req_bands)
for band in req_bands:
free_channels[band] = BTS.bands[band]['valid_values'].difference(used_channels[band])
if (len(free_channels[band]) > 0): #something available
return Response({ band : free_channels[band],
'power_level' : POWER_LEVEL},
status=status.HTTP_200_OK)
return Response("No Available Bands", status=status.HTTP_404_NOT_FOUND)
views.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录