annotate bns_website/apache/bns.wsgi @ 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 a5e8741452a3
children f00199f1524c
rev   line source
bgneal@19 1 import os
bgneal@19 2 import sys
bgneal@19 3
bgneal@19 4 OFFLINE = False
bgneal@19 5
bgneal@19 6 here = os.path.dirname(__file__)
bgneal@19 7 website = os.path.dirname(here)
bgneal@26 8 repo = os.path.dirname(website)
bgneal@26 9 project = os.path.dirname(repo)
bgneal@19 10 eggs = os.path.join(project, 'eggs')
bgneal@27 11 django = os.path.join(project, 'django')
bgneal@19 12
bgneal@27 13 sys.path.extend([repo, website, django])
bgneal@19 14
bgneal@19 15 os.environ['PYTHON_EGG_CACHE'] = eggs
bgneal@19 16
bgneal@19 17
bgneal@19 18 def offline_handler(environ, start_response):
bgneal@19 19 """
bgneal@19 20 This handler is run when the site is in maintenance mode.
bgneal@19 21 It either displays a brief outage message, or, if a template
bgneal@19 22 file exists, it reads the file and returns its contents.
bgneal@19 23
bgneal@19 24 """
bgneal@19 25 wsgi_dir = os.path.dirname(__file__)
bgneal@19 26 sys.path.append(wsgi_dir)
bgneal@19 27
bgneal@19 28 offline_file = os.path.abspath(
bgneal@19 29 os.path.join(wsgi_dir, '..', 'templates', 'offline.html'))
bgneal@19 30 if os.path.exists(offline_file):
bgneal@19 31 response_headers = [('Content-type','text/html')]
bgneal@19 32 response = open(offline_file).read()
bgneal@19 33 else:
bgneal@19 34 response_headers = [('Content-type','text/plain')]
bgneal@19 35 response = ('Brave New Surf website maintenance in progress; '
bgneal@19 36 'please check back soon.')
bgneal@19 37
bgneal@19 38 if environ['REQUEST_METHOD'] == 'GET':
bgneal@19 39 status = '503 Service Unavailable'
bgneal@19 40 else:
bgneal@19 41 status = '405 Method Not Allowed'
bgneal@19 42 start_response(status, response_headers)
bgneal@19 43 return [response]
bgneal@19 44
bgneal@19 45
bgneal@19 46 if not OFFLINE:
bgneal@19 47 os.environ['DJANGO_SETTINGS_MODULE'] = 'bns_website.settings.production'
bgneal@19 48 import django.core.handlers.wsgi
bgneal@19 49 application = django.core.handlers.wsgi.WSGIHandler()
bgneal@19 50 else:
bgneal@19 51 application = offline_handler