diff --git a/data/interfaces/default/managealbums.html b/data/interfaces/default/managealbums.html index aaef784b..6e88cd04 100644 --- a/data/interfaces/default/managealbums.html +++ b/data/interfaces/default/managealbums.html @@ -1,7 +1,8 @@ <%inherit file="base.html" /> <%! - from headphones import db - import headphones + # Removed direct DB imports/interactions here, as data should be pre-fetched server-side. + # from headphones import db + import headphones # Still needed for headphones.LOSSY_MEDIA_FORMATS if used %> <%def name="headerIncludes()"> @@ -17,9 +18,10 @@

Manage Albums

-
+ <%-- Renamed ID to avoid conflict with markalbum div --%>
Mark selected albums as - @@ -28,25 +30,27 @@ - + <%-- This hidden input might be redundant if data is sent via AJAX --%>
- - - - - - - - - + <%-- Added ID for easier targeting --%> + + + + + + + + %for album in albums: <% + # Assuming these values are now pre-calculated and available in the 'album' dict + # Removed all in-template database queries for performance. if album['Status'] == 'Skipped': grade = 'Z' elif album['Status'] == 'Wanted': @@ -58,45 +62,30 @@ else: grade = 'A' - myDB = db.DBConnection() - totaltracks = len(myDB.select('SELECT TrackTitle from tracks WHERE AlbumID=?', [album['AlbumID']])) - havetracks = len(myDB.select('SELECT TrackTitle from tracks WHERE AlbumID=? AND Location IS NOT NULL', [album['AlbumID']])) + len(myDB.select('SELECT TrackTitle from have WHERE ArtistName like ? AND AlbumTitle LIKE ? AND Matched = "Failed"', [album['ArtistName'], album['AlbumTitle']])) - - try: - percent = (havetracks*100.0)/totaltracks - if percent > 100: - percent = 100 - except (ZeroDivisionError, TypeError): - percent = 0 - totaltracks = '?' - - avgbitrate = myDB.action("SELECT AVG(BitRate) FROM tracks WHERE AlbumID=?", [album['AlbumID']]).fetchone()[0] - if avgbitrate: - bitrate = str(int(avgbitrate)/1000) + ' kbps' - else: - bitrate = '' - - albumformatcount = myDB.action("SELECT COUNT(DISTINCT Format) FROM tracks WHERE AlbumID=?", [album['AlbumID']]).fetchone()[0] - if albumformatcount == 1: - albumformat = myDB.action("SELECT DISTINCT Format FROM tracks WHERE AlbumID=?", [album['AlbumID']]).fetchone()[0] - elif albumformatcount > 1: - albumformat = 'Mixed' - else: - albumformat = '' - - lossy_formats = [str.upper(fmt) for fmt in headphones.LOSSY_MEDIA_FORMATS] - + # Use the pre-calculated values from the album object + totaltracks_display = album.get('TotalTracks', '?') + havetracks_display = album.get('HaveTracks', 0) + percent_display = album.get('PercentOwned', 0) + bitrate_display = album.get('BitrateDisplay', '') # e.g., '192 kbps' + albumformat_display = album.get('AlbumFormat', '') # e.g., 'MP3', 'FLAC', 'Mixed' %> - - - - - - - - - + <%-- Unique name and class for individual checkboxes --%> + + + + + + + + %endfor @@ -106,28 +95,75 @@ <%def name="headIncludes()"> + ${parent.headIncludes()} <%-- Ensure parent head includes are kept --%> + <%def name="javascriptIncludes()"> + ${parent.javascriptIncludes()} <%-- Ensure parent javascript includes are kept --%> -
AlbumArtistDateTypeStatusHaveBitrateFormatAlbumArtistDateTypeStatusHaveBitrateFormat
${album['AlbumTitle']}${album['ArtistName']}${album['ReleaseDate']}${album['Type']}${album['Status']}
${havetracks}/${totaltracks}
${bitrate}${albumformat}${album['AlbumTitle']}${album['ArtistName']}${album['ReleaseDate']}${album['Type']}${album['Status']} + <%-- Using percent_display for title attribute --%> +
+
+
${havetracks_display}/${totaltracks_display}
+
+
+
${bitrate_display}${albumformat_display}