1
0
Fork 0
IdreXyz/label/views.py
2018-04-26 21:52:47 +02:00

63 lines
1.9 KiB
Python

from django.shortcuts import get_object_or_404, render
import markdown
from label.models import Artist, Release, VideoClip
from label.tools import (
get_catalog_tag_from_id,
get_contribs,
get_id_from_catalog_tag,
)
def artists_view(request):
artists = Artist.objects.all()
context = {'artists': artists}
return render(request, 'label/artists.html', context)
def artist_view(request, slug):
artist = get_object_or_404(Artist, slug = slug)
artist.description = markdown.markdown(artist.description)
releases = artist.release_set.all()
for release in releases:
release.tag = get_catalog_tag_from_id(release.ident)
context = {'artist': artist, 'releases': releases}
return render(request, 'label/artist.html', context)
def releases_view(request):
artists = Artist.objects.all()
releases = Release.objects.all()
releases_and_infos = []
for release in releases:
release_tag = get_catalog_tag_from_id(release.ident)
releases_and_infos.append({
'id': release.id,
'release_type': release.release_type,
'tag': release_tag,
'title': release.title,
'contribs': get_contribs(release.contributors.all()),
'year': release.year,
'cover': release.cover,
})
context = { 'releases': releases_and_infos }
return render(request, 'label/releases.html', context)
def release_view(request, tag):
ident = get_id_from_catalog_tag(tag)
release = get_object_or_404(Release, ident = ident)
contribs = get_contribs(release.contributors.all())
context = {'release': release, 'contribs': contribs}
return render(request, 'label/release.html', context)
def videos_view(request):
videos = VideoClip.objects.order_by('-year', 'title')
context = {'videos': videos}
return render(request, 'label/videos.html', context)