From df62fc21eee51eb808ef3a80700fe0ba46053614 Mon Sep 17 00:00:00 2001 From: Kevin Mok Date: Wed, 7 Nov 2018 00:14:45 -0500 Subject: [PATCH] Copied Chris' code to get genre graph working --- api/views.py | 4 ++-- graphs/templates/graphs/genre_graph.html | 11 +---------- graphs/urls.py | 3 --- graphs/utils.py | 2 +- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/api/views.py b/api/views.py index 741c4c3..6dc204d 100644 --- a/api/views.py +++ b/api/views.py @@ -211,7 +211,7 @@ def get_artist_data(request, user_secret): filter=Q(track__users=user))) processed_artist_counts = [{'name': artist.name, 'num_songs': artist.num_songs} for artist in artist_counts] - pprint.pprint(processed_artist_counts) + pprint(processed_artist_counts) return JsonResponse(data=processed_artist_counts, safe=False) # }}} get_artist_data # @@ -257,7 +257,7 @@ def get_genre_data(request, user_secret): genre_dict['artists'] = get_artists_in_genre(user, genre_dict['genre'], genre_dict['num_songs']) print("*** Genre Breakdown ***") - pprint.pprint(list(genre_counts)) + pprint(list(genre_counts)) return JsonResponse(data=list(genre_counts), safe=False) # }}} get_genre_data # diff --git a/graphs/templates/graphs/genre_graph.html b/graphs/templates/graphs/genre_graph.html index 4eb5940..7d35ee8 100644 --- a/graphs/templates/graphs/genre_graph.html +++ b/graphs/templates/graphs/genre_graph.html @@ -46,16 +46,7 @@ var y = d3.scaleLinear() .rangeRound([height, 0]); - // PU: trying to store genreData locally - var genreData; - d3.json("{% url "api:get_genre_data" user_secret %}", - function(data) { - genreData = data; - } - ); - console.log(genreData); - create_genre_graph(genreData); - // d3.json("{% url "api:get_genre_data" user_secret %}").then(create_genre_graph); + d3.json("{% url "api:get_genre_data" user_secret %}").then(create_genre_graph); diff --git a/graphs/urls.py b/graphs/urls.py index 6ff4da5..527822b 100644 --- a/graphs/urls.py +++ b/graphs/urls.py @@ -10,8 +10,5 @@ urlpatterns = [ name='display_genre_graph'), path('audio_features/', display_features_graphs, name='display_audio_features'), - # path('history/', display_history_table, - # name='display_history_table'), - # path('history/', display_history_table, name='display_history_table'), path('history/', HistoryList.as_view(), name='display_history_table'), ] diff --git a/graphs/utils.py b/graphs/utils.py index 25be3b6..14c037e 100644 --- a/graphs/utils.py +++ b/graphs/utils.py @@ -10,8 +10,8 @@ class HistoryTable(tables.Table): template_name = 'django_tables2/bootstrap.html' iso_timestamp = tables.Column(accessor='get_iso_timestamp', orderable=False) - track_name = tables.Column(accessor='track.name', orderable=False) track_id = tables.Column(accessor='track.id', orderable=False) + track_name = tables.Column(accessor='track.name', orderable=False) artists = tables.Column(accessor='get_artists', orderable=False) def get_secret_context(user_secret):