From de492c7a9e45975230d0cc4e633e344974944d19 Mon Sep 17 00:00:00 2001 From: dece Date: Mon, 23 Aug 2021 17:03:24 +0200 Subject: [PATCH] models: add released flag for releases --- label/migrations/0004_release_released.py | 18 ++++++++++++++++++ label/migrations/0005_auto_20210823_1658.py | 21 +++++++++++++++++++++ label/models.py | 2 ++ label/views.py | 8 ++++---- 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 label/migrations/0004_release_released.py create mode 100644 label/migrations/0005_auto_20210823_1658.py diff --git a/label/migrations/0004_release_released.py b/label/migrations/0004_release_released.py new file mode 100644 index 0000000..fe12ed9 --- /dev/null +++ b/label/migrations/0004_release_released.py @@ -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), + ), + ] diff --git a/label/migrations/0005_auto_20210823_1658.py b/label/migrations/0005_auto_20210823_1658.py new file mode 100644 index 0000000..675be83 --- /dev/null +++ b/label/migrations/0005_auto_20210823_1658.py @@ -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), + ] diff --git a/label/models.py b/label/models.py index 9b75987..02e8ab0 100644 --- a/label/models.py +++ b/label/models.py @@ -45,6 +45,7 @@ class Release(models.Model): release_type: see TYPE_HINT year: year of 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)' @@ -58,6 +59,7 @@ class Release(models.Model): year = models.IntegerField() embed = models.TextField(blank=True, help_text=EMBED_HINT) description = models.TextField(blank=True) + released = models.BooleanField(default=False) def __str__(self): return self.title diff --git a/label/views.py b/label/views.py index 010a253..c7e0c63 100644 --- a/label/views.py +++ b/label/views.py @@ -16,7 +16,7 @@ def artists_view(request): 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) releases = artist.release_set.all() @@ -29,7 +29,7 @@ def artist_view(request, slug): def releases_view(request): artists = Artist.objects.all() - releases = Release.objects.all() + releases = Release.objects.filter(released=True) releases_and_infos = [] for release in releases: @@ -44,13 +44,13 @@ def releases_view(request): 'cover': release.cover, }) - context = { 'releases': releases_and_infos } + 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) + release = get_object_or_404(Release, ident=ident, released=True) contribs = get_contribs(release.contributors.all()) context = {'release': release, 'contribs': contribs} return render(request, 'label/release.html', context)