changeset 50:5913ddcebea4

For issue #6, create a videos application.
author Brian Neal <bgneal@gmail.com>
date Sat, 24 Mar 2012 16:18:48 -0500
parents 0900c08055f0
children 13b2561c909d
files madeira/band/urls.py madeira/settings/base.py madeira/templates/band/base.html madeira/templates/videos/collection_detail.html madeira/templates/videos/collection_list.html madeira/urls.py madeira/videos/__init__.py madeira/videos/admin.py madeira/videos/management/__init__.py madeira/videos/management/commands/__init__.py madeira/videos/management/commands/import_old_videos.py madeira/videos/models.py madeira/videos/static/js/videos/videos_admin.js madeira/videos/urls.py
diffstat 11 files changed, 209 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/madeira/band/urls.py	Sat Mar 24 15:18:11 2012 -0500
+++ b/madeira/band/urls.py	Sat Mar 24 16:18:48 2012 -0500
@@ -18,8 +18,8 @@
    (r'^press_old/$', 'press_index'),
    (r'^press_old/(\d+)$', 'press_detail'),
    (r'^songs_old/$', 'songs'),
-   (r'^videos/$', 'videos_index'),
-   (r'^videos/(\d+)$', 'video_detail'),
+   (r'^videos_old/$', 'videos_index'),
+   (r'^videos_old/(\d+)$', 'video_detail'),
 )
 
 urlpatterns += patterns('band.admin_views',
--- a/madeira/settings/base.py	Sat Mar 24 15:18:11 2012 -0500
+++ b/madeira/settings/base.py	Sat Mar 24 16:18:48 2012 -0500
@@ -110,6 +110,7 @@
     'gigs',
     'mp3',
     'news',
+    'videos',
     'photologue',
 ]
 
--- a/madeira/templates/band/base.html	Sat Mar 24 15:18:11 2012 -0500
+++ b/madeira/templates/band/base.html	Sat Mar 24 16:18:48 2012 -0500
@@ -55,8 +55,9 @@
 
 <div id="footer" class="span-24 last">
 Website &copy; 2008 - 2012 by The Madeira <br />
-Visit <a href="http://myspace.com/themadeira">The Madeira on Myspace</a><br />
-and <a href="http://facebook.com/themadeira">The Madeira on Facebook</a><br />
+Visit The Madeira on <a href="http://myspace.com/themadeira">Myspace</a>,
+<a href="http://facebook.com/themadeira">Facebook</a>, and 
+<a href="http://www.youtube.com/user/TheMadeiraSurf">YouTube</a>
 </div>
 
 </div>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/madeira/templates/videos/collection_detail.html	Sat Mar 24 16:18:48 2012 -0500
@@ -0,0 +1,20 @@
+{% extends 'band/base.html' %}
+{% load url from future %}
+{% block title %}The Madeira | Videos: {{ collection.title }}{% endblock %}
+{% block content %}
+<h1>Madeira Videos: {{ collection.title }}</h1>
+<div>
+{{ collection.description|safe }}
+</div>
+
+<div align="center">
+<table cellspacing="3" cellpadding="2" border="0">
+{% for video in collection.video_set.all %}
+   <tr><th>{{ video.title }}</th><td>{{ video.embed_code|safe }}</td></tr>
+{% endfor %}
+</table>
+</div>
+<br />
+<center><a href="{% url 'videos-index' %}">Back to videos index</a></center>
+
+{% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/madeira/templates/videos/collection_list.html	Sat Mar 24 16:18:48 2012 -0500
@@ -0,0 +1,19 @@
+{% extends 'band/base.html' %}
+{% load url from future %}
+{% block title %}The Madeira | Videos{% endblock %}
+{% block content %}
+<h1>Madeira Videos</h1>
+<p>
+To see all of these videos and many more, please visit <a href="http://www.youtube.com/user/TheMadeiraSurf">The
+   Madeira YouTube Channel</a>.
+</p>
+{% if collection_list %}
+   <ul>
+   {% for collection in collection_list %}
+      <li><a href="{{ collection.get_absolute_url }}">{{ collection.title }}</a></li>
+   {% endfor %}
+   </ul>
+{% else %}
+<p>No videos available at this time.</p>
+{% endif %}
+{% endblock %}
--- a/madeira/urls.py	Sat Mar 24 15:18:11 2012 -0500
+++ b/madeira/urls.py	Sat Mar 24 16:18:48 2012 -0500
@@ -11,6 +11,7 @@
    (r'^news/', include('news.urls')),
    (r'^press/', include('articles.urls')),
    (r'^songs/', include('mp3.urls')),
+   (r'^videos/', include('videos.urls')),
    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
    (r'^admin/', include(admin.site.urls)),
    (r'^photologue/', include('photologue.urls')),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/madeira/videos/admin.py	Sat Mar 24 16:18:48 2012 -0500
@@ -0,0 +1,29 @@
+"""
+Automatic admin definitions for the models in the videos application.
+
+"""
+from django.contrib import admin
+from django.conf import settings
+
+from videos.models import Collection, Video
+
+
+class VideoInline(admin.StackedInline):
+   model = Video
+
+
+class CollectionAdmin(admin.ModelAdmin):
+    list_filter = ['date_added']
+    list_display = ['title', 'date_added']
+    inlines = [VideoInline]
+
+    class Media:
+        js = ['js/videos/videos_admin.js'] + settings.THIRD_PARTY_JS['tiny_mce']
+
+
+class VideoAdmin(admin.ModelAdmin):
+    list_display = ['title', 'collection']
+
+
+admin.site.register(Collection, CollectionAdmin)
+admin.site.register(Video, VideoAdmin)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/madeira/videos/management/commands/import_old_videos.py	Sat Mar 24 16:18:48 2012 -0500
@@ -0,0 +1,69 @@
+"""
+import_old_videos.py - For importing video data from the older version of this
+website.
+
+"""
+import datetime
+
+from django.core.management.base import LabelCommand
+from django.utils import simplejson as json
+from django.utils.html import linebreaks
+
+from videos.models import Collection, Video
+
+
+class Command(LabelCommand):
+    args = '<filename filename ...>'
+    help = 'Imports older video & video sets in JSON format'
+
+    collections = {}
+
+    def handle_label(self, filename, **options):
+        """
+        Process the file of older video & video sets in JSON. Convert to the new
+        model scheme.
+
+        """
+        with open(filename, 'rb') as f:
+            items = json.load(f)
+
+        for item in items:
+            if item['model'] == 'band.video_set':
+                self.process_set(item)
+
+        for item in items:
+            if item['model'] == 'band.video':
+                self.process_video(item)
+
+    def process_set(self, item):
+
+        fields = item['fields']
+
+        description = linebreaks(fields['text'].strip())
+
+        # there are several sets with the same date, so to get the ordering
+        # right, add the pk as seconds.
+
+        date_added = datetime.datetime.strptime(fields['date'], '%Y-%m-%d')
+        date_added += datetime.timedelta(seconds=int(item['pk']))
+
+        coll = Collection(
+                id=item['pk'],
+                title=fields['title'].strip(),
+                date_added=date_added,
+                description=description)
+
+        coll.save()
+        self.collections[coll.pk] = coll
+
+    def process_video(self, item):
+
+        fields = item['fields']
+
+        video = Video(
+                id=item['pk'],
+                title=fields['title'].strip(),
+                embed_code=fields['embed_code'],
+                collection=self.collections[fields['video_set']],
+                )
+        video.save()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/madeira/videos/models.py	Sat Mar 24 16:18:48 2012 -0500
@@ -0,0 +1,42 @@
+"""
+Models for the videos application.
+
+"""
+from django.db import models
+
+
+class Collection(models.Model):
+    """
+    This model represents a collection of videos.
+
+    """
+    title = models.CharField(max_length=64)
+    description = models.TextField()
+    date_added = models.DateTimeField()
+
+    class Meta:
+        ordering = ['-date_added']
+
+    def __unicode__(self):
+        return self.title
+
+    @models.permalink
+    def get_absolute_url(self):
+        return ('videos-item', [], {'pk': str(self.id)})
+
+
+class Video(models.Model):
+    """
+    This model represents a video clip hosted on a remote video sharing site
+    (e.g. YouTube).
+
+    """
+    title = models.CharField(max_length=64)
+    embed_code = models.TextField()
+    collection = models.ForeignKey(Collection)
+
+    class Meta:
+        ordering = ['title']
+
+    def __unicode__(self):
+        return self.title
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/madeira/videos/static/js/videos/videos_admin.js	Sat Mar 24 16:18:48 2012 -0500
@@ -0,0 +1,3 @@
+django.jQuery(document).ready(function() {
+   django.jQuery('.embed_code textarea').addClass('mceNoEditor');      
+});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/madeira/videos/urls.py	Sat Mar 24 16:18:48 2012 -0500
@@ -0,0 +1,20 @@
+"""
+Urls for the videos application.
+
+"""
+from django.conf.urls.defaults import patterns, url
+from django.views.generic import DetailView, ListView
+
+from videos.models import Collection
+
+
+urlpatterns = patterns('',
+   url(r'^$',
+       ListView.as_view(
+           model=Collection,
+           context_object_name='collection_list'),
+       name='videos-index'),
+   url(r'^(?P<pk>\d+)/$',
+       DetailView.as_view(model=Collection, context_object_name='collection'),
+       name='videos-item')
+)