def process_children(self, request, parameters, arguments, include=None): """ Allows to process the children questions for the current question """ if include is None: include = [] children = {} report = arguments['report'] children_parameters = {} if 'children' in parameters and parameters['children'] is not None: children_parameters = OrderedDict(parameters['children']) for child, value in children_parameters.items(): if not include or child in include: children[child] = { 'state': 'ok', 'text': question_loader.process_questions( request, report.report.pk, value, view_type=self.view_type, reportbyproj=report) }
def get_service_handler(base_url, proxy_base=None, service_type=enumerations.AUTO): """Return the appropriate remote service handler for the input URL. If the service type is not explicitly passed in it will be guessed from """ handlers = OrderedDict({ enumerations.WMS: { "OWS": True, "handler": WmsServiceHandler }, enumerations.GN_WMS: { "OWS": True, "handler": GeoNodeServiceHandler }, # enumerations.WFS: {"OWS": True, "handler": ServiceHandlerBase}, # enumerations.TMS: {"OWS": False, "handler": ServiceHandlerBase}, enumerations.REST_MAP: { "OWS": False, "handler": ArcMapServiceHandler }, enumerations.REST_IMG: { "OWS": False, "handler": ArcImageServiceHandler }, # enumerations.CSW: {"OWS": False, "handler": ServiceHandlerBase}, # enumerations.HGL: {"OWS": True, "handler": ServiceHandlerBase}, # TODO: verify this # enumerations.OGP: {"OWS": False, "handler": ServiceHandlerBase}, # TODO: verify this }) if service_type in (enumerations.AUTO, enumerations.OWS): if service_type == enumerations.AUTO: to_check = handlers.keys() else: to_check = [k for k, v in handlers.items() if v["OWS"]] for type_ in to_check: logger.debug("Checking {}...".format(type_)) try: service = get_service_handler(base_url, type_) except Exception: pass # move on to the next service type else: break else: raise RuntimeError("Could not parse service {!r} with any of the " "available service handlers".format(base_url)) else: handler = handlers.get(service_type, {}).get("handler") try: service = handler(base_url) except Exception: logger.exception( msg="Could not parse service {!r}".format(base_url)) raise return service
def get_service_handler(base_url, proxy_base=None, service_type=enumerations.AUTO): """Return the appropriate remote service handler for the input URL. If the service type is not explicitly passed in it will be guessed from """ handlers = OrderedDict({ enumerations.WMS: {"OWS": True, "handler": WmsServiceHandler}, enumerations.GN_WMS: {"OWS": True, "handler": GeoNodeServiceHandler}, # enumerations.WFS: {"OWS": True, "handler": ServiceHandlerBase}, # enumerations.TMS: {"OWS": False, "handler": ServiceHandlerBase}, enumerations.REST_MAP: {"OWS": False, "handler": ArcMapServiceHandler}, enumerations.REST_IMG: {"OWS": False, "handler": ArcImageServiceHandler}, # enumerations.CSW: {"OWS": False, "handler": ServiceHandlerBase}, # enumerations.HGL: {"OWS": True, "handler": ServiceHandlerBase}, # TODO: verify this # enumerations.OGP: {"OWS": False, "handler": ServiceHandlerBase}, # TODO: verify this }) if service_type in (enumerations.AUTO, enumerations.OWS): if service_type == enumerations.AUTO: to_check = handlers.keys() else: to_check = [k for k, v in handlers.items() if v["OWS"]] for type_ in to_check: logger.debug("Checking {}...".format(type_)) try: service = get_service_handler(base_url, type_) except Exception: pass # move on to the next service type else: break else: raise RuntimeError("Could not parse service {!r} with any of the " "available service handlers".format(base_url)) else: handler = handlers.get(service_type, {}).get("handler") try: service = handler(base_url) except Exception: logger.exception( msg="Could not parse service {!r}".format(base_url)) raise return service
def get_service_handler(base_url, service_type=enumerations.AUTO, headers=None): """Return the appropriate remote service handler for the input URL. If the service type is not explicitly passed in it will be guessed from """ handlers = OrderedDict({ enumerations.WMS: {"OWS": True, "handler": ExchangeWmsServiceHandler}, # enumerations.WFS: {"OWS": True, "handler": ServiceHandlerBase}, # enumerations.TMS: {"OWS": False, "handler": ServiceHandlerBase}, enumerations.REST: {"OWS": False, "handler": ExchangeMapserverServiceHandler}, # enumerations.CSW: {"OWS": False, "handler": ServiceHandlerBase}, # enumerations.HGL: {"OWS": True, "handler": ServiceHandlerBase}, # enumerations.OGP: {"OWS": False, "handler": ServiceHandlerBase}, }) if service_type in (enumerations.AUTO, enumerations.OWS): if service_type == enumerations.AUTO: to_check = handlers.keys() else: to_check = [k for k, v in handlers.items() if v["OWS"]] for type_ in to_check: logger.info("Checking {}...".format(type_)) try: service = get_service_handler(base_url, type_, headers=(headers or None)) except Exception: pass # move on to the next service type else: break else: raise RuntimeError("Could not parse service {!r} with any of the " "available service handlers".format(base_url)) else: handler = handlers.get(service_type, {}).get("handler") if (base_url.lower().startswith('https') and (callable(has_ssl_config) and has_ssl_config(base_url, via_query=True))): # has_ssl_config needs to query db, as call may be from task # worker, whose hostnameport_pattern_cache may be out of sync base_url = pki_route(base_url) logger.debug('Rewritten URL for pki proxy: {0}'.format(base_url)) bearer_header = {'Authorization': "Bearer {0}".format( get_bearer_token(valid_time=30))} logger.debug('Add bearer_header: {0}'.format(repr(bearer_header))) if headers and isinstance(headers, dict): headers.update(bearer_header) else: headers = bearer_header # Pass service type to pki_request view, for workarounds headers['PKI_SERVICE_TYPE'] = "{0}".format(service_type) try: service = handler(base_url, headers=headers) except Exception as e: logger.exception( msg="Could not parse service {!r}".format(base_url)) raise e return service
def get_service_handler(base_url, service_type=enumerations.AUTO, headers=None): """Return the appropriate remote service handler for the input URL. If the service type is not explicitly passed in it will be guessed from """ handlers = OrderedDict({ enumerations.WMS: { "OWS": True, "handler": ExchangeWmsServiceHandler }, # enumerations.WFS: {"OWS": True, "handler": ServiceHandlerBase}, # enumerations.TMS: {"OWS": False, "handler": ServiceHandlerBase}, enumerations.REST: { "OWS": False, "handler": ExchangeMapserverServiceHandler }, # enumerations.CSW: {"OWS": False, "handler": ServiceHandlerBase}, # enumerations.HGL: {"OWS": True, "handler": ServiceHandlerBase}, # enumerations.OGP: {"OWS": False, "handler": ServiceHandlerBase}, }) if service_type in (enumerations.AUTO, enumerations.OWS): if service_type == enumerations.AUTO: to_check = handlers.keys() else: to_check = [k for k, v in handlers.items() if v["OWS"]] for type_ in to_check: logger.info("Checking {}...".format(type_)) try: service = get_service_handler(base_url, type_, headers=(headers or None)) except Exception: pass # move on to the next service type else: break else: raise RuntimeError("Could not parse service {!r} with any of the " "available service handlers".format(base_url)) else: handler = handlers.get(service_type, {}).get("handler") if (base_url.lower().startswith('https') and (callable(has_ssl_config) and has_ssl_config(base_url, via_query=True))): # has_ssl_config needs to query db, as call may be from task # worker, whose hostnameport_pattern_cache may be out of sync base_url = pki_route(base_url) logger.debug('Rewritten URL for pki proxy: {0}'.format(base_url)) bearer_header = { 'Authorization': "Bearer {0}".format(get_bearer_token(valid_time=30)) } logger.debug('Add bearer_header: {0}'.format(repr(bearer_header))) if headers and isinstance(headers, dict): headers.update(bearer_header) else: headers = bearer_header # Pass service type to pki_request view, for workarounds headers['PKI_SERVICE_TYPE'] = "{0}".format(service_type) try: service = handler(base_url, headers=headers) except Exception as e: logger.exception( msg="Could not parse service {!r}".format(base_url)) raise e return service