Show tracks differently on home page.
authorDavid ‘Bombe’ Roden <bombe@demoscenemusic.org>
Fri, 10 May 2013 06:05:10 +0000 (08:05 +0200)
committerDavid ‘Bombe’ Roden <bombe@demoscenemusic.org>
Fri, 10 May 2013 06:05:36 +0000 (08:05 +0200)
data/views.py
templates/home.html

index 1ca48df..bb3b52c 100644 (file)
@@ -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)
index d9378ad..3353229 100644 (file)
@@ -6,12 +6,29 @@
 
 <h1>Tracks</h1>
 
-{% for track in tracks %}
-
-       <div class="track">
-               <span class="name"><a href="/track/{{ track.id }}/">{{ track }}</a></span>
+{% for party, compoTracks in partyTracks.items %}
+       <div>
+               <h2>{{ party }}</h2>
+               {% for compo, tracks in compoTracks.items %}
+                       <h3>{{ compo }}</h3>
+                       <ul>
+                               {% for track in tracks %}
+                                       <li>
+                                               <a href="/track/{{ track.id }}">{{ track.name }}</a>
+                                               by
+                                               {% for artist in track.artists.all %}
+                                                       {% if not forloop.first %}&amp;{% endif %}
+                                                       <a href="/artist/{{ artist.id }}">{{ artist.name }}</a>
+                                                       {% for group in artist.groups.all %}
+                                                               {% if forloop.first %}/{% else %}^{% endif %}
+                                                               <a href="/group/{{ group.id }}">{{ group.shortName|default:group.name }}</a>
+                                                       {% endfor %}
+                                               {% endfor %}
+                                       </li>
+                               {% endfor %}
+                       </ul>
+               {% endfor %}
        </div>
-
 {% endfor %}
 
 {% endblock content %}