# HG changeset patch # User Brian Neal # Date 1362850955 21600 # Node ID 560e4fe35bd390943b1ba29f733906972131a297 # Parent 1872c8fca82aef531f469eb54d3df0074897e587 Add a tag to choose slides for home slideshow. diff -r 1872c8fca82a -r 560e4fe35bd3 core/templatetags/core_tags.py --- a/core/templatetags/core_tags.py Sat Feb 16 18:01:30 2013 -0600 +++ b/core/templatetags/core_tags.py Sat Mar 09 11:42:35 2013 -0600 @@ -4,6 +4,9 @@ """ import collections import datetime +import glob +import os +import random import urllib from django import template @@ -220,3 +223,18 @@ querydict = bits[1] args = [arg[1:-1] for arg in bits[2:]] return EncodeParamsNode(querydict, args) + + +@register.inclusion_tag('core/slideshow.html') +def slideshow_images(): + """Randomly choose images from a pool for a slideshow.""" + + slides_dir = os.path.join(settings.STATIC_ROOT, 'slideshow', '*') + slides = [os.path.basename(s) for s in glob.glob(slides_dir)] + if len(slides) >= 5: + slides = random.sample(slides, 5) + slides = ['%sslideshow/%s' % (settings.STATIC_URL, s) for s in slides] + + return { + 'slides': slides, + } diff -r 1872c8fca82a -r 560e4fe35bd3 sg101/templates/core/slideshow.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sg101/templates/core/slideshow.html Sat Mar 09 11:42:35 2013 -0600 @@ -0,0 +1,3 @@ +{% for slide in slides %} + Slideshow Image +{% endfor %} diff -r 1872c8fca82a -r 560e4fe35bd3 sg101/templates/home.html --- a/sg101/templates/home.html Sat Feb 16 18:01:30 2013 -0600 +++ b/sg101/templates/home.html Sat Mar 09 11:42:35 2013 -0600 @@ -39,11 +39,9 @@

Welcome to SurfGuitar101!

- Slideshow Image 1 - Slideshow Image 2 - Slideshow Image 3 - Slideshow Image 4 - Slideshow Image 5 + {% cache 600 home_slideshow %} + {% slideshow_images %} + {% endcache %}
diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/425.JPG Binary file static/slideshow/425.JPG has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/casino66.jpg Binary file static/slideshow/casino66.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/chum.jpg Binary file static/slideshow/chum.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/friasivan.jpg Binary file static/slideshow/friasivan.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/insect.jpg Binary file static/slideshow/insect.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/jeffdavepaul.jpg Binary file static/slideshow/jeffdavepaul.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/lehos_zps7d7f75a5.jpg Binary file static/slideshow/lehos_zps7d7f75a5.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/lorenzo.jpg Binary file static/slideshow/lorenzo.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/slack3.jpg Binary file static/slideshow/slack3.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/spco.jpg Binary file static/slideshow/spco.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/spra001.jpg Binary file static/slideshow/spra001.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/ssiv.jpg Binary file static/slideshow/ssiv.jpg has changed diff -r 1872c8fca82a -r 560e4fe35bd3 static/slideshow/wronski.jpg Binary file static/slideshow/wronski.jpg has changed