def songs(request): if request.method== 'POST': form=SongForm(request.POST) if form.is_valid(): form.save() return redirect('songs') else: form=SongForm() songs=Song.objects.all().order_by('-added_on') return render_to_response('songs.html' , locals(), context_instance=RequestContext(request))
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ # ADD THE NECESSARY CODE HERE FOR THIS ROUTE TO WORK form = SongForm() if form.validate_on_submit(): title = form.title.data artist = form.artist.data if Song.query.filter(Song.title == title, Song.artist == artist).first(): form.title.errors.append( 'A song with that name and artist already exists in the database.' ) return render_template('new_song.html', form=form) new_song = Song(title=title, artist=artist) db.session.add(new_song) db.session.commit() return redirect('/songs') return render_template('new_song.html', form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): title = form.title.data artist = form.artist.data # Check if inputs are empty spaces if title.isspace() or artist.isspace(): flash("Title and Artist names are required", "danger") return redirect("/songs/add") song = Song(title=title, artist=artist) db.session.add(song) db.session.commit() flash("Song Added!", "success") return redirect("/songs") return render_template("new_song.html", form=form)
def home(): form = SongForm() if form.validate_on_submit(): context_uri = form.link.data username = sys.argv[1] scope = 'user-read-private user-read-playback-state user-modify-playback-state' # You can find other scopes here: https://developer.spotify.com/documentation/general/guides/scopes/ client_id = 'ce89313ce56745faa9fba21be85de838' client_secret = 'b76fb4e1082040bb8ca8ac3076a9e58e' redirect_uri = 'http://www.google.com/' # Erase cache and prompt for user permission try: token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) # add scope except (AttributeError, JSONDecodeError): os.remove(f".cache-{username}") token = util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri) # add scope # Create our spotify object with permissions spotifyObject = spotipy.Spotify(auth=token) #Get current device devices = spotifyObject.devices() print(json.dumps(devices, sort_keys=True, indent=4)) deviceID = devices['devices'][0]['id'] #Start playback spotifyObject.start_playback(deviceID, context_uri) #'spotify:playlist:4mqjYC4Ov8u0DrkCcsALbA' return render_template('home.html', form=form, form=)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ # ADD THE NECESSARY CODE HERE FOR THIS ROUTE TO WORK form = SongForm() # if the CSRF token is validated after the form is submitted if form.validate_on_submit(): title = form.title.data artist = form.artist.data # Create a new playlist instance new_song = Song(title=title, artist=artist) db.session.add(new_song) db.session.commit() flash("Song created!") return redirect('/songs') return render_template('new_song.html', form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ # ADD THE NECESSARY CODE HERE FOR THIS ROUTE TO WORK form = SongForm() if request.method == "GET": return render_template('new_song.html', form=form) elif request.method == "POST": if form.validate_on_submit(): title = form.title.data artist = form.artist.data song = Song(title=title, artist=artist) db.session.add(song) db.session.commit() return redirect('/songs') else: return render_template('new_song.html', form=form) else: flash('something went wrong') return redirect('/songs')
def add_song(): form = SongForm() if form.validate_on_submit(): Song.create_song(form=form) return redirect('/songs') return render_template('new_song.html', form=form)
def add(): form = SongForm() if form.validate_on_submit(): song = form.song.data store_song(song) flash("Stored Song'[]'".format(description)) return redirect(url_for('index')) return render_template('add.html', form=form)
def addsong(request): if request.user.is_authenticated(): if request.is_ajax(): form = request.POST.dict() response_data = {} if form['artist'] and form['song_name']: response_data = serializers.serialize( "json", Song.objects.filter(artist__contains=form['artist'], song_name__contains=form['song_name'])) elif form['artist']: response_data = serializers.serialize( "json", Song.objects.filter(artist__contains=form['artist'])) elif form['song_name']: response_data = serializers.serialize( "json", Song.objects.filter(song_name__contains=form['song_name'])) return HttpResponse(json.dumps(response_data), content_type="application/json") elif request.method == 'POST': if u'vote' in request.POST.dict(): form = request.POST.dict() votesong(request.user.id, int(form['song_id'])) return redirect('mysong') else: form = SongForm(request.POST) if form.is_valid(): song = form.save(commit=False) song.user = request.user song.code = get_song_link(song.artist, song.song_name) song.save() SongVoted(user=request.user, song=song).save() return redirect('mysong') else: form = SongForm() return render(request, "addsong.html", {'form': form}) else: return redirect('index')
def api_songs(): form = SongForm() if form.is_submitted(): result = request.form songs_dict['song_name'] = result['song_name'] songs_dict['artist'] = result['artist'] songs_dict['date_of_release'] = result['date_of_release'] return redirect(url_for('apiget', action="all")) return render_template('songs.html', form=form)
def new_song(): """ Creates form for input of new song details """ search_form = SearchForm() form = SongForm() return render_template('new_song.html', title='Add New Song', form=form, search_form=search_form)
def edit_song(song_id): song = SongModel.get_by_id(song_id) form = SongForm(obj=song) if request.method == "POST": if form.validate_on_submit(): song.name = form.data.get('name') song.content = form.data.get('content') song.put() flash(u'Song %s successfully saved.' % song_id, 'success') return redirect(url_for('list_songs')) return render_template('edit_song.html', song=song, form=form)
def song_create(request): if request.method == 'POST': form = SongForm(request.POST) unit_id = request.POST.get('album') print 'unit_id ', unit_id if form.is_valid( ): # coming from save button click, after running clean_title() q = Song() ar = '' for each in form: if type( each.field ) is forms.ModelChoiceField: # get the value from 'select' value_needed = form.cleaned_data[each.name] if each.name == 'artist': ar = Artist.objects.get( name=value_needed) # Artist instance from select setattr(q, each.name, ar) else: alb = ar.album_set.all() # all albums for this artist title = alb[int(unit_id) - 1] al = Album.objects.get( title=title) # album instance from select setattr(q, each.name, al) else: value_needed = form.cleaned_data[ each.name] # other fields - title field setattr(q, each.name, value_needed) q.save() print 'valid ' return redirect('songs') # you won't see 'form' in url else: # when getting to page at first - Stay, or with 'GET' method form = SongForm() # empty form print 'Initial song_create page ' return render( request, 'mymusic/song_create.html', { 'form': form # show empty form in initial state or filled form in case the user started to type and submitted })
def home(): form = SongForm() if request.method == 'POST': artist = form.artist.data song = form.song.data choice = form.choice.data return redirect(url_for('predict', artist=artist, song=song, choice=choice)) return render_template('index_copy.html', form=form, legend='Predict Song!', title=' ')
def add_song(): form = SongForm(request.form) if request.method == 'POST' and form.validate(): title = form.title.data lyrics = form.lyrics.data song = Song(title=title, lyrics=lyrics, author=session['username']) db_session.add(song) db_session.commit() # cur.execute("INSERT INTO songs(title, body, author) VALUES(%s, %s, %s)",(title, body, session['username'])) flash('song Created', 'success') return redirect(url_for('dashboard')) return render_template('add_song.html', form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add song to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): db.session.add(Song(title=form.title.data, artist=form.artist.data)) db.session.commit() return redirect('/songs') else: return render_template('new_song.html', form=form)
def add_song(): """Handle add-song form.""" form = SongForm() if form.validate_on_submit(): title = form.title.data artist = form.artist.data new_song = Song(title=title, artist=artist) db.session.add(new_song) db.session.commit() return redirect("/songs") return render_template("new_song.html", form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): song = Song(title=form.title.data, artist=form.artist.data) db.session.add(song) db.session.commit() return redirect(f"/songs/{song.id}") return render_template("new_song.html", form=form)
def add_song(id): if not user_check(id): playlists = db.get_public_playlists() error = "You are not allowed to do this command." return render_template('home.html', error=error, playlists=playlists) form = SongForm(request.form) if request.method == 'POST' and form.validate(): title = form.title.data artist = form.artist.data genre = form.genre.data duration = form.duration.data db.add_song(title, artist, genre, duration, id) flash('Song added', 'success') return redirect(url_for('edit_playlist', id=id)) return render_template('add_song.html', form=form)
def edit_song(id): result = Song.query.filter_by(id=id).first() form = SongForm() form.title.data = result.title form.lyrics.data = result.lyrics if request.method == 'POST' and form.validate(): result.title = request.form['title'] result.lyrics = request.form['lyrics'] db_session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('dashboard')) return render_template('edit_song.html', form=form)
def new_song(): """ Add a new album """ form = SongForm(request.form) if request.method == 'POST' and form.validate(): # save the album song = Song() save_changes(song, form, new=True) flash('Song uploaded successfully!') return redirect('/upload') return render_template('new_album.html', form=form) #should be new_song, not new_album
def edit(id): qry = db_session.query(Song).filter(Song.id == id) song = qry.first() if song: form = SongForm(formdata=request.form, obj=song) if request.method == 'POST' and form.validate(): # save edits save_changes(song, form) flash('Song updated successfully!') return redirect('/search') return render_template('edit_album.html', form=form) #edit_song, not edit_album else: return 'Error loading #{id}'.format(id=id)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): title = request.form['title'] artist = request.form['artist'] song = Song(title=title, artist=artist) db.session.add(song) db.session.commit() return redirect('/songs') else: return render_template('new_song.html', form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): title = form.title.data artist = form.artist.data song = Song(title=title, artist=artist) db.session.add(song) db.session.commit() flash(f"Song added", "primary") return redirect("/songs") return render_template("new_song.html", form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ # ADD THE NECESSARY CODE HERE FOR THIS ROUTE TO WORK form = SongForm() if form.validate_on_submit(): song = Song() form.populate_obj(song) db.session.add(song) db.session.commit() return redirect(url_for('show_all_songs')) return render_template("new_song.html", form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): data = {key: value for key, value in form.data.items() if key != 'csrf_token'} song = Song(**data) db.session.add(song) db.session.commit() return redirect(url_for("show_all_songs")) return render_template("new_song.html", form=form)
def createsong(album_id): album = Album.query.get(album_id) form = SongForm() if form.validate_on_submit(): song = Song(name=form.name.data, link=form.link.data, album_id=album.id) album.songs.append(song) db.session.add(song) db.session.commit() return redirect('/albums') return render_template('/home/createsong.html', action="Add", form=form, title="Add song")
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): data = {k: v for k, v in form.data.items() if k != 'csrf_token'} new_song = Song(**data) db.session.add(new_song) db.session.commit() flash(f"{new_song.title} has been added!", 'success') return redirect('/songs') else: return render_template('new_song.html', form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ # ADD THE NECESSARY CODE HERE FOR THIS ROUTE TO WORK form = SongForm() if form.validate_on_submit(): title = form.title.data artist = form.artist.data new_song = Song(title=title, artist=artist) db.session.add(new_song) db.session.commit() return redirect("/songs") return render_template("new_song.html", form=form)
def add_song(): """Handle add-song form: - if form not filled out or invalid: show form - if valid: add playlist to SQLA and redirect to list-of-songs """ form = SongForm() if form.validate_on_submit(): data = {k: v for k, v in form.data.items() if k != "csrf_token"} new_song = Song(**data) # new_pet = Pet(name=form.name.data, age=form.age.data, ...) db.session.add(new_song) db.session.commit() flash(f"{new_song.title} added.") return redirect('/songs') else: # re-present form for editing return render_template("new_song.html", form=form)