def search_indrz(request, campus_id, search_string, format=None): # query_string = '' # found_entries = None # if using a url like http://www.campus.com/search/?q=sometext # use this if statement and indent code block # if ('q' in request.GET) and request.GET['q'].strip(): # query_string = request.GET['q'] entry_query = get_query( search_string, ['short_name', 'long_name', 'room_code', 'room_description']) # return only first 20 results found_entries = BuildingFloorSpace.objects.filter( fk_building__fk_campus=campus_id).filter(entry_query)[:20] # buildings_on_campus = BuildingFloorSpace.objects.filter(Q(short_name__icontains=search_string) | Q(room_code__icontains=search_string)) serializer = BuildingFloorSpaceSerializer(found_entries, many=True) if found_entries: return Response(serializer.data) # elif: # pass # return Response({'error': 'sorry nothing found with the text: ' + search_string}) else: return Response( {'error': 'sorry nothing found with the text: ' + search_string})
def space_details(request, space_id, format=None): """ Return the GeoJSON of a single space ex. a single room """ if request.method == 'GET': floor_space_info = BuildingFloorSpace.objects.filter(id=space_id) serializer = BuildingFloorSpaceSerializer(floor_space_info, many=True) return Response(serializer.data)
def get_space_by_id(request, building_id, floor_id, space_id, format=None): """ Provided a space id return GeoJson of that single space """ if request.method == 'GET': space_value = BuildingFloorSpace.objects.filter(pk=space_id) serializer = BuildingFloorSpaceSerializer(space_value, many=True) return Response(serializer.data)
def building_spaces_list(request, building_id, floor_id, format=None): """ List all spaces on a specified floor in given building. """ if request.method == 'GET': floor_spaces = BuildingFloorSpace.objects.filter( fk_building=building_id, fk_building_floor=floor_id) serializer = BuildingFloorSpaceSerializer(floor_spaces, many=True) return Response(serializer.data)
def get_spaces_on_floor(request, floor_id, format=None): """ List all spaces on the provided building and floor """ if request.method == 'GET': space_ids = BuildingFloorSpace.objects.filter( fk_building_floor=floor_id) serializer = BuildingFloorSpaceSerializer(space_ids, many=True) return Response(serializer.data)
def campus_search(request, campus_id, search_string, format=None): """ Get a list of buildings on a singlge campus """ if request.method == 'GET': buildings_on_campus = BuildingFloorSpace.objects.filter( short_name__icontains=search_string) serializer = BuildingFloorSpaceSerializer(buildings_on_campus, many=True) # appending 2 quersets together into one new sorted list # result_list = sorted( # chain(page_list, article_list, post_list), # key=lambda instance: instance.date_created) return Response(serializer.data)
def campus_floor_spaces(request, campus_id, floor_num, format=None): """ Return all spaces from all buildings on a specified campus and floor number (not floor ID) :param campus_id: campus_id as integer the unique key :param floor_num: the floor number for all buildings :param format: :return: all spaces in all buildings for a specified floor number """ if request.method == 'GET': spaces_ids = BuildingFloorSpace.objects.filter( fk_building__fk_campus=campus_id).filter( fk_building_floor__floor_num=floor_num) serializer = BuildingFloorSpaceSerializer(spaces_ids, many=True) return Response(serializer.data)
def get_building_floor_spaces(request, building_id, floor_id, format=None): """ Return GeoJson of all spaces located on specified floor """ if request.method == 'GET': floor_ids = BuildingFloor.objects.filter(fk_building=building_id) foo = BuildingFloorSpace.objects.filter(fk_building_floor=floor_ids) spaces_on_floor = BuildingFloorSpace.objects.filter( fk_building_floor=floor_id) serializer = BuildingFloorSpaceSerializer(spaces_on_floor, many=True, context={'request': request}) return Response(serializer.data)