示例#1
0
def songs_edit(song_id):

    s = Song.query.get(song_id)

    if s.account_id != current_user.id:
        flash("You can only edit songs you've added yourself!")
        return redirect(url_for("songs_index"))

    form = SongForm(request.form)

    if request.method == "GET":
        form.name.default = s.name
        form.artist.default = s.artist
        form.length.default = s.length
        form.songkey.default = s.songkey
        form.process()
        return render_template("songs/edit.html", form=form, song=s)

    s.name = form.name.data
    s.artist = form.artist.data
    s.length = form.length.data
    s.songkey = form.songkey.data

    db.session().commit()
    flash("Song successfully edited!")
    return redirect(url_for("songs_index"))
示例#2
0
文件: views.py 项目: vikketii/tsoha
def songs_form():
    form = SongForm()
    form.song_artist.choices = [(artist.id, artist.name)
                                for artist in Artist.query.order_by('name')]
    form.album.choices = [(album.id, album.name)
                          for album in Album.query.order_by('name')]

    return render_template('songs/new.html', form=form)
示例#3
0
def songs_create():
    form = SongForm(request.form)

    if not form.validate():
        return render_template("songs/new.html", form=form)

    s = Song(form.name.data)
    s.artist = form.artist.data
    s.length = form.length.data
    s.songkey = form.songkey.data
    s.account_id = current_user.id

    db.session().add(s)

    db.session().commit()

    flash("Song successfully created!")
    return redirect(url_for("songs_index"))
示例#4
0
def songs_create():
    form = SongForm(request.form)

    if not form.validate():
        return render_template("songs/new.html", form=form, song_error="")

    song = Song.query.filter_by(songname=form.songname.data).first()
    artist = Artist.query.filter_by(artistname=form.artistname.data).first()

    if song and artist:
        artistsong = Song.check_artistsong(song, artist)

        if artistsong:
            return render_template(
                "songs/new.html",
                form=form,
                song_error="This song has been added already")

        else:
            song = Song(form.songname.data)
            Song.new_song_dbs(song, artist)
            return redirect(url_for("songs_index"))

    elif song:
        song = Song(form.songname.data)
        song.description = form.description.data
        artist = Artist(form.artistname.data)
        Song.new_song_dbs(song, artist)
        return redirect(url_for("songs_index"))

    elif not song:
        song = Song(form.songname.data)
        song.description = form.description.data

        if artist:
            Song.new_song_dbs(song, artist)
            return redirect(url_for("songs_index"))

        if not artist:
            artist = Artist(form.artistname.data)
            Song.new_song_dbs(song, artist)
            return redirect(url_for("songs_index"))

    return redirect(url_for("songs_index"))
示例#5
0
文件: views.py 项目: vikketii/tsoha
def songs_create():
    form = SongForm(request.form)
    form.song_artist.choices = [(artist.id, artist.name)
                                for artist in Artist.query.order_by('name')]
    form.album.choices = [(album.id, album.name)
                          for album in Album.query.order_by('name')]

    if not form.validate():
        return render_template('songs/new.html', form=form)

    song = Song(form.name.data, form.album.data)
    song.account_id = current_user.id

    artist = Artist.query.get(form.song_artist.data)
    artist.song_artist.append(song)

    db.session().add(song)
    db.session().add(artist)
    db.session().commit()

    return redirect(url_for('songs_index'))
示例#6
0
def songs_create():
    """Method gets user input from form and adds new song to db"""
    form = SongForm(request.form)

    if not form.validate():
        return render_template("songs/new.html", form=form)

    song_already_added = Song.query.filter_by(name=form.name.data,
                                              artist=form.artist.data).first()

    if song_already_added:
        form.name.errors.append("Song is already in database")
        return render_template("songs/new.html", form=form)

    new_song = Song(form.name.data, form.artist.data)
    new_song.account_id = current_user.id
    db.session().add(new_song)
    db.session().commit()

    flash('Song successfully added')
    return redirect(url_for("songs_index"))
示例#7
0
def songs_change_name(song_id):

    song = Song.query.get(song_id)
    artist_id = Song.find_artist_for_song(song)
    artist = Artist.query.get(artist_id)
    form = ChangeSongForm(obj=song)  #the form prefilled with the song

    if not form.validate():
        return render_template("songs/change.html",
                               song=song,
                               artist=artist,
                               form=form)

    return render_template("songs/change.html",
                           song=song,
                           artist=artist,
                           form=SongForm(obj=song))
示例#8
0
def song_choose(song_id):

    song = Song.query.get(song_id)
    form = SongForm(request.form)

    accountsong = Accountsongs.check_if_exists(song, current_user)

    if accountsong:
        return render_template(
            "songs/mylist.html",
            form=form,
            mysongs=Song.find_songs_for_current_user(),
            song_error="You have this song on your list already")

    if not accountsong:
        accountsong = Accountsongs(current_user, song, 0, 0)

        db.session().add(accountsong)
        db.session().commit()

    return redirect(url_for("show_mylist"))
示例#9
0
def songs_form():
    """View controller for adding new song"""
    return render_template("songs/new.html", form=SongForm())
示例#10
0
def songs_form():
    return render_template("songs/new.html", form=SongForm())
示例#11
0
def show_stats():

    return render_template("songs/stats.html",
                           stat_songs=Song.how_many_have_this(),
                           form=SongForm())
示例#12
0
def show_mylist():

    return render_template("songs/mylist.html",
                           mysongs=Song.find_songs_for_current_user(),
                           form=SongForm())