示例#1
0
def handle_400_errors(e):
    """
    Return a custom response for 400 errors.
    :param e:
    :return:
    """
    return response('failed', 'Bad Request', 400)
示例#2
0
def handle_404_error(e):
    """
    Return a custom message for 404 errors.
    :param e:
    :return:
    """
    return response('failed', 'Ground resource cannot be found', 404)
示例#3
0
def get_ground(current_user, ground_id):
    """
    Return a user ground with the supplied user Id.
    :param current_user: User
    :param ground_id: ground Id
    :return:
    """
    try:
        int(ground_id)
    except ValueError:
        return response('failed', 'Please provide a valid Ground Id', 400)
    else:
        ground = Ground.get_by_id(ground_id)
        if ground:
            return response_for_ground(ground.json())
        return response('failed', "Ground not found", 404)
示例#4
0
def route_not_found(e):
    """
    Return a custom 404 Http response message for missing or not found routes.
    :param e: Exception
    :return: Http Response
    """
    return response('failed', 'Endpoint not found', 404)
示例#5
0
def internal_server_error(e):
    """
    Return a custom message for a 500 internal error
    :param e: Exception
    :return:
    """
    return response('failed', 'Internal server error', 500)
示例#6
0
def method_not_found(e):
    """
    Custom response for methods not allowed for the requested URLs
    :param e: Exception
    :return:
    """
    return response('failed',
                    'The method is not allowed for the requested URL', 405)
示例#7
0
def grounds_geography(current_user):
    """
    Get grounds by geography filters.
    :param current_user: Current User
    :return:
    """
    if request.content_type == 'application/json':
        data = request.get_json()

        frame = data.get('geobounds')

        if frame:
            # northEast point
            northEast = frame.get('northEast')

            if not northEast:
                return response('failed', 'Missing northEast attribute', 400)

            ne_latitude = northEast.get('latitude')
            ne_longitude = northEast.get('longitude')

            if not ne_latitude:
                return response(
                    'failed', 'Missing latitude attribute for northEast point',
                    400)

            if not ne_longitude:
                return response(
                    'failed',
                    'Missing longitude attribute for northEast point', 400)

            # southWest point
            southWest = frame.get('southWest')

            if not southWest:
                return response('failed', 'Missing southWest attribute', 400)

            sw_latitude = southWest.get('latitude')
            sw_longitude = southWest.get('longitude')

            if not sw_latitude:
                return response(
                    'failed', 'Missing latitude attribute for southWest point',
                    400)

            if not sw_longitude:
                return response(
                    'failed',
                    'Missing longitude attribute for southWest point', 400)

            try:
                float(ne_latitude)
                float(ne_longitude)
                float(sw_latitude)
                float(sw_longitude)
            except ValueError:
                return response('failed', 'Wrong coordinates values type', 400)

            grounds = Ground.get_by_location_rect(ne_latitude, ne_longitude,
                                                  sw_latitude, sw_longitude)
            if not grounds:
                grounds = []

            return response_for_grounds(get_ground_geojson_list(grounds))
        return response('failed', 'Missing feobounds attribute', 400)
    return response('failed', 'Content-type must be json', 202)