コード例 #1
0
ファイル: test_artists.py プロジェクト: forkbong/buzuki
    def test_search(self, client):
        SongFactory(name='a', artist='lorem ipsum').tofile()
        SongFactory(name='b', artist='lorem ipsum').tofile()
        SongFactory(name='c', artist='lalalalalal').tofile()

        artists = list(Artist.search('ipsum'))
        assert len(artists) == 1
        assert len(artists[0].songs) == 2
        assert artists[0].slug == 'lorem_ipsum'

        artists = list(Artist.search('la'))
        assert len(artists) == 1
        assert len(artists[0].songs) == 1
        assert artists[0].slug == 'lalalalalal'
コード例 #2
0
ファイル: views.py プロジェクト: forkbong/buzuki
def search():
    query = request.args.get('q')
    if not query:
        return redirect(url_for('main.index'))

    songs = list(Song.search(query))

    if len(songs) > 1:
        return render_template(
            'index.html',
            title=query,
            songs=songs,
            admin=session.get('logged_in'),
        )

    if len(songs) == 1:
        return redirect(url_for('main.song', slug=songs[0].slug))

    artists = list(Artist.search(query))

    if len(artists) > 1:
        return render_template(
            'list.html',
            title=query,
            objects=artists,
            detail_url='main.artist',
            admin=session.get('logged_in'),
        )

    if len(artists) == 1:
        return redirect(url_for('main.artist', slug=artists[0].slug))

    if any(scale.name == query for scale in Scale.all()):
        scale = Scale.get(query)
        return redirect(url_for('main.scale', slug=scale.slug))

    abort(404)