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 show_work_plan(value): if not value: return '' intervention = PCA.objects.get(id=int(value)) results = intervention.results.all() data = tablib.Dataset() work_plan = SortedDict() if results: try: tf_cols = next(x.disaggregation for x in results if x.result_type.name == 'Activity').keys() except: tf_cols = [] for num, result in enumerate(results): row = SortedDict() row['Code'] = result.indicator.code if result.indicator else result.result.code row['Details'] = result.indicator.name if result.indicator else result.result.name row['Targets'] = result.target if result.target else '' if result.result_type.name == 'Activity' and result.disaggregation: row.update(result.disaggregation) else: row.update(dict.fromkeys(tf_cols, '')) row['Total'] = result.total if result.total else '' row['CSO'] = result.partner_contribution if result.partner_contribution else '' row['UNICEF Cash'] = result.unicef_cash if result.unicef_cash else '' row['UNICEF Supplies'] = result.in_kind_amount if result.in_kind_amount else '' work_plan[num] = row if work_plan: for row in work_plan.values(): if not data.headers or len(data.headers) < len(row.values()): data.headers = row.keys() data.append(row.values()) return data.html return '<p>No results</p>'
def show_work_plan(value): if not value: return '' intervention = PCA.objects.get(id=int(value)) results = intervention.results.all() data = tablib.Dataset() work_plan = SortedDict() if results: try: tf_cols = next(x.disaggregation for x in results if x.result_type.name == 'Activity').keys() except: tf_cols = [] for num, result in enumerate(results): row = SortedDict() row['Code'] = result.indicator.code if result.indicator else result.result.code row['Details'] = result.indicator.name if result.indicator else result.result.name row['Targets'] = result.target if result.target else '' if result.result_type.name == 'Activity' and result.disaggregation: row.update(result.disaggregation) else: row.update(dict.fromkeys(tf_cols, '')) row['Total'] = result.total if result.total else '' row['CSO'] = result.partner_contribution if result.partner_contribution else '' row['UNICEF Cash'] = result.unicef_cash if result.unicef_cash else '' row['UNICEF Supplies'] = result.in_kind_amount if result.in_kind_amount else '' work_plan[num] = row if work_plan: for row in work_plan.values(): if not data.headers or len(data.headers) < len(row.values()): data.headers = row.keys() data.append(row.values()) return data.html return '<p>No results</p>'
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