# HG changeset patch # User Brian Neal # Date 1332623928 18000 # Node ID 5913ddcebea46a70210263f5ab73cd87f312fda4 # Parent 0900c08055f0a3825f0bc7a3e5cbb44c838fa345 For issue #6, create a videos application. diff -r 0900c08055f0 -r 5913ddcebea4 madeira/band/urls.py --- 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', diff -r 0900c08055f0 -r 5913ddcebea4 madeira/settings/base.py --- 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', ] diff -r 0900c08055f0 -r 5913ddcebea4 madeira/templates/band/base.html --- 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 @@ diff -r 0900c08055f0 -r 5913ddcebea4 madeira/templates/videos/collection_detail.html --- /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 %} +

Madeira Videos: {{ collection.title }}

+
+{{ collection.description|safe }} +
+ +
+ +{% for video in collection.video_set.all %} + +{% endfor %} +
{{ video.title }}{{ video.embed_code|safe }}
+
+
+
Back to videos index
+ +{% endblock %} diff -r 0900c08055f0 -r 5913ddcebea4 madeira/templates/videos/collection_list.html --- /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 %} +

Madeira Videos

+

+To see all of these videos and many more, please visit The + Madeira YouTube Channel. +

+{% if collection_list %} + +{% else %} +

No videos available at this time.

+{% endif %} +{% endblock %} diff -r 0900c08055f0 -r 5913ddcebea4 madeira/urls.py --- 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')), diff -r 0900c08055f0 -r 5913ddcebea4 madeira/videos/admin.py --- /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) diff -r 0900c08055f0 -r 5913ddcebea4 madeira/videos/management/commands/import_old_videos.py --- /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 = '' + 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() diff -r 0900c08055f0 -r 5913ddcebea4 madeira/videos/models.py --- /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 diff -r 0900c08055f0 -r 5913ddcebea4 madeira/videos/static/js/videos/videos_admin.js --- /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'); +}); diff -r 0900c08055f0 -r 5913ddcebea4 madeira/videos/urls.py --- /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\d+)/$', + DetailView.as_view(model=Collection, context_object_name='collection'), + name='videos-item') +)