def get_users_observations(self, username): if not username: return None work_id = extract_numeric_id_from_olid(self.key) raw_observations = Observations.get_patron_observations(username, work_id) formatted_observations = defaultdict(list) for r in raw_observations: kv_pair = Observations.get_key_value_pair(r['type'], r['value']) formatted_observations[kv_pair.key].append(kv_pair.value) return formatted_observations
def GET(self, work_id): user = accounts.get_current_user() if not user: raise web.seeother('/account/login') username = user.key.split('/')[2] existing_records = Observations.get_patron_observations( username, work_id) patron_observations = defaultdict(list) for r in existing_records: kv_pair = Observations.get_key_value_pair(r['type'], r['value']) patron_observations[kv_pair.key].append(kv_pair.value) return delegate.RawText(json.dumps(patron_observations), content_type="application/json")