From 52158b110b3ea853a0b9363439fcc9ef997d3c23 Mon Sep 17 00:00:00 2001 From: yomguy Date: Thu, 27 Oct 2011 11:48:12 +0200 Subject: [PATCH] fix sound_pub_items lists in index --- .../templates/telemeta_default/index.html | 8 +++++-- telemeta/web/base.py | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/telemeta/templates/telemeta_default/index.html b/telemeta/templates/telemeta_default/index.html index 7c0be013..2c944d4f 100644 --- a/telemeta/templates/telemeta_default/index.html +++ b/telemeta/templates/telemeta_default/index.html @@ -14,6 +14,7 @@ {% trans +{% if sound_pub_item %}

playlist {% trans "Musical selection" %}

@@ -23,6 +24,7 @@
+{% endif %} {% include "telemeta/inc/module_revisions.html" %} @@ -35,17 +37,19 @@ {{ page_content|render_flatpage }} +{% if sound_pub_items %}

playlists {% trans "Musical selection" %}

-{% for item in sound_items %} - {% endfor %}
{{ item }}{% if item.alt_title %} ({{ item.alt_title }}){% endif %}
{{ item.location.fullnames|to_string }}
+{% for item in sound_pub_items %} +
{{ item }}{% if item.alt_title %} ({{ item.alt_title }}){% endif %}
{{ item.location.fullnames|to_string }}
+{% endif %} {% endblock %} diff --git a/telemeta/web/base.py b/telemeta/web/base.py index 2f4f0aa7..163d632c 100644 --- a/telemeta/web/base.py +++ b/telemeta/web/base.py @@ -175,9 +175,9 @@ class GeneralView(object): """Render the homepage""" if not request.user.is_authenticated(): template = loader.get_template('telemeta/index.html') - ids = [id for id in MediaItem.objects.all().values_list('id', flat=True).order_by('?')[0:3]] - items = MediaItem.objects.enriched().filter(pk__in=ids) - +# ids = [id for id in MediaItem.objects.all().values_list('id', flat=True).order_by('?')[0:3]] +# items = MediaItem.objects.enriched().filter(pk__in=ids) +# sound_items = MediaItem.objects.sound() sound_pub_items = [] for item in sound_items: @@ -185,15 +185,20 @@ class GeneralView(object): str(item.recorded_to_date).split('-')[0]): sound_pub_items.append(item) - sound_pub_item = sound_pub_items[0] random.shuffle(sound_pub_items) - if len(sound_pub_items) >= 2: - sound_pub_items = sound_pub_items[0:2] - + if len(sound_pub_items) != 0: + sound_pub_item = sound_pub_items[0] + else: + sound_pub_item = None + if len(sound_pub_items) == 2: + sound_pub_items = sound_pub_items[1] + if len(sound_pub_items) > 2: + sound_pub_items = sound_pub_items[1:3] + revisions = get_revisions(4) context = RequestContext(request, { 'page_content': pages.get_page_content(request, 'home', ignore_slash_issue=True), - 'items': items, 'revisions': revisions, 'sound_items': sound_pub_items, + 'revisions': revisions, 'sound_pub_items': sound_pub_items, 'sound_pub_item': sound_pub_item }) return HttpResponse(template.render(context)) else: -- 2.39.5