def get_artist_engine(artist_id: int) -> dict: """ Show the artist page with the given artist_id :param artist_id: id of artist """ artist = get_music_entity_engine(artist_id, _ARTIST_) return add_show_summary(artist_id, artist, shows_by_artist)
def get_venue_engine(venue_id: int): """ Get a venue :param venue_id: id of venue """ venue = get_music_entity_engine(venue_id, _VENUE_) return add_show_summary(venue_id, venue, shows_by_venue)
def venue_to_edit_engine(venue_id: int): """ Edit a venue :param venue_id: id of the venue to edit """ venue = get_music_entity_engine(venue_id, _VENUE_) as_type = EntityResult.DICT # availability as a dict return venue, as_type
def artist_to_edit_engine(artist_id: int) -> (dict, EntityResult, dict): """ Edit an artist :param artist_id: id of the artist to edit """ artist = get_music_entity_engine(artist_id, _ARTIST_) as_type = EntityResult.DICT # availability as a dict no_availability = dict() return artist, as_type, no_availability
def update_artist_engine(artist_id: int, form: FlaskForm, availability: dict) -> (Union[bool, None], str): """ Update an artist in ENGINE mode :param artist_id: id of the artist to update :param form: form to populate from :param availability: artist availability """ stmts = [] artist = get_music_entity_engine(artist_id, _ARTIST_) updated_artist = populate_artist_engine(_ARTIST_.model_dict(), form) if not equal_dict(artist, updated_artist, IGNORE_ID): # change has occurred update artist to_set = [ f'{k}=\'{v}\'' for k, v in updated_artist.items() if k in dict_disjoint(artist, updated_artist, IGNORE_ID_GENRES) ] if len(to_set) > 0: to_set = ", ".join(to_set) stmts.append( f'UPDATE "{ARTIST_TABLE}" SET {to_set} WHERE id={artist_id};') # update genre link table if updated_artist["genres"] != artist["genres"]: for stmt in genre_changes_engine(artist["genres"], updated_artist["genres"], artist_id, _ARTIST_): stmts.append(stmt) new_availability = populate_availability_engine( _AVAILABILITY_.model_dict(), form) new_availability["artist_id"] = artist_id if is_available(availability) != is_available(new_availability) or \ not equal_dict(availability, new_availability, IGNORE_ID_DATE): # availability has changed, add new setting stmts.append(availability_insert_sql(artist_id, new_availability)) return exec_transaction_engine(stmts, updated_artist["name"])
def update_venue_engine(venue_id: int, form: FlaskForm) -> (Union[bool, None], str): """ Update an venue in ENGINE mode :param venue_id: id of the venue to update :param form: form to update from """ stmts = [] venue = get_music_entity_engine(venue_id, _VENUE_) updated_venue = populate_venue_engine(_VENUE_.model_dict(), form) if not equal_dict(venue, updated_venue, IGNORE_ID): # change has occurred update venue to_set = [f'{k}=\'{v}\'' for k, v in updated_venue.items() if k in dict_disjoint(venue, updated_venue, IGNORE_ID_GENRES)] if len(to_set) > 0: to_set = ", ".join(to_set) stmts.append(f'UPDATE "{VENUE_TABLE}" SET {to_set} WHERE id={venue_id};') # update genre link table if updated_venue["genres"] != venue["genres"]: for stmt in genre_changes_engine(venue["genres"], updated_venue["genres"], venue_id, _VENUE_): stmts.append(stmt) return exec_transaction_engine(stmts, updated_venue["name"])