comparison bns_website/videos/models.py @ 60:a0d3bc630ebd

For issue #8, create a videos application to randomize videos in the playlist. This commit now adds a dependency to the Google Python GData library. The admin enters a playlist URL in the admin. Then the admin uses an admin action to synchronize the playlist with YouTube. This reads the playlist title and retrieves the video list from YouTube. The view function reads all the playlist objects to get the complete list of videos, then shuffles them up. The template generates Javascript to create a YouTube player with the shuffled list. A fixture is included for convenience and for the tests. I also committed a test tool I wrote to prove out this idea in case it is useful for future enhancements or experimentation.
author Brian Neal <bgneal@gmail.com>
date Sat, 19 Nov 2011 14:19:00 -0600
parents
children
comparison
equal deleted inserted replaced
59:f8858447adda 60:a0d3bc630ebd
1 """
2 Models for the videos app.
3
4 """
5 from django.db import models
6
7
8 # The whole purpose of this application is to shuffle the videos in
9 # a YouTube playlist.
10 #
11 # We'd like to embed a video player to show videos from all the bands that
12 # participated in the compilation. So we create a YouTube playlist with a long
13 # list of videos. YouTube no longer offers a way to shuffle the playlist via
14 # the embed code. Instead we will use the YouTube Javascript API to accomplish
15 # this. However, the Javascript API works off of video IDs. So we now need
16 # a way to obtain all the video IDs from a YouTube playlist. This model
17 # stores the playlist URL and an admin function can be run to retrieve the
18 # video ID list via the Python GData YouTube API. The video list is also
19 # stored in this model. The view function can then read the video ID list,
20 # randomize it, and give it to the template to build the appropriate
21 # Javascript.
22
23 class Playlist(models.Model):
24 """
25 This model stores a YouTube playlist URL and a list of video IDs that
26 make up the playlist.
27
28 """
29 playlist_title = models.CharField(max_length=128, blank=True)
30 playlist_url = models.URLField()
31 video_list = models.TextField(blank=True)
32 sync_date = models.DateTimeField(null=True, blank=True)
33
34 def __unicode__(self):
35 if self.playlist_title:
36 return self.playlist_title
37
38 return u"(Please sync with YouTube to retrieve the videos)"