示例#1
0
def patrol_path(request):
    #get the latest map (if there is nothing, create it)
    last_map = Map.objects.last()
    if last_map is None:
        last_map = Map()
        last_map.save()

    return JsonResponse({"patrol_path": last_map.get_parsed_patrol_path()})
示例#2
0
def current_mode(request):
    last_map = Map.objects.last()
    if last_map is None:
        last_map = Map()
        last_map.save()

    data = {"current_mode": last_map.current_mode}
    """
	if last_map.current_mode == Map.NORMAL_MODE:
		data["mode_data"] = last_map.get_parsed_boundaries()
	elif last_map.current_mode == Map.PATROL_MODE:
		data["mode_data"] = last_map.get_parsed_patrol_path()
	"""

    return JsonResponse(data)
示例#3
0
def start_mapping(request):
    if request.method == 'POST':
        #get the latest map
        last_map = Map.objects.last()
        if last_map is None:
            return HttpResponse(
                'ERROR: cannot start mapping mode if you have not created a map before'
            )

        if last_map.current_mode != Map.NORMAL_MODE:
            return HttpResponse(
                'ERROR: cannot start mapping mode if not in normal mode')

        #create a new map everytime you start mapping
        last_map = Map()
        last_map.current_mode = Map.MAPPING_MODE
        last_map.save()
        return HttpResponse('started mapping mode!')
    else:
        return HttpResponse('ERROR: cannot start mapping mode if GET request')
示例#4
0
def picture_request(request):
    last_map = Map.objects.last()
    if last_map is None:
        last_map = Map()
        last_map.save()

    #only allow people to add requests in POST
    if request.method == 'POST':
        last_map.images_requested = last_map.images_requested + 1
        last_map.save()
        return HttpResponse("picture request added!")

    #else, get how many requests we have so far and send true if more than 0. Also, decrease the size if so
    else:
        data = {"image_requested": False}

        if last_map.images_requested > 0:
            last_map.images_requested = last_map.images_requested - 1
            last_map.save()
            data["image_requested"] = True

        return JsonResponse(data)
示例#5
0
def current_location(request):
    '''
		If POST request: check if in mapping mode, and add boundary if so
		If GET request: get current boundaries
	'''
    #get the latest map (if there is nothing, create it)
    last_map = Map.objects.last()
    if last_map is None:
        last_map = Map()
        last_map.save()

    if request.method == 'POST':
        last_map.update_location(request.POST.get('x'), request.POST.get('y'),
                                 request.POST.get('angle'))
        last_map.save()
        return HttpResponse('location updated')
    else:
        return JsonResponse(
            {"current_location": last_map.get_parsed_location()})
示例#6
0
def clear_patrol_path(request):
    if request.method == 'POST':
        #get the latest map (if there is nothing, create it)
        last_map = Map.objects.last()
        if last_map is None:
            last_map = Map()
            last_map.save()

        last_map.patrol_path = "[]"
        last_map.save()
        return HttpResponse("patrol path cleared!")
    else:
        return HttpResponse('ERROR: cannot stop mapping mode if GET request')
示例#7
0
def current_target(request):
    '''
		If POST request: check if in mapping mode, and add boundary if so
		If GET request: get current boundaries
	'''
    #get the latest map (if there is nothing, create it)
    last_map = Map.objects.last()
    if last_map is None:
        last_map = Map()
        last_map.save()

    if request.method == 'POST':
        last_map.update_target(request.POST.get('x'), request.POST.get('y'))
        last_map.save()
        return HttpResponse('target updated')
    else:
        return HttpResponse(last_map.current_target,
                            content_type="application/json")
示例#8
0
def boundaries(request):
    '''
		If POST request: check if in mapping mode, and add boundary if so
		If GET request: get current boundaries
	'''
    #get the latest map (if there is nothing, create it)
    last_map = Map.objects.last()
    if last_map is None:
        last_map = Map()
        last_map.save()

    if request.method == 'POST':
        if last_map.current_mode == Map.MAPPING_MODE:
            last_map.add_boundary_point(request.POST.get('x'),
                                        request.POST.get('y'))
            last_map.save()
            return HttpResponse('point added!')
        else:
            return HttpResponse(
                'ERROR: not in mapping mode, so the point was not added!')

    else:
        return JsonResponse({"boundaries": last_map.get_parsed_boundaries()})