def _querydict_to_objects(request, raise_on_not_found=False): """ Finds all object specifications in a querydict and returns a list of pynag objects Typically this is used to name specific objects from the querystring. Valid input in the request is either id=object_id or object_type=short_name Arguments: request - A django request object. Usually the data is in a querystring or POST data - Example: host=localhost,service=localhost/Ping raise_on_not_found - Raise ValueError if some object is not found Returns: List of pynag objects """ result = [] mydict = request.GET or request.POST # Find everything in the querystring in the form of id=[object_ids] for object_id in mydict.getlist('id'): try: my_object = ObjectDefinition.objects.get_by_id(object_id) result.append(my_object) except Exception as e: if raise_on_not_found is True: raise e # Find everything in querystring in the form of object_type=[shortnames] for object_type,Class in list(string_to_class.items()): objects = mydict.getlist(object_type) for shortname in objects: try: my_object = Class.objects.get_by_shortname(shortname) result.append(my_object) except Exception as e: # If a service was not found, check if it was registered in # some unusual way if object_type == 'service' and '/' in shortname: host_name,service_description = shortname.split('/', 1) result.append(_find_service(host_name, service_description)) if raise_on_not_found is True: raise e return result
List of pynag objects """ result = [] mydict = request.GET or request.POST # Find everything in the querystring in the form of id=[object_ids] for object_id in mydict.getlist('id'): try: my_object = ObjectDefinition.objects.get_by_id(object_id) result.append(my_object) except Exception, e: if raise_on_not_found is True: raise e # Find everything in querystring in the form of object_type=[shortnames] for object_type, Class in string_to_class.items(): objects = mydict.getlist(object_type) for shortname in objects: try: my_object = Class.objects.get_by_shortname(shortname) result.append(my_object) except Exception, e: # If a service was not found, check if it was registered in # some unusual way if object_type == 'service' and '/' in shortname: host_name, service_description = shortname.split('/', 1) result.append(_find_service(host_name, service_description)) if raise_on_not_found is True: raise e return result
List of pynag objects """ result = [] mydict = request.GET or request.POST # Find everything in the querystring in the form of id=[object_ids] for object_id in mydict.getlist('id'): try: my_object = ObjectDefinition.objects.get_by_id(object_id) result.append(my_object) except Exception, e: if raise_on_not_found is True: raise e # Find everything in querystring in the form of object_type=[shortnames] for object_type,Class in string_to_class.items(): objects = mydict.getlist(object_type) for shortname in objects: try: my_object = Class.objects.get_by_shortname(shortname) result.append(my_object) except Exception, e: # If a service was not found, check if it was registered in # some unusual way if object_type == 'service' and '/' in shortname: host_name,service_description = shortname.split('/', 1) result.append(_find_service(host_name, service_description)) if raise_on_not_found is True: raise e return result