From b73588789909110dd6068b603dbc8373e8ac23eb Mon Sep 17 00:00:00 2001 From: Chris Shyi Date: Mon, 4 Jun 2018 22:17:31 -0400 Subject: [PATCH] Bug fixes Server crashes as of the last commit, now fixed. --- .../migrations/0002_auto_20180605_0209.py | 18 ++++++++++++++++++ .../migrations/0003_auto_20180605_0211.py | 18 ++++++++++++++++++ spotifyvis/models.py | 2 +- spotifyvis/templates/spotifyvis/user_data.html | 1 + spotifyvis/views.py | 15 ++++++++++----- 5 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 spotifyvis/migrations/0002_auto_20180605_0209.py create mode 100644 spotifyvis/migrations/0003_auto_20180605_0211.py diff --git a/spotifyvis/migrations/0002_auto_20180605_0209.py b/spotifyvis/migrations/0002_auto_20180605_0209.py new file mode 100644 index 0000000..fe5fb37 --- /dev/null +++ b/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', + ), + ] diff --git a/spotifyvis/migrations/0003_auto_20180605_0211.py b/spotifyvis/migrations/0003_auto_20180605_0211.py new file mode 100644 index 0000000..9e59bb3 --- /dev/null +++ b/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), + ), + ] diff --git a/spotifyvis/models.py b/spotifyvis/models.py index 773492c..02a081d 100644 --- a/spotifyvis/models.py +++ b/spotifyvis/models.py @@ -21,7 +21,7 @@ class User(models.Model): verbose_name_plural = "Users" 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): return self.username diff --git a/spotifyvis/templates/spotifyvis/user_data.html b/spotifyvis/templates/spotifyvis/user_data.html index c008bdd..209350a 100644 --- a/spotifyvis/templates/spotifyvis/user_data.html +++ b/spotifyvis/templates/spotifyvis/user_data.html @@ -1,3 +1,4 @@ +{% load static %} diff --git a/spotifyvis/views.py b/spotifyvis/views.py index bd7a300..9a9fdd1 100644 --- a/spotifyvis/views.py +++ b/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() 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 try: user = User.objects.get(user_id=request.session['user_id']) except User.DoesNotExist: 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 = { "audio_features":{},