From: David ‘Bombe’ Roden Date: Fri, 10 May 2013 06:05:10 +0000 (+0200) Subject: Show tracks differently on home page. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=96f8a2539ba4b3dc9dadb0e4403efeeecae2c238;p=demoscenemusic.git Show tracks differently on home page. --- diff --git a/data/views.py b/data/views.py index 1ca48df..bb3b52c 100644 --- a/data/views.py +++ b/data/views.py @@ -1,12 +1,19 @@ # encoding: utf-8 +from collections import defaultdict from django.shortcuts import render_to_response from django.http import HttpResponse from DemosceneMusic.data.models import Track def home(request): - tracks = Track.objects.all() - return render_to_response('templates/home.html', { 'tracks': tracks }) + tracks = Track.objects.all().annotate().order_by('releases__party', 'trackartist__artist__name', 'name', 'remix') + partyCompoTracks = defaultdict(lambda: defaultdict(list)) + for track in tracks: + for release in track.releases.all(): + partyCompoTracks[release.party][release.compo].append(track) + for party, compoTracks in partyCompoTracks.iteritems(): + partyCompoTracks[party] = dict(compoTracks) + return render_to_response('templates/home.html', {'partyTracks': dict(partyCompoTracks)}) def track(request, trackId): return HttpResponse('Track: %s' % trackId) diff --git a/templates/home.html b/templates/home.html index d9378ad..3353229 100644 --- a/templates/home.html +++ b/templates/home.html @@ -6,12 +6,29 @@

Tracks

-{% for track in tracks %} - -
- {{ track }} +{% for party, compoTracks in partyTracks.items %} +
+

{{ party }}

+ {% for compo, tracks in compoTracks.items %} +

{{ compo }}

+ + {% endfor %}
- {% endfor %} {% endblock content %}