1
0
Fork 0
IdreXyz/label/views.py

64 lines
1.9 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
2017-08-17 19:25:59 +02:00
from label.models import Artist, Release, VideoClip
from label.tools import (
get_catalog_tag_from_id,
get_contribs,
get_id_from_catalog_tag,
)
2015-03-14 22:38:12 +01:00
def artists_view(request):
2015-03-14 22:38:12 +01:00
artists = Artist.objects.all()
2018-04-26 21:52:47 +02:00
context = {'artists': artists}
2017-08-15 15:26:32 +02:00
return render(request, 'label/artists.html', context)
2015-03-14 22:38:12 +01:00
2017-08-17 16:44:26 +02:00
def artist_view(request, slug):
2021-08-23 17:03:24 +02:00
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:
2017-08-17 19:36:54 +02:00
release.tag = get_catalog_tag_from_id(release.ident)
2018-04-26 21:52:47 +02:00
context = {'artist': artist, 'releases': releases}
2017-08-15 15:26:32 +02:00
return render(request, 'label/artist.html', context)
2015-03-14 22:38:12 +01:00
2017-08-17 16:44:26 +02:00
def releases_view(request):
2015-03-14 22:38:12 +01:00
artists = Artist.objects.all()
2021-08-23 17:03:24 +02:00
releases = Release.objects.filter(released=True)
2015-03-14 22:38:12 +01:00
releases_and_infos = []
for release in releases:
2017-08-17 19:36:54 +02:00
release_tag = 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,
2017-08-17 19:36:54 +02:00
'contribs': get_contribs(release.contributors.all()),
2017-08-17 16:44:26 +02:00
'year': release.year,
'cover': release.cover,
2023-09-14 22:34:18 +02:00
'url_bandcamp': release.url_bandcamp,
2015-03-14 22:38:12 +01:00
})
2021-08-23 17:03:24 +02:00
context = {'releases': releases_and_infos}
2017-08-15 15:26:32 +02:00
return render(request, 'label/releases.html', context)
2015-03-14 22:38:12 +01:00
2017-08-17 16:44:26 +02:00
def release_view(request, tag):
2017-08-17 19:36:54 +02:00
ident = get_id_from_catalog_tag(tag)
2021-08-23 17:03:24 +02:00
release = get_object_or_404(Release, ident=ident, released=True)
2017-08-17 19:36:54 +02:00
contribs = get_contribs(release.contributors.all())
2018-04-26 21:52:47 +02:00
context = {'release': release, 'contribs': contribs}
2017-08-15 15:26:32 +02:00
return render(request, 'label/release.html', context)
2017-08-17 19:25:59 +02:00
def videos_view(request):
2017-08-17 19:36:54 +02:00
videos = VideoClip.objects.order_by('-year', 'title')
2018-04-26 21:52:47 +02:00
context = {'videos': videos}
2017-08-17 19:25:59 +02:00
return render(request, 'label/videos.html', context)