Browse Source

Bug fixes

Server crashes as of the last commit, now fixed.
master
Chris Shyi 7 years ago
parent
commit
b735887899
  1. 18
      spotifyvis/migrations/0002_auto_20180605_0209.py
  2. 18
      spotifyvis/migrations/0003_auto_20180605_0211.py
  3. 2
      spotifyvis/models.py
  4. 1
      spotifyvis/templates/spotifyvis/user_data.html
  5. 15
      spotifyvis/views.py

18
spotifyvis/migrations/0002_auto_20180605_0209.py

@ -0,0 +1,18 @@
# Generated by Django 2.0.5 on 2018-06-05 02:09
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('spotifyvis', '0001_initial'),
]
operations = [
migrations.RenameField(
model_name='user',
old_name='username',
new_name='user_name',
),
]

18
spotifyvis/migrations/0003_auto_20180605_0211.py

@ -0,0 +1,18 @@
# Generated by Django 2.0.5 on 2018-06-05 02:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('spotifyvis', '0002_auto_20180605_0209'),
]
operations = [
migrations.AlterField(
model_name='user',
name='user_name',
field=models.CharField(blank=True, max_length=30),
),
]

2
spotifyvis/models.py

@ -21,7 +21,7 @@ class User(models.Model):
verbose_name_plural = "Users" verbose_name_plural = "Users"
user_id = models.CharField(primary_key=True, max_length=30) # the user's Spotify ID user_id = models.CharField(primary_key=True, max_length=30) # the user's Spotify ID
username = models.CharField(max_length=30) # User's Spotify user name, if set
user_name = models.CharField(max_length=30, blank=True) # User's Spotify user name, if set
def __str__(self): def __str__(self):
return self.username return self.username

1
spotifyvis/templates/spotifyvis/user_data.html

@ -1,3 +1,4 @@
{% load static %}
<!DOCTYPE html> <!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->

15
spotifyvis/views.py

@ -135,16 +135,21 @@ def user_data(request):
user_data_response = requests.get('https://api.spotify.com/v1/me', headers = headers).json() user_data_response = requests.get('https://api.spotify.com/v1/me', headers = headers).json()
request.session['user_id'] = user_data_response['id'] # store the user_id so it may be used to create model request.session['user_id'] = user_data_response['id'] # store the user_id so it may be used to create model
request.session['user_name'] = user_data_response['display_name']
display_name = user_data_response['display_name']
if display_name is not None:
request.session['user_name'] = display_name
else:
request.session['user_name'] = ""
user = None # will be set to the current user object later user = None # will be set to the current user object later
try: try:
user = User.objects.get(user_id=request.session['user_id']) user = User.objects.get(user_id=request.session['user_id'])
except User.DoesNotExist: except User.DoesNotExist:
user = User.objects.create(user_id=request.session['user_id'], user_name=request.session['user_name']) user = User.objects.create(user_id=request.session['user_id'], user_name=request.session['user_name'])
# context = {
# 'user_name': user_data_response['display_name'],
# 'id': user_data_response['id'],
# }
context = {
'user_name': user_data_response['display_name'],
'id': user_data_response['id'],
}
library_stats = { library_stats = {
"audio_features":{}, "audio_features":{},

Loading…
Cancel
Save