def get_all_providers(invalidate=False): """ wrapper function to get all the providers for PACT and cache them. ugly for now - the number of entries is small enough that loading all and scanning on checking is small enough overhead on a single page load. """ if invalidate: cache.delete(PACT_PROVIDERS_FIXTURE_CACHE_KEY) raw_cached_fixtures = cache.get(PACT_PROVIDERS_FIXTURE_CACHE_KEY, None) if raw_cached_fixtures is None: #requery and cache pact_hp_group = Group.by_name(PACT_DOMAIN, PACT_HP_GROUPNAME) providers = FixtureDataItem.by_group(pact_hp_group) cache.set(PACT_PROVIDERS_FIXTURE_CACHE_KEY, json.dumps([x.to_json() for x in providers])) return providers else: try: json_data = json.loads(raw_cached_fixtures) #not necessary in the grand scheme of things - we could really just use raw JSON return [FixtureDataItem.wrap(x) for x in json_data] except Exception as ex: logging.error("Error loading json from cache key %s: %s" % (PACT_PROVIDERS_FIXTURE_CACHE_KEY, ex)) return [] # cache.set('%s_casedoc' % self._id, json.dumps(self._case), PACT_CACHE_TIMEOUT) # xml_ret = cache.get('%s_schedule_xml' % self._id, None) pass
def get_all_providers(invalidate=False): """ wrapper function to get all the providers for PACT and cache them. ugly for now - the number of entries is small enough that loading all and scanning on checking is small enough overhead on a single page load. """ if invalidate: cache.delete(PACT_PROVIDERS_FIXTURE_CACHE_KEY) raw_cached_fixtures = cache.get(PACT_PROVIDERS_FIXTURE_CACHE_KEY, None) if raw_cached_fixtures is None: #requery and cache pact_hp_group = Group.by_name(PACT_DOMAIN, PACT_HP_GROUPNAME) providers = FixtureDataItem.by_group(pact_hp_group) cache.set(PACT_PROVIDERS_FIXTURE_CACHE_KEY, json.dumps([x.to_json() for x in providers])) return providers else: try: json_data = json.loads(raw_cached_fixtures) #not necessary in the grand scheme of things - we could really just use raw JSON return [FixtureDataItem.wrap(x) for x in json_data] except Exception, ex: logging.error("Error loading json from cache key %s: %s" % (PACT_PROVIDERS_FIXTURE_CACHE_KEY, ex)) return [] # cache.set('%s_casedoc' % self._id, json.dumps(self._case), PACT_CACHE_TIMEOUT) # xml_ret = cache.get('%s_schedule_xml' % self._id, None) pass
def data(self): # this is being called multiple times def render(f): title = { "public": _("Public Facility"), "private": _("Private Facility"), "transport": _("Transport") }[f.fields["type"]] return format_html(u"%s: %s<br /># %s" % (title, f.fields.get("name", ""), f.fields.get("number", ""))) fixtures = FixtureDataItem.by_group(self.group) _data = [] self._headers = [] for f in fixtures: _data.append(render(f)) self._headers.append(" ") if not _data: _data = ['No referrals for %s' % self.group.name] self._headers = [" "] return _data
def data(self): # this is being called multiple times def render(f): title = { "public": _("Public Facility"), "private": _("Private Facility"), "transport": _("Transport") }[f.fields_without_attributes["type"]] return format_html(u"%s: %s<br /># %s" % (title, f.fields_without_attributes.get("name", ""), f.fields_without_attributes.get("number", ""))) fixtures = FixtureDataItem.by_group(self.group) _data = [] self._headers = [] for f in fixtures: _data.append(render(f)) self._headers.append(" ") if not _data: _data = ['No referrals for %s' % self.group.name] self._headers = [" "] return _data