def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=WorkIncludes.parse) work = get_work_by_gid(query_work(g.db, include), gid) if work is None: abort(response_error(NOT_FOUND_ERROR, 'work not found')) if include.relationships: load_links(g.db, [work], include.relationships) return response_ok(work=serialize_work(work, include))
def get_labels_by_ids(db, ids, include): if not ids: return {} labels = query_label(db, include).filter(Label.id.in_(ids)).all() if include.relationships: load_links(db, labels, include.relationships) results = {} for label in labels: results[label.id] = serialize_label(label, include) return results
def get_recordings_by_ids(db, ids, include): if not ids: return {} recordings = query_recording(db, include).filter(Recording.id.in_(ids)).all() if include.relationships: load_links(db, recordings, include.relationships) results = {} for recording in recordings: results[recording.id] = serialize_recording(recording, include) return results
def test_load_links(db): work = db.query(Work).filter_by( gid='e02ccc5b-d39f-31d2-aaf5-b56ad67e4ffe').one() load_links(db, [work], RelationshipsIncludes.parse(['artist'])) assert_equals(len(work.artist_links), 2) link = work.artist_links[0] assert_equals(link.link.link_type.name, 'composer') assert_equals(link.artist.name, 'Richard Melville Hall') link = work.artist_links[1] assert_equals(link.link.link_type.name, 'lyricist') assert_equals(link.artist.name, 'Richard Melville Hall')
def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=ReleaseIncludes.parse) if include.artist and include.artists: abort(response_error(INCLUDE_DEPENDENCY_ERROR, 'include=artist and include=artists are mutually exclusive')) release = get_release_by_gid(query_release(g.db, include), gid) if release is None: abort(response_error(NOT_FOUND_ERROR, 'release not found')) if include.relationships: load_links(g.db, [release], include.relationships) return response_ok(release=serialize_release(release, include))
def get_release_groups_by_ids(db, ids, include): if not ids: return {} release_groups = query_release_group(db, include).filter( ReleaseGroup.id.in_(ids)).all() if include.relationships: load_links(db, release_groups, include.relationships) results = {} for release_group in release_groups: results[release_group.id] = serialize_release_group( release_group, include) return results
def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=PlaceIncludes.parse) place = get_place_by_gid(query_place(g.db, include), gid) if place is None: abort(response_error(NOT_FOUND_ERROR, 'place not found')) if include.area: load_areas(g.db, [place], include.area) if include.relationships: load_links(g.db, [place], include.relationships) return response_ok(place=serialize_place(place, include))
def get_artists_by_ids(db, ids, include): if not ids: return {} artists = query_artist(db, include).filter(Artist.id.in_(ids)).all() if include.areas: load_areas(db, artists, include.areas) if include.relationships: load_links(db, artists, include.relationships) results = {} for artist in artists: results[artist.id] = serialize_artist(artist, include) return results
def handle_get(): gid = get_param('id', type='uuid', required=True) include = get_param('include', type='enum+', container=ArtistIncludes.parse) artist = get_artist_by_gid(query_artist(g.db, include), gid) if artist is None: abort(response_error(NOT_FOUND_ERROR, 'artist not found')) if include.areas: load_areas(g.db, [artist], include.areas) if include.relationships: load_links(g.db, [artist], include.relationships) return response_ok(artist=serialize_artist(artist, include))