views.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:CommunityCellularManager 作者: facebookincubator 项目源码 文件源码
def post(self, request):
        if not (
                request.POST.get('uuid') and
                request.POST.get('lat') and
                request.POST.get('long') and
                request.POST.get('band') and
                request.POST.get('channel') and
                request.POST.get('power_level')
        ):
            return Response("Missing Arguments", status=status.HTTP_406_NOT_ACCEPTABLE)

        if not (
                request.POST.get('band') in BTS.bands and
                request.POST.get('channel').isdigit() and
                request.POST.get('power_level').isdigit()
        ):
            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))).filter(
                    band=request.POST.get('band')).exclude(uuid=request.POST.get('uuid'))
            for t in nearby_towers:
                if (int(request.POST.get('channel')) == t.channel):
                    return Response("Channel In Use", status=status.HTTP_409_CONFLICT)
            #no one interfered
            tower.channel = int(request.POST.get('channel'))
            tower.location = pnt
            tower.band = request.POST.get('band')
            tower.save()
            return Response("Success", status=status.HTTP_200_OK)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号