Site is as functional as before (resolves #47)
Finished setting up graphs app and getting data from API app. Only issue now is this branch is behind a few commits from other branches.
This commit is contained in:
@@ -6,11 +6,10 @@
|
||||
<title>Artist Graphs</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Logged in as {{ user_id }}</p>
|
||||
<script src="https://d3js.org/d3.v5.js"></script>
|
||||
<script src="{% static "spotifyvis/scripts/artist_graph.js" %}"></script>
|
||||
<script src="{% static "graphs/scripts/artist_graph.js" %}"></script>
|
||||
<script>
|
||||
d3.json("{% url "get_artist_data" user_secret %}").then(function(data) {
|
||||
d3.json("{% url "api:get_artist_data" user_secret %}").then(function(data) {
|
||||
for (let index = 0; index < data.length; index++) {
|
||||
console.log(data[index].name);
|
||||
console.log(data[index].num_songs);
|
||||
@@ -24,4 +23,4 @@
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
<!--[if lt IE 7]>
|
||||
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
|
||||
<![endif]-->
|
||||
<p>Logged in as {{ user_id }}</p>
|
||||
<script src="https://d3js.org/d3.v5.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<title>Test DB Page</title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="{% static 'spotifyvis/css/dark_bg.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/dark_bg.css' %}">
|
||||
</head>
|
||||
|
||||
<!-- }}} header -->
|
||||
@@ -22,7 +22,7 @@
|
||||
<script src="https://d3js.org/d3.v5.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/randomcolor/0.5.2/randomColor.min.js"></script>
|
||||
{% load static %}
|
||||
<script src="{% static "spotifyvis/scripts/genre_graph.js" %}"></script>
|
||||
<script src="{% static "graphs/scripts/genre_graph.js" %}"></script>
|
||||
|
||||
<svg width="1920" height="740"></svg>
|
||||
<script>
|
||||
@@ -38,7 +38,7 @@
|
||||
var y = d3.scaleLinear()
|
||||
.rangeRound([height, 0]);
|
||||
|
||||
d3.json("{% url "get_genre_data" user_secret %}").then(create_genre_graph);
|
||||
d3.json("{% url "api:get_genre_data" user_secret %}").then(create_genre_graph);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
20
graphs/templates/graphs/logged_in.html
Normal file
20
graphs/templates/graphs/logged_in.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
{% load static %}
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Logged In</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="{% static 'css/dark_bg.css' %}">
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ user_id }}'s Graphs</h1>
|
||||
<a class="btn btn-primary" href="{% url "graphs:display_audio_features" user_secret %}"
|
||||
role="button">Audio Features</a>
|
||||
<a class="btn btn-primary" href="{% url "graphs:display_genre_graph" user_secret %}"
|
||||
role="button">Genres</a>
|
||||
<a class="btn btn-primary" href="{% url "graphs:display_artist_graph" user_secret %}" role="button">
|
||||
Artists
|
||||
</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -4,10 +4,10 @@ from .views import *
|
||||
|
||||
app_name = 'graphs'
|
||||
urlpatterns = [
|
||||
path('artists/<str:user_secret>', artist_data,
|
||||
path('artists/<str:user_secret>', display_artist_graph,
|
||||
name='display_artist_graph'),
|
||||
path('genre/<str:user_secret>', display_genre_graph,
|
||||
name='display_genre_graph'),
|
||||
path('audio_features/<str:user_secret>', audio_features,
|
||||
path('audio_features/<str:user_secret>', display_features_graphs,
|
||||
name='display_audio_features'),
|
||||
]
|
||||
|
||||
8
graphs/utils.py
Normal file
8
graphs/utils.py
Normal file
@@ -0,0 +1,8 @@
|
||||
def get_secret_context(user_secret):
|
||||
"""Return user_secret in context for graph pages.
|
||||
|
||||
:user_secret: User secret to put in context.
|
||||
:returns: context with user secret.
|
||||
|
||||
"""
|
||||
return { 'user_secret': user_secret, }
|
||||
@@ -11,41 +11,32 @@ import string
|
||||
from datetime import datetime
|
||||
|
||||
from django.shortcuts import render, redirect
|
||||
from .utils import *
|
||||
|
||||
# }}} imports #
|
||||
|
||||
def artist_data(request, user_secret):
|
||||
def display_artist_graph(request, user_secret):
|
||||
"""Renders the artist data graph display page
|
||||
|
||||
:param request: the HTTP request
|
||||
:param user_secret: the user secret used for identification
|
||||
:return: render the artist data graph display page
|
||||
"""
|
||||
user = User.objects.get(user_secret=user_secret)
|
||||
context = {
|
||||
'user_id': user.user_id,
|
||||
'user_secret': user_secret,
|
||||
}
|
||||
return render(request, "spotifyvis/artist_graph.html", context)
|
||||
return render(request, "graphs/artist_graph.html",
|
||||
get_secret_context(user_secret))
|
||||
|
||||
|
||||
def display_genre_graph(request, user_secret):
|
||||
user = User.objects.get(user_secret=user_secret)
|
||||
context = {
|
||||
'user_secret': user_secret,
|
||||
}
|
||||
return render(request, "spotifyvis/genre_graph.html", context)
|
||||
return render(request, "graphs/genre_graph.html",
|
||||
get_secret_context(user_secret))
|
||||
|
||||
|
||||
def audio_features(request, user_secret):
|
||||
def display_features_graphs(request, user_secret):
|
||||
"""Renders the audio features page
|
||||
|
||||
:param request: the HTTP request
|
||||
:param user_secret: user secret used for identification
|
||||
:return: renders the audio features page
|
||||
"""
|
||||
user = User.objects.get(user_secret=user_secret)
|
||||
context = {
|
||||
'user_id': user.user_id,
|
||||
'user_secret': user_secret,
|
||||
}
|
||||
return render(request, "spotifyvis/audio_features.html", context)
|
||||
return render(request, "graphs/features_graphs.html",
|
||||
get_secret_context(user_secret))
|
||||
|
||||
Reference in New Issue
Block a user