Пример #1
0
def new_album():
    """Page for creating a new album."""

    if request.method == 'POST':
        # if empty name field (i.e. user cancelled):
        if request.form['name'].strip() == '':
            return redirect(url_for('show_albums'))

        add_album = Album(name     =request.form['name'],
                          user_id  =login_session['user_id']
                          )
        # try committing changes:
        if not commit_changes(add_album, 'add'):
            return redirect(url_for('show_albums'))

        # create new subdirectory for images:
        add_album.file_path = os.path.join(app.config['UPLOAD_FOLDER'],
                                           str(add_album.id))
        os.makedirs(add_album.file_path)
        session.commit()

        # flash message:
        flash("New album successfully created")

        return redirect(url_for('show_albums'))
    else:
        return render_template('newAlbum.html', title='New Album')
Пример #2
0
def createAlbum(form, login_session, artist):
    newAlbum = Album(name=form['name'],
                     artist=artist.name,
                     artist_id=artist.id,
                     year=form['year'],
                     genre=form['genre'],
                     artwork=form['artwork'],
                     user_id=login_session['user_id'])
    session.add(newAlbum)
    session.commit()
    flash("%s has been added" % newAlbum.name)
    return redirect(url_for('showDiscography', artist_id=newAlbum.artist_id))
Пример #3
0
def newAlbum():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newAlbum = Album(name=request.form['name'],
                         user_id=login_session['user_id'])
        session.add(newAlbum)
        session.commit()
        flash("New album has been added!")
        return redirect(url_for('showAlbums'))
    else:
        return render_template('newAlbum.html')
def newAlbum(artist_id):
    if 'username' not in login_session:
        return redirect('/login')
    artist = session.query(Artist).filter_by(id=artist_id).one()
    if request.method == 'POST':
        newAlbum = Album(name=request.form['name'],
                         description=request.form['description'],
                         year=request.form['year'],
                         numtracks=request.form['numtracks'],
                         cover=request.form['cover'],
                         artist_id=artist_id,
                         user_id=login_session['user_id'])
        session.add(newAlbum)
        session.commit()
        flash('New Album %s Successfully Created' % (newAlbum.name))
        return redirect(url_for('showAlbums', artist_id=artist_id))
    else:
        return render_template('newalbum.html', artist_id=artist_id)
Пример #5
0
def populateDb(username, token):
    """Add items found in the user's Discogs collection to the sqlite DB.

    args: Discogs username, Discogs API token
    """
    # create user
    me = User(name='Gry0u', email='*****@*****.**')
    session.add(me)
    session.commit()
    # get all the release IDs in the user collection
    # then get the infos for each release using the api
    # Use the infos to set values for the new entries in the SQL DB
    # add new entries in DB
    for release in getReleasesID(username, token):
        infos = getReleaseInfo(release, token)
        if infos:
            if not session.query(Genre).filter_by(name=infos['genre']).first():
                genre = Genre(name=infos['genre'], user=me)
                session.add(genre)
                session.commit()
                print 'Genre added'
            else:
                genre = (session.query(Genre).filter_by(
                    name=infos['genre']).first())
            album = Album(title=infos['title'],
                          artist=infos['artist'],
                          label=infos['label'],
                          released=infos['released'],
                          image=infos['image'],
                          genre=genre,
                          user=me)
            session.add(album)
            session.commit()
            print 'Album added'

            for song in infos['songs']:
                song = Song(position=song['position'],
                            title=song['title'],
                            album=album,
                            user=me)
                session.add(song)
                session.commit()
                print 'song added'
    print 'Insertion of new items in DB completed !'
Пример #6
0
def newAlbum(genre_id):
    if 'username' not in login_session:
        return redirect('/login')
    genre = session.query(Genre).filter_by(id=genre_id).one()
    if request.method == 'POST':

            newAlbum = Album(album_name=request.form['album_name'],
                             artist=request.form['artist'],
                             year=request.form['year'],
                             picture_url=request.form['picture_url'],
                             genre_id=genre_id,
                             user_id=login_session['user_id'])

            session.add(newAlbum)
            session.commit()
            flash('New Album %s  Successfully Created' % (newAlbum.album_name))
            return redirect(url_for('showAlbum', genre_id=genre_id))
    else:
        return render_template('newAlbum.html', genre_id=genre_id)
Пример #7
0
def addNewAlbum(artist_id):
    """
	Add a New Album
	"""
    artist = session.query(Artist).filter_by(id=artist_id).one()
    if artist.user_id != login_session['user_id']:
        return "<script>function myFunction() {alert('You are not authorized \
to add albums to this artist. Please add your own artist in order \
to add albums.');}</script><body onload='myFunction()''>"

    if request.method == 'POST':
        newAlbum = Album(name=request.form['name'],
                         description=request.form['description'],
                         year_released=request.form['year_released'],
                         artist_id=artist.id,
                         user_id=login_session['user_id'])
        session.add(newAlbum)
        session.commit()
        flash('New Album %s Successfully Added to %s' %
              (newAlbum.name, artist.name))
        return redirect(url_for('showAlbums', artist_id=artist.id))
    return render_template('newalbum.html', artist=artist)
Пример #8
0
def newAlbum(collection_id):
    """ Create a new album in the database.

    Args:
        collection_id: An integer identifying a distinct collection.

    Returns:
        on GET: Page to create a new album.
        on POST: Redirect to collection page after album has been created.
        Login page when user is not signed in.
        Alert when user is trying to create an album he is not authorized to.
    """
    if 'username' not in login_session:
        return redirect('/login')
    collection = session.query(Collection).filter_by(id=collection_id).one()
    if login_session['user_id'] != collection.user_id:
        return ("<script>function myFunction() {alert('You are not authorized "
                "to add albums to this collection. Please create your own "
                "collection in order to add albums.');}</script><body "
                "onload='myFunction()'>")
    if request.method == 'POST':
        source, filename = process_image_source(request.form['image_source'])
        newAlbum = Album(name=request.form['name'],
                         artist=request.form['artist'],
                         genre=request.form['genre'],
                         year=request.form['year'],
                         description=request.form['description'],
                         cover_source=source,
                         cover_image=filename,
                         collection_id=collection_id,
                         user_id=login_session['user_id'])
        session.add(newAlbum)
        session.commit()
        flash('New album %s album Successfully Created' % (newAlbum.name))
        return redirect(url_for('indexAlbums', collection_id=collection_id))
    else:
        return render_template('newAlbum.html', collection_id=collection_id)
Пример #9
0
def newRelease(genre_id):
    """Render template to add new release and handle post request."""
    if 'username' not in login_session:
        return redirect('/login')
    genre = session.query(Genre).filter_by(id=genre_id).one()
    if request.method == 'POST':
        image = request.form['image'] if request.form[
            'image'] != '' else '/static/record-player.jpeg'
        release = Album(
            title=request.form['title'],
            artist=request.form['artist'],
            label=request.form['label'],
            released=request.form['released'],
            image=image,
            genre_id=genre.id,
            # connected user doesn't have to be
            # the creator of a genre to add a new release to it
            user_id=login_session['user_id'])
        session.add(release)
        session.commit()
        flash('New release added!')
        return redirect(url_for('showReleases', genre_id=genre_id))
    if request.method == 'GET':
        return render_template('newrelease.html', genre=genre)
session.commit()

user2 = User(name='Radiant Moxie', email='*****@*****.**', id=2)
session.add(user2)
session.commit()

#Albums for Sting
artist1 = Artist(user_id=1, name='Sting', picture='/static/Sting.jpg')

session.add(artist1)
session.commit()

album1 = Album(name = 'Brand New Day', description = \
 "From AllMusic.com:\
	By the late '90s, Sting had reached a point where he didn't have to prove \
	his worth every time out; \
	he had so ingrained himself in pop culture, he really had the freedom to \
	do whatever he wanted."                        ,
               year_released = 1999, artist = artist1, picture = '/static/BrandNewDay.jpg',
               user_id = 1)

session.add(album1)
session.commit()

album2 = Album(name = 'The Dream of the Blue Turtles', description = \
 "From AllMusic.com:\
	Sting had a lot to prove on his first post-Police effort, and he proved \
	himself up to the task of \
	establishing a distinctive identity as a solo artist."                                                       ,
               year_released = 1985, artist = artist1,
               picture = '/static/DreamTurtles.jpg', user_id = 1)
Пример #11
0
             email="*****@*****.**",
             picture='https://i.ytimg.com/vi/gt5cl0jmrwA/hqdefault.jpg')
session.add(User1)
session.commit()

# Add the Beatles
beatles = Artist(user_id=1, name="The Beatles")

session.add(beatles)
session.commit()

rubbersoul = Album(
    user_id=1,
    name="Rubber Soul",
    description=
    "Their first undeniable classic, the group shows an affinity for Bob Dylan with thoughtful lyricism",
    year='1965',
    numtracks="14",
    cover='http://www.beatlesinterviews.org/al6.jpg',
    artist=beatles)

session.add(rubbersoul)
session.commit()

revolver = Album(
    user_id=1,
    name="Revolver",
    description=
    "Heralding the psychedlic era, many believe this is the group's crowning achievment.",
    year='1966',
    numtracks="14",
Пример #12
0
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

User2 = User(name = "Sahe Mayson", email="*****@*****.**")
session.add(User2)
session.commit()

genre1 = Genre(name="Rock", user_id =1)

album1 = Album(album_name = "No Plan EP",year = "2017", artist = "David Bowie", genre= genre1
	, catalog_id ="88985419612", picture_url="https://upload.wikimedia.org/wikipedia/en/thumb/d/d1/No_Plan_EP_%28Front_Cover%29.jpg/220px-No_Plan_EP_%28Front_Cover%29.jpg" )

session.add(album1)
session.commit()

album2 = Album(album_name = "The Eyes",year = "2017", artist = "Plastic Tones", genre= genre1
	, catalog_id ="MONO-004", picture_url="http://stupidorecords.com/1065-home_default/plastic-tones-more-trouble-7.jpg" )

session.add(album2)
session.commit()

album3 = Album(album_name = "Synchronicity",year = "1983", artist = "The Police", genre= genre1
	, catalog_id ="A&M SP-3735", picture_url="http://www.thepolice.com/sites/g/files/g2000003646/f/styles/opengraph_thumbnail/public/albums/600_3.jpg?itok=gzla1OoC" )

session.add(album3)
session.commit()
Пример #13
0
    name='letlive.',
    id=4,
    user_id=1,
    image=
    'http://epitaph.com/media/artists/letlive_MegaImage_kZWFHtn.jpg.600x375_q90.jpg'
)
session.add(artist4)
session.commit()

# Albums

album1 = Album(
    user_id=1,
    name='Distances',
    id=1,
    artist='The Afterparty',
    year='2014',
    artist_id=1,
    artwork=
    'http://www.hitthefloor.com/wp-content/uploads/2014/03/PDGIQ4FT.jpeg')
session.add(album1)
session.commit()

album2 = Album(
    user_id=1,
    name='Hope',
    id=2,
    artist='Manchester Orchestra',
    year='2014',
    artist_id=2,
    artwork=
Пример #14
0
album1 = Album(name = 'Brand New Day', description = \
 "From AllMusic.com:\
	By the late '90s, Sting had reached a point where he didn't have to prove \
	his worth every time out; \
	he had so ingrained himself in pop culture, he really had the freedom to \
	do whatever he wanted. \
	He had that attitude on Mercury Falling, but it was too somber and serious,\
	 everything that its successor, \
	Brand New Day, is not. Light, even effervescent, Brand New Day feels like \
	little else in Sting's catalog. \
	Not that it represents a new beginning, contrary to what the title may \
	promise. \
	The album is not only firmly within his tradition, it sounds out of time \
	-- it's odd how close \
	Brand New Day comes to feeling like a sequel to Nothing Like the Sun. \
	Musically, that is. \
	The sparkling, meticulous production and the very tone of the music -- \
	ranging from light funk to \
	mellow ballads to the Lyle Lovett tribute 'Fill Her Up' -- are of a piece \
	with Sting's late-'80s work. \
	That's the main thing separating it from Ten Summoner's Tales, his other \
	straight pop album -- \
	well, that, and the levity. There are no overarching themes, no political \
	messages on Brand New Day \
	-- only love songs, story songs, and, for lack of a better term, \
	inspirational exhortations. \
	This is all a good thing, since by keeping things light he's managed to \
	craft an appealing, engaging record. \
	It may not ask as much from its audience as Sting's other '90s efforts, \
	but it's immediately enjoyable, \
	which isn't the case for its cousins. Brand New Day doesn't boast any new \
	classics, \
	and it does sound a little dated, but it's well-crafted, melodic, and has \
	a good sense of humor -- \
	exactly the kind of record Sting should be making as he embarks on the \
	third decade of his career."                             ,
               year_released = 1999, artist = artist1, picture = '/static/BrandNewDay.jpg',
               user_id = 1)
Пример #15
0
#create users
User1 = User(name="Widya", email="*****@*****.**")
session.add(User1)
session.commit()

User2 = User(
    name="Robo Barista",
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(User2)
session.commit()

#Songs for Parachutes album
album1 = Album(name="Parachutes")

session.add(album1)
session.commit()

songItem1 = SongItem(name="Don't Panic",
                     year="2001",
                     length="2:17",
                     genre="alternative rock, soft rock",
                     album=album1,
                     album_id=1)

session.add(songItem1)
session.commit()

songItem2 = SongItem(name="Shiver",