Пример #1
0
def song(slug, semitones=None, root=None):
    """A song optionally transposed by given semitones."""
    logging.info(f"Got request for song {slug}")

    playlist: Playlist = get_selected_playlist()
    if playlist and not root:
        try:
            root = playlist.roots[slug]
        except KeyError:
            pass

    logging.debug("Got selected playlist")

    if session.get('logged_in') and request.args.get('random') != 'true':
        Session.get().add_song(slug)

    logging.debug("Added song to session")

    song = Song.get_or_404(slug, semitones=semitones, root=root, unicode=True)
    artist = Artist.get(song.artist_slug)

    logging.debug("Read song data from disk")

    related_songs = get_related(slug)
    if related_songs is not None:
        related_title = 'Σχετικά'
    else:
        related_songs = [song for song in artist.songs if song.slug != slug]
        related_title = ('Άλλα παραδοσιακά' if song.artist == 'Παραδοσιακό'
                         else f'Άλλα του {artist.genitive}')

    logging.debug("Rendering\n")

    return render_template(
        'song.html',
        song=song,
        artist=artist,
        songs=related_songs,
        related_title=related_title,
        semitones=semitones,
        root=root,
        admin=session.get('logged_in'),
    )
Пример #2
0
 def test_artist(self, client):
     SongFactory(name='a').tofile()
     SongFactory(name='b').tofile()
     assert repr(Artist.get('artist')) == "<Artist 'artist'>"