def getUpcomingRecommendedEventsSegmented(self, uid, offset, limit=20): """Return the upcoming, active, recommended event entries specified by offset and limit parameters. Uses :func:`~app.DAOs.EventDAO.EventDAO.getUpcomingRecommendedEventsSegmented` as well as: * :func:`~app.handlers.SharedValidationFunctions.validate_offset_limit` * :func:`~app.handlers.EventHandler._buildCoreEventResponse` :param uid: User ID :type uid: int :param offset: Number of result rows to ignore from top of query results. :type offset: int :param limit: Max number of result rows to return. Default=20. :type limit: int :returns JSON Response Object: JSON containing limit-defined number of events recommended to a user that have not ended. """ if not isinstance(uid, int) or not uid > 0: return jsonify(Error="Invalid uid: " + str(uid)), 400 try: SVF.validate_offset_limit(offset=offset, limit=limit) except ValueError as ve: return jsonify(Error=str(ve)), 400 events = EventDAO().getUpcomingRecommendedEventsSegmented(uid=uid, offset=offset, limit=limit) if not events: response = {'events': None} else: event_list = [] for row in events: # TODO: consider re-developing Response builders for more flexibility. event_entry = _buildCoreEventResponse(event_tuple=row) event_entry['itype'] = row[11] event_list.append(event_entry) response = {'events': event_list} return jsonify(response)
def getAllPastEventsSegmented(self, offset, limit=20): """Get all events whose end dates are equal to or less than the current timestamp of the database. Uses :func:`~app.DAOs.EventDAO.EventDAO.getAllPastEventsSegmented` as well as: * :func:`~app.handlers.SharedValidationFunctions.validate_offset_limit` * :func:`~app.handlers.EventHandler._buildCoreEventResponse` :param offset: Number of results to skip from top of list. :type offset: int :param limit: Number of results to return. Default = 20. :type limit: int :returns JSON Response Object: JSON Response Object containing success or error response. """ try: SVF.validate_offset_limit(offset=offset, limit=limit) except ValueError as ve: return jsonify(Error=str(ve)), 400 events = EventDAO().getAllPastEventsSegmented(offset=offset, limit=limit) if not events: response = {'events': None} else: event_list = [] for row in events: event_entry = _buildCoreEventResponse(event_tuple=row) event_list.append(event_entry) response = {'events': event_list} return jsonify(response)
def getRoomsByKeywordSegmented(self, searchstring, offset, limit=20): """ Return the room entries matching the search parameters. :param searchstring: string separated by whitespaces with terms to search for :param offset: Number of result rows to ignore from top of query results. :param limit: Max number of result rows to return. Default=20. :return JSON: containing room information or null. Error JSON otherwise. """ try: SVF.validate_offset_limit(offset=offset, limit=limit) keywords = SVF.processSearchString(searchstring=searchstring) except KeyError as e: return jsonify(Error=str(e)), 400 except ValueError as e: return jsonify(Error=str(e)), 400 dao = RoomDAO() rooms = dao.getRoomsByKeywordSegmented(keywords=keywords, limit=limit, offset=offset) if not rooms: response = {"rooms": None} else: room_list = [] for row in rooms: room_result = _buildCoreRoomResponse(room_tuple=row) room_result['building'] = BuildingHandler( ).getCoreBuildingByID(bid=row[1], no_json=True) room_list.append(room_result) response = {"rooms": room_list} return jsonify(response)
def getServicesByKeywords(self, searchstring, offset, limit=20): """ Get all services by keyword, segmented Uses :func:`~app.DAOs.ServiceDAO.ServiceDAO.getServicesByKeywords` as well as :func:`~app.handlers.ServiceHandler._buildServiceResponse` :param searchstring: Keyword to search for services. :type offset: string :param offset: Number of results to skip from top of list. :type offset: int :param limit: Number of results to return. Default = 20. :type limit: int :returns JSON Response Object: JSON Response Object containing success or error response. """ try: SVF.validate_offset_limit(offset=offset, limit=limit) keywords = SVF.processSearchString(searchstring=searchstring) except ValueError as ve: return jsonify(Error=str(ve)), 400 dao = ServiceDAO() services = dao.getServicesByKeywords(searchstring=keywords, offset=offset, limit=limit) if not services: response = {'services': None} else: service_list = [] for row in services: service_list.append( _buildCoreServiceResponse(service_tuple=row)) response = {'services': service_list} return jsonify(response)
def getServicesSegmented(self, offset, limit): """Get all services, segmented Uses :func:`~app.DAOs.ServiceDAO.ServiceDAO.getServicesSegmented` as well as: * :func:`~app.handlers.SharedValidationFunctions.validate_offset_limit` * :func:`~app.handlers.ServiceHandler._buildCoreServiceResponse` :param offset: Number of results to skip from top of list. :type offset: int :param limit: Number of results to return. Default = 20. :type limit: int :returns JSON Response Object: JSON Response Object containing success or error response. """ try: SVF.validate_offset_limit(offset=offset, limit=limit) except ValueError as ve: return jsonify(Error=str(ve)), 400 dao = ServiceDAO() services = dao.getServicesSegmented(offset=offset, limit=limit) if not services: response = {'services': None} else: service_list = [] for row in services: service_list.append(_buildCoreServiceResponse(row)) response = {'services': service_list} return jsonify(response)
def getRoomsByCodeSearchSegmented(self, babbrev, rcode, offset, limit=20): """ Return the room entries matching the search parameters. :param babbrev: string corresponding to the building abbreviation :param rcode: string corresponding to the room code :param offset: Number of result rows to ignore from top of query results. :param limit: Max number of result rows to return. Default=20. :return JSON: containing room information or null. Error JSON otherwise. """ try: SVF.validate_offset_limit(offset=offset, limit=limit) except KeyError as e: return jsonify(Error=str(e)), 400 except ValueError as e: return jsonify(Error=str(e)), 400 # Filter strings. # Force sent abbrev and rcode to be strings appropriate for LIKE query. babbrev = str(babbrev).upper() rcode = str(rcode) # Remove symbols and spaces from strings. Leave only numbers and letters. rcode = "".join(filter(str.isalnum, rcode)) babbrev = "".join(filter(str.isalnum, babbrev)) dao = RoomDAO() rooms = dao.getRoomsByCodeSearchSegmented(babbrev=babbrev, rcode=rcode, limit=limit, offset=offset) if not rooms: response = {"rooms": None} else: room_list = [] for row in rooms: room_result = _buildCoreRoomResponse(room_tuple=row) room_result['building'] = BuildingHandler( ).getCoreBuildingByID(bid=row[1], no_json=True) room_list.append(room_result) response = {"rooms": room_list} return jsonify(response)
def getUpcomingRecommendedEventsByKeywordSegmented(self, uid, searchstring, offset, limit=20): """Return the upcoming, recommended, active event entries specified by offset and limit parameters. Uses :func:`~app.DAOs.EventDAO.EventDAO.getUpcomingRecommendedEventsByKeywordSegmented` as well as: * :func:`~app.handlers.SharedValidationFunctions.validate_offset_limit` * :func:`~app.handlers.SharedValidationFunctions.processSearchString` * :func:`~app.handlers.EventHandler._buildCoreEventResponse` :param uid: User ID :type uid: int :param searchstring: String to use as search criteria for recommended events. Search terms must be separated by whitespaces. :type searchstring: str :param offset: Number of result rows to ignore from top of query results. :type offset: int :param limit: Max number of result rows to return. Default=20. :type limit: int :returns JSON Response Object: JSON containing limit-defined number of recommended events that have not ended and match search criteria. """ if not isinstance(uid, int) or not uid > 0: return jsonify(Error="Invalid uid: " + str(uid)), 400 try: SVF.validate_offset_limit(offset=offset, limit=limit) # Process keywords to be filtered and separated by pipes. keywords = SVF.processSearchString(searchstring=searchstring) except ValueError as ve: return jsonify(Error=str(ve)), 400 events = EventDAO().getUpcomingRecommendedEventsByKeywordSegmented(uid=uid, keywords=keywords, offset=offset, limit=limit) if not events: response = {'events': None} else: event_list = [] for row in events: # TODO: consider re-developing Response builders for more flexibility. event_entry = _buildCoreEventResponse(event_tuple=row) event_entry['itype'] = row[11] event_list.append(event_entry) response = {'events': event_list} return jsonify(response)