def albums_by_artist(artist): albums = [] sql = "SELECT * FROM albums WHERE artist_id = %s" values = [artist.id] results = run_sql(sql, values) for row in results: label = label_repository.select(row['label_id']) genre = genre_repository.select(row['genre_id']) album = Album(row['title'], artist, genre, row['price'], row['cost_price'], row['release_year'], row['cover_art'], row['stock'], label, row['sales_count'], row['id']) albums.append(album) return albums
def select(id): album = None sql = "SELECT * FROM albums WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: artist = artist_repository.select(result['artist_id']) label = label_repository.select(result['label_id']) genre = genre_repository.select(result['genre_id']) album = Album(result['title'], artist, genre, result['price'], result['cost_price'], result['release_year'], result['cover_art'], result['stock'], label, result['sales_count'], result['id']) return album
def select_all(): albums = [] sql = "SELECT * FROM albums ORDER BY artist_id ASC, release_year DESC" results = run_sql(sql) for row in results: artist = artist_repository.select(row['artist_id']) label = label_repository.select(row['label_id']) genre = genre_repository.select(row['genre_id']) album = Album(row['title'], artist, genre, row['price'], row['cost_price'], row['release_year'], row['cover_art'], row['stock'], label, row['sales_count'], row['id']) albums.append(album) return albums
def update_album(id): title = request.form['title'] artist = artist_repository.select(request.form['artist_id']) genre = genre_repository.select(request.form['genre_id']) price = float(request.form['price']) cost_price = float(request.form['cost-price']) release_year = request.form['release-year'] cover_art = request.form['cover-art'] stock = int(request.form['stock']) label = label_repository.select(request.form['label_id']) sales_count = int(request.form['sales_count']) album = Album(title, artist, genre, price, cost_price, release_year, cover_art, stock, label, sales_count, id) album_repository.update(album) return render_template("/albums/updated.html", **locals())
def bestsellers(): albums = [] sql = "SELECT * FROM albums ORDER BY sales_count DESC LIMIT 12" results = run_sql(sql) for row in results: artist = artist_repository.select(row['artist_id']) label = label_repository.select(row['label_id']) genre = genre_repository.select(row['genre_id']) album = Album(row['title'], artist, genre, row['price'], row['cost_price'], row['release_year'], row['cover_art'], row['stock'], label, row['sales_count'], row['id']) albums.append(album) return albums # Search function? # "SELECT title, name FROM albums INNER JOIN artists on artists.id = albums.artist_id WHERE name LIKE 'Leonard Cohen';"
def genre_albums(id): genre = genre_repository.select(id) genres_albums = genre_repository.albums_by_genre(genre) return render_template("genres/show.html", genre=genre, albums=genres_albums)