# 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)
<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 %}&{% 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 %}