コード例 #1
0
ファイル: app.py プロジェクト: BrandonLMcintosh/DatabaseDJ
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')
コード例 #2
0
ファイル: app.py プロジェクト: MBloom/JukeBerry
def add() :
    form = SongForm(request.form)
    if form.validate():
        songData = form.data['song'].split(" - ")
        notTitle = songData[1].split(" (")
        artist = notTitle[0]
        album = notTitle[1].split(")")[0]
        song = models.get_song(songData[0], artist, album)
        user = models.get_user(current_user.get_id())
        print song.id
        print song.artist
        print song.album
        print song.pi_owner
        if song != None and user != None:
            uname = current_user.get_id()
            all_songs = g.db.query(Song).all()
            your_songs = g.db.query(Queue).filter_by(owner=uname).all()
            queue = g.db.query(Queue).all()
            nextSong = Queue(id=song.id, album = song.album, artist = song.artist, title = song.title, pi_owner = song.pi_owner, owner=user.name)
            qsong = models.get_qsong(songData[0], artist, album)
            if qsong == None:
                g.db.add(nextSong)
                g.db.flush()
                return redirect(url_for("home"))
                #render_template('home.html', your_songs=your_songs, uname=uname, songs=all_songs)
            else:
                return render_template('home.html', your_songs=your_songs, uname=uname, songs=all_songs, error="You've already added that song to the list!", queue=queue)
                #return render_template("home.html", ) 
            #return redirect(url_for("home"))
        return render_template("home.html", error="Song not in available list.")
    return render_template("home.html", error="Uhoh. Looks like you forgot to enter a song!")
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
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)
コード例 #6
0
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=)
コード例 #7
0
ファイル: app.py プロジェクト: CalebPenning/database-dj
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)
コード例 #8
0
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)
コード例 #9
0
ファイル: main.py プロジェクト: davatar2000/dbisworkshops
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)
コード例 #10
0
ファイル: views.py プロジェクト: mdamien/ponysynth
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)
コード例 #11
0
ファイル: views.py プロジェクト: rosskarchner/wedding
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))
コード例 #12
0
ファイル: views.py プロジェクト: wintergalt/mysite
def new_song_submit(req):
	if req.method == 'POST':
		form = SongForm(req.POST, req.FILES)
        print req
        if form.is_valid():
            handle_uploaded_mp3(req.FILES['mp3_file'])
            form.save()
            return index(req)
        else:
            print 'form is not valid'
            return render_to_response('tabcollection/new_song.html', { 'form': form }, 
								context_instance=RequestContext(req))
コード例 #13
0
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)
コード例 #14
0
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)
コード例 #15
0
ファイル: app.py プロジェクト: DanBrown501/Playlist-app
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)
コード例 #16
0
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)
コード例 #17
0
ファイル: views.py プロジェクト: itucsdb1913/itucsdb1913
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)
コード例 #18
0
ファイル: main.py プロジェクト: masgrebnesor/MusicMatchup
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
コード例 #19
0
ファイル: main.py プロジェクト: masgrebnesor/MusicMatchup
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)
コード例 #20
0
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)
コード例 #21
0
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)
コード例 #22
0
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)
コード例 #23
0
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)
コード例 #24
0
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")
コード例 #25
0
ファイル: views.py プロジェクト: stuntman723/rap-analyzer
def new_song(request):
    if request.method == "POST":
        form = SongForm(request.POST)
        if form.is_valid():
            data = analyze(form.cleaned_data['lyrics'])
            try :
                artist = Artist.objects.all().filter(name=form.cleaned_data['artist-name'])
            except:
                artist = Artist(name=form.cleaned_data['artist_name'])
                artist.save()
            song = Song(name=form.cleaned_data['song_name'], lyrics = form.cleaned_data['lyrics'], artist=artist,
                        number_of_words= data['total_words'], number_unique_words=data['unique_words'],
                        unique_word_percent=data['percentage'], repeated_rhymes=data['repeated_rhymes'],
                        bad_words=data['bad_words'], thug_rating=data['thug_rating'], avg_syllables=data['thug_rating'])
            song.save()
            return redirect("/")
    form = SongForm()
    return render(request, 'lyrics/new_song.html', { 'form': form })
コード例 #26
0
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)
コード例 #27
0
ファイル: app.py プロジェクト: erojas4704/Classes
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)
コード例 #28
0
ファイル: app.py プロジェクト: mahdimq/playlist-app
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)
コード例 #29
0
ファイル: views.py プロジェクト: shrujancheruku/Music-picker
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)
コード例 #30
0
ファイル: app.py プロジェクト: williamthethird/DatabaseDJ
def add_song():
    print(request.form)
    #    """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(title=form.title.data, artist=form.artist.data)
        # flash(
        #     f"Artist new song: artist is {artist}, story is {story}")
        # sg = Song(artist=artist, story=story)

        db.session.add(song)
        db.session.commit()
        return redirect('/')
    else:
        return render_template('new_song.html', form=form)
コード例 #31
0
ファイル: app.py プロジェクト: hvanlear/database-assessment-
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)
コード例 #32
0
ファイル: views.py プロジェクト: dganit04/music
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
        })
コード例 #33
0
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=' ')
コード例 #34
0
ファイル: views.py プロジェクト: Fajkowsky/PlayList
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')
コード例 #35
0
ファイル: views.py プロジェクト: mdamien/ponysynth
def list_songs():
    """List all songs"""
    import_form = ImportForm()
    songs_unfiltered = SongModel.query()
    songs = [song for song in songs_unfiltered if song.added_by == users.get_current_user()]
    
    form = SongForm()
    if form.validate_on_submit():
        song = SongModel(
            name=form.name.data,
            content=form.content.data,
            added_by=users.get_current_user()
        )
        try:
            song.put()
            song_id = song.key.id()
            flash(u'Song %s successfully saved.' % song_id, 'success')
            return redirect(url_for('list_songs'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'info')
            return redirect(url_for('list_songs'))
    return render_template('list_songs.html', songs=songs, form=form, import_form=import_form)
コード例 #36
0
ファイル: app.py プロジェクト: sanspanic/25.0-playlists
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

        new_song = Song(title=title, artist=artist)

        db.session.add(new_song)
        db.session.commit()

        flash('Successfully added new song!', "success")
        return redirect('/songs')

    return render_template('new_song.html', form=form)
コード例 #37
0
ファイル: views.py プロジェクト: walkandre/opentapes
def create(request):
	if request.method == 'POST':
		url = request.POST.get('playlist_location', '')
		#
		#regexp here!!!!!!!!!
		#
		result = urlfetch.fetch(url + "code/xspf.php")

		if result.status_code == 200:
#			xml = minidom.parseString(unicode(result.content, "utf-8" ))
			try:
				xml = minidom.parseString(result.content.replace("&", "&"))
			except:
				return render_to_response('create.html', {'flash' : "Ops. Something went wrong!!!..."})
			
			tracks = xml.getElementsByTagName('track')
			playlist = Playlist(title="lorem ipsum dolor", location=url)
			playlist.save()

			for song in tracks:
				loc = song.getElementsByTagName('location')[0]
				me = song.getElementsByTagName('meta')[0]
				ti = song.getElementsByTagName('title')[0]
				fo = song.getElementsByTagName('info')[0]

				s = SongForm({
					'location': getText(loc.childNodes),
					'meta': getText(me.childNodes),
					'title': getText(ti.childNodes),
					'info': getText(fo.childNodes),
				})
				if s.is_valid():
					s.playlist = playlist
					s.save()

			return render_to_response('create.html', {'flash' : "Playlist added! <a href=\"/\">Go back to home page.</a>"})

	return render_to_response('create.html')