def clean_providers(providers): u"""Get only supported providers list from query string.""" providers_list = get_cache_value(constants.CACHE_KEY_PROVIDERS) if providers_list is None: logger.debug("retrieving providers from db") providers_list = [provider.id for provider in models.Provider.all()] set_cache_value(constants.CACHE_KEY_PROVIDERS, providers_list) if PROVIDER_SPEC_ALL in providers: return providers_list return list(set([prov.lower() for prov in providers if prov.lower() in providers_list]))
def get_data(lat, lng, providers, filters): logger.debug("query filters: %s" % filters) filters = clean_filters(filters) logger.debug("cleaned filters: %s" % filters) if not filters: return [] logger.debug("query providers: %s" % providers) providers = clean_providers(providers) logger.debug("cleaned providers: %s" % providers) if not providers: return [] logger.debug("query object types: %s" % filters) object_types = get_object_types(filters) logger.debug("cleaned object types: %s" % object_types) markers = [] for provider in providers: for object_type in object_types: cache_key = "%s:%s" % (provider, object_type) logger.debug('requesting data for "%s"' % cache_key) data = get_cache_value(cache_key) if data is not None: markers.extend(data) else: model = TYPES_TO_MODELS[object_type] data = [marker.to_dict() for marker in model.all().filter("provider =", provider)] logger.debug('retrieved %d entries for "%s" from db' % (len(data), cache_key)) set_cache_value(cache_key, data) markers.extend(data) markers = apply_filters(markers, filters) logger.debug("retrieved %d filtered markers" % len(markers)) if all([lat, lng]): markers = nearest(markers, lat, lng) logger.info("returned %d nearest markers" % len(markers)) else: logger.info("returned %d markers" % len(markers)) return markers