1
0
Fork 0

models: add released flag for releases

This commit is contained in:
dece 2021-08-23 17:03:24 +02:00
parent f21b23e849
commit de492c7a9e
4 changed files with 45 additions and 4 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 3.2.6 on 2021-08-23 14:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('label', '0003_auto_20170818_1202'),
]
operations = [
migrations.AddField(
model_name='release',
name='released',
field=models.BooleanField(default=False),
),
]

View file

@ -0,0 +1,21 @@
# Generated by Django 3.2.6 on 2021-08-23 14:58
from django.db import migrations
def publish_all_releases(apps, schema_editor):
Release = apps.get_model('label', 'Release')
for release in Release.objects.all():
release.released = True
release.save()
class Migration(migrations.Migration):
dependencies = [
('label', '0004_release_released'),
]
operations = [
migrations.RunPython(publish_all_releases),
]

View file

@ -45,6 +45,7 @@ class Release(models.Model):
release_type: see TYPE_HINT release_type: see TYPE_HINT
year: year of release year: year of release
cover: image file associated to this release cover: image file associated to this release
released: show this release publicly
""" """
TYPE_HINT = 'full-length (0), EP (1), Split (2), Démo (3)' TYPE_HINT = 'full-length (0), EP (1), Split (2), Démo (3)'
@ -58,6 +59,7 @@ class Release(models.Model):
year = models.IntegerField() year = models.IntegerField()
embed = models.TextField(blank=True, help_text=EMBED_HINT) embed = models.TextField(blank=True, help_text=EMBED_HINT)
description = models.TextField(blank=True) description = models.TextField(blank=True)
released = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return self.title return self.title

View file

@ -16,7 +16,7 @@ def artists_view(request):
def artist_view(request, slug): def artist_view(request, slug):
artist = get_object_or_404(Artist, slug = slug) artist = get_object_or_404(Artist, slug=slug)
artist.description = markdown.markdown(artist.description) artist.description = markdown.markdown(artist.description)
releases = artist.release_set.all() releases = artist.release_set.all()
@ -29,7 +29,7 @@ def artist_view(request, slug):
def releases_view(request): def releases_view(request):
artists = Artist.objects.all() artists = Artist.objects.all()
releases = Release.objects.all() releases = Release.objects.filter(released=True)
releases_and_infos = [] releases_and_infos = []
for release in releases: for release in releases:
@ -44,13 +44,13 @@ def releases_view(request):
'cover': release.cover, 'cover': release.cover,
}) })
context = { 'releases': releases_and_infos } context = {'releases': releases_and_infos}
return render(request, 'label/releases.html', context) return render(request, 'label/releases.html', context)
def release_view(request, tag): def release_view(request, tag):
ident = get_id_from_catalog_tag(tag) ident = get_id_from_catalog_tag(tag)
release = get_object_or_404(Release, ident = ident) release = get_object_or_404(Release, ident=ident, released=True)
contribs = get_contribs(release.contributors.all()) contribs = get_contribs(release.contributors.all())
context = {'release': release, 'contribs': contribs} context = {'release': release, 'contribs': contribs}
return render(request, 'label/release.html', context) return render(request, 'label/release.html', context)