def show_band(band_id): error = None try: band = db_session.query(Band).filter(Band.id == band_id).one() albums = db_session.query(Album).filter(Album.band_id == band_id) except NoResultFound: abort(404) return render_template('show-band.html', error = error, band = band, albums = albums)
def show_album(album_id): error = None try: album = db_session.query(Album).filter(Album.id == album_id).one() band = db_session.query(Band).filter(Band.id == album.band_id).one() tracks = db_session.query(Track).filter(Track.album_id == album_id) except NoResultFound: abort(404) return render_template('show-album.html', error = error, album = album, band_name = band.name, track_list = tracks, band_id = band.id)
def delete_band(band_id): if request.method=='POST': band = db_session.query(Band).filter(Band.id == band_id).one() db_session.delete(band) db_session.commit() return redirect(url_for('show_bands')) else: band = db_session.query(Band).filter(Band.id == band_id).one() return render_template('delete-band.html', band = band)
def show_albums(): error = None try: albums = db_session.query(Album).order_by(Album.name) except NoResultFound: error = 'No albums at all in the database :(' return render_template('show-album-list.html', error = error, album_list = albums)
def show_bands(): error = None try: bands = db_session.query(Band).order_by(Band.name) except NoResultFound: error = 'No bands at all in the database :(' return render_template('show-band-list.html', error = error, band_list = bands)
if line[0] == '~': line = album_data.readline() #read the '-' line elif line[0] == '@': line = album_data.readline() elif line[0] == '"': #read the trackline track_data = line.split('-') track_name = track_data[0] time = track_data[1].split(':') track_duration = int(time[0]) * 60 + int(time[1]) track = Track(track_name, track_duration) line = album_data.readline() album = db_session.query(Album).filter(Album.name == tmp[0]).one() track.album_id = album.id db_session.add(track) else: #this is a album data line, need to init the album table tmp = [s.strip() for s in line.split(',')] album_name = tmp[0] album_label = tmp[1] album_year = int(tmp[2]) album = Album(album_name, album_year, album_label) line = album_data.readline() band = db_session.query(Band).filter(Band.name == tmp[3]).one()
if line[0]=='~': line = album_data.readline() #read the '-' line elif line[0] == '@': line = album_data.readline() elif line[0] == '"':#read the trackline track_data = line.split('-') track_name = track_data[0] time = track_data[1].split(':') track_duration = int(time[0])*60+int(time[1]) track = Track(track_name, track_duration) line = album_data.readline() album = db_session.query(Album).filter(Album.name == tmp[0]).one() track.album_id = album.id db_session.add(track) else:#this is a album data line, need to init the album table tmp = [s.strip() for s in line.split(',')] album_name = tmp[0] album_label = tmp[1] album_year = int(tmp[2]) album = Album(album_name, album_year, album_label) line = album_data.readline()