changeset 640:560e4fe35bd3

Add a tag to choose slides for home slideshow.
author Brian Neal <bgneal@gmail.com>
date Sat, 09 Mar 2013 11:42:35 -0600
parents 1872c8fca82a
children 546f669b8688
files core/templatetags/core_tags.py sg101/templates/core/slideshow.html sg101/templates/home.html static/slideshow/425.JPG static/slideshow/casino66.jpg static/slideshow/chum.jpg static/slideshow/friasivan.jpg static/slideshow/insect.jpg static/slideshow/jeffdavepaul.jpg static/slideshow/lehos_zps7d7f75a5.jpg static/slideshow/lorenzo.jpg static/slideshow/slack3.jpg static/slideshow/spco.jpg static/slideshow/spra001.jpg static/slideshow/ssiv.jpg static/slideshow/wronski.jpg
diffstat 16 files changed, 24 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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,
+    }
--- /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 %}
+   <img src="{{ slide }}" alt="Slideshow Image" />
+{% endfor %}
--- 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 @@
 <h2>Welcome to SurfGuitar101!</h2>
 <div class="span-9">
    <div id="home-slideshow">
-   <img src="{{ STATIC_URL }}slideshow/image-1.jpg" alt="Slideshow Image 1" />
-   <img src="{{ STATIC_URL }}slideshow/image-2.jpg" alt="Slideshow Image 2" />
-   <img src="{{ STATIC_URL }}slideshow/image-3.jpg" alt="Slideshow Image 3" />
-   <img src="{{ STATIC_URL }}slideshow/image-4.jpg" alt="Slideshow Image 4" />
-   <img src="{{ STATIC_URL }}slideshow/image-5.jpg" alt="Slideshow Image 5" />
+   {% cache 600 home_slideshow %}
+      {% slideshow_images %}
+   {% endcache %}
    </div>
 </div>
 <div class="span-10 last">
Binary file static/slideshow/425.JPG has changed
Binary file static/slideshow/casino66.jpg has changed
Binary file static/slideshow/chum.jpg has changed
Binary file static/slideshow/friasivan.jpg has changed
Binary file static/slideshow/insect.jpg has changed
Binary file static/slideshow/jeffdavepaul.jpg has changed
Binary file static/slideshow/lehos_zps7d7f75a5.jpg has changed
Binary file static/slideshow/lorenzo.jpg has changed
Binary file static/slideshow/slack3.jpg has changed
Binary file static/slideshow/spco.jpg has changed
Binary file static/slideshow/spra001.jpg has changed
Binary file static/slideshow/ssiv.jpg has changed
Binary file static/slideshow/wronski.jpg has changed