1
0
Fork 0
IdreXyz/label/views.py

49 lines
1.6 KiB
Python
Raw Normal View History

from django.shortcuts import get_object_or_404, render
import markdown
2015-03-14 22:38:12 +01:00
from label.models import Artist, Release
import label.tools as tools
def artists_view(request):
2015-03-14 22:38:12 +01:00
artists = Artist.objects.all()
2017-08-15 15:26:32 +02:00
context = { 'artists': artists }
return render(request, 'label/artists.html', context)
2015-03-14 22:38:12 +01:00
def artist_view(request, slug):
artist = get_object_or_404(Artist, slug = slug)
artist.description = markdown.markdown(artist.description)
2015-03-14 22:38:12 +01:00
releases = artist.release_set.all()
for release in releases:
release.tag = tools.get_catalog_tag_from_id(release.ident)
2017-08-15 15:26:32 +02:00
context = { 'artist': artist, 'releases': releases }
return render(request, 'label/artist.html', context)
2015-03-14 22:38:12 +01:00
def releases_view(request):
2015-03-14 22:38:12 +01:00
artists = Artist.objects.all()
releases = Release.objects.all()
releases_and_infos = []
for release in releases:
release_tag = tools.get_catalog_tag_from_id(release.ident)
2015-03-14 22:38:12 +01:00
releases_and_infos.append({
2017-08-15 15:26:32 +02:00
'id': release.id,
'release_type': release.release_type,
'tag': release_tag,
'title': release.title,
'contribs': tools.get_contribs(release.contributors.all()),
'year': release.year
2015-03-14 22:38:12 +01:00
})
2017-08-15 15:26:32 +02:00
context = { 'releases': releases_and_infos }
return render(request, 'label/releases.html', context)
2015-03-14 22:38:12 +01:00
def release_view(request, tag):
ident = tools.get_id_from_catalog_tag(tag)
release = get_object_or_404(Release, ident = ident)
2015-03-14 22:38:12 +01:00
contribs = tools.get_contribs(release.contributors.all())
2017-08-15 15:26:32 +02:00
context = { 'release': release, 'contribs': contribs }
return render(request, 'label/release.html', context)