Exemplo n.º 1
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"))
Exemplo n.º 2
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"))
Exemplo n.º 3
0
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'))
Exemplo n.º 4
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"))