App Infrastructure

Config

Aim
To allow users to enter their own playlist and have the app remember the playlist from session to session on one device.
Method
I followed this tutorial (Grinberg, 2017). This adds a form to the site, but doesn’t do anything further with the form entries. Grinberg’s tutorial goes on to describe how to create a full login system using SQLAlchemy, but I don’t need anything as complex for my aim.

I used the WTForms module to create the form fields and collect their entries, for example playlist_url = form.playlist.data.

A username is generated for each user which consists of the ID of the playlist they entered plus a randomly generated text string. This is saved as a cookie on their device, and into the database along with the Playlist URL and ID.

WTForms has some validation utilities, and it catches entries that don’t seem to be a URL.

Once the user has entered their playlist, they are redirected to the index page, where a message is flashed saying “The NAME playlist has been added”, where the name is extracted from the YouTube API given the playlist ID.

Standard