Browse Source
Wrote up proposed model design for database
Wrote up proposed model design for database
Have not actually created any models yet.master
Kevin Mok
7 years ago
7 changed files with 189 additions and 42 deletions
-
85spotifyvis/migrations/0001_initial.py
-
70spotifyvis/models.py
-
42spotifyvis/static/spotifyvis/scripts/index.js
-
14spotifyvis/templates/spotifyvis/index.html
-
2spotifyvis/tests.py
-
8spotifyvis/utils.py
@ -0,0 +1,85 @@ |
|||
# Generated by Django 2.0.5 on 2018-06-03 23:01 |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
initial = True |
|||
|
|||
dependencies = [ |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name='Artist', |
|||
fields=[ |
|||
('artist_id', models.CharField(max_length=30, primary_key=True, serialize=False)), |
|||
('name', models.CharField(max_length=50, unique=True)), |
|||
('genre', models.CharField(max_length=20)), |
|||
], |
|||
options={ |
|||
'verbose_name': 'Artist', |
|||
'verbose_name_plural': 'Artists', |
|||
}, |
|||
), |
|||
migrations.CreateModel( |
|||
name='Track', |
|||
fields=[ |
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|||
('track_id', models.CharField(max_length=30)), |
|||
('year', models.PositiveSmallIntegerField()), |
|||
('popularity', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('runtime', models.PositiveSmallIntegerField()), |
|||
('name', models.CharField(max_length=75)), |
|||
], |
|||
options={ |
|||
'verbose_name': 'Track', |
|||
'verbose_name_plural': 'Tracks', |
|||
}, |
|||
), |
|||
migrations.CreateModel( |
|||
name='User', |
|||
fields=[ |
|||
('user_id', models.CharField(max_length=30, primary_key=True, serialize=False)), |
|||
('username', models.CharField(max_length=30)), |
|||
], |
|||
options={ |
|||
'verbose_name': 'User', |
|||
'verbose_name_plural': 'Users', |
|||
}, |
|||
), |
|||
migrations.CreateModel( |
|||
name='AudioFeatures', |
|||
fields=[ |
|||
('track', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='spotifyvis.Track')), |
|||
('danceability', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('energy', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('loudness', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('speechiness', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('acousticness', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('instrumentalness', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('valence', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
('tempo', models.DecimalField(decimal_places=2, max_digits=2)), |
|||
], |
|||
options={ |
|||
'verbose_name': 'AudioFeatures', |
|||
'verbose_name_plural': 'AudioFeatures', |
|||
}, |
|||
), |
|||
migrations.AddField( |
|||
model_name='track', |
|||
name='artist', |
|||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='spotifyvis.Artist'), |
|||
), |
|||
migrations.AddField( |
|||
model_name='track', |
|||
name='users', |
|||
field=models.ManyToManyField(to='spotifyvis.User'), |
|||
), |
|||
migrations.AlterUniqueTogether( |
|||
name='track', |
|||
unique_together={('track_id', 'artist')}, |
|||
), |
|||
] |
@ -0,0 +1,42 @@ |
|||
document.getElementById("login-btn").addEventListener("click", function() { |
|||
let httpRequest = new XMLHttpRequest(); |
|||
|
|||
/* |
|||
* Handler for the response |
|||
*/ |
|||
httpRequest.onreadystatechange = function() { |
|||
if (httpRequest.readyState === XMLHttpRequest.DONE) { |
|||
if (httpRequest.status === 200) { |
|||
// hide the login button
|
|||
document.getElementById('login').setAttribute("display", "none"); |
|||
|
|||
let responseData = JSON.parse(httpRequest.responseText); |
|||
let dataList = document.getElementById("data-list"); |
|||
|
|||
|
|||
for (let key in responseData) { |
|||
let newLi = document.createElement("li"); |
|||
let innerList = document.createElement("ul"); |
|||
|
|||
let dataLabel = document.createElement("li"); |
|||
dataLabel.innerText = key; |
|||
|
|||
let dataValue = document.createElement("li"); |
|||
dataValue.innerText = responseData[key]; |
|||
|
|||
innerList.appendChild(dataLabel); |
|||
innerList.appendChild(dataValue); |
|||
|
|||
newLi.appendChild(innerList); |
|||
dataList.appendChild(newLi); |
|||
} |
|||
} else { |
|||
alert("There was a problem with the login request, please try again!"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
httpRequest.open('GET', '/login', true); |
|||
httpRequest.send(); |
|||
}); |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue