From 20dac82f1897ef45002430422c6c1d19c533f323 Mon Sep 17 00:00:00 2001 From: Shgck Date: Tue, 15 Aug 2017 15:26:32 +0200 Subject: [PATCH] Minor refactoring --- label/admin.py | 2 +- label/migrations/0001_initial.py | 50 ++++++++++++++++++++++++++++++++ label/migrations/__init__.py | 0 label/models.py | 42 ++++++++++++++------------- label/tools.py | 6 ++-- label/urls.py | 8 ++--- label/views.py | 28 +++++++++--------- 7 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 label/migrations/0001_initial.py create mode 100644 label/migrations/__init__.py diff --git a/label/admin.py b/label/admin.py index fd6b55a..be877eb 100644 --- a/label/admin.py +++ b/label/admin.py @@ -4,7 +4,7 @@ from label.models import Artist, Release class ArtistAdmin(admin.ModelAdmin): - exclude = ("slug",) + exclude = ('slug',) admin.site.register(Artist, ArtistAdmin) diff --git a/label/migrations/0001_initial.py b/label/migrations/0001_initial.py new file mode 100644 index 0000000..7236eaf --- /dev/null +++ b/label/migrations/0001_initial.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-08-14 16:04 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Artist', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=64)), + ('slug', models.SlugField()), + ('image', models.ImageField(upload_to='artists')), + ('url_bandcamp', models.URLField(blank=True)), + ('url_soundcloud', models.URLField(blank=True)), + ('genre', models.CharField(help_text='lowercase please!', max_length=256)), + ('description', models.TextField(blank=True, help_text='Markdown or HTML formatting supported')), + ('artist_type', models.IntegerField(default=0, help_text='main roster (0), side project (1)')), + ], + options={ + 'ordering': ('name',), + }, + ), + migrations.CreateModel( + name='Release', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('ident', models.IntegerField()), + ('title', models.CharField(max_length=256)), + ('release_type', models.IntegerField(default=0, help_text='full-length (0), EP (1), Split (2), Démo (3)')), + ('cover', models.ImageField(upload_to='releases')), + ('year', models.IntegerField()), + ('embed', models.TextField(blank=True, help_text='HTML iframe -- for Bandcamp, add the whole tracklist')), + ('description', models.TextField(blank=True)), + ('contributors', models.ManyToManyField(to='label.Artist')), + ], + options={ + 'ordering': ('ident', 'title'), + }, + ), + ] diff --git a/label/migrations/__init__.py b/label/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/label/models.py b/label/models.py index 91ec4d2..dc0931c 100644 --- a/label/models.py +++ b/label/models.py @@ -4,36 +4,35 @@ from django.dispatch.dispatcher import receiver from django.template.defaultfilters import slugify -ART_GENRE_HINT = "lowercase please!" -ART_DESC_HINT = "Markdown or HTML formatting supported" -ART_TYPES_HINT = "main roster (0), side project (1)" +ART_GENRE_HINT = 'lowercase please!' +ART_DESC_HINT = 'Markdown or HTML formatting supported' +ART_TYPES_HINT = 'main roster (0), side project (1)' + class Artist(models.Model): """ An Artist of the label. """ - name = models.CharField(max_length = 64) + name = models.CharField(max_length=64) slug = models.SlugField() - image = models.ImageField(upload_to = "artists") - url_bandcamp = models.URLField(blank = True) - url_soundcloud = models.URLField(blank = True) - genre = models.CharField(max_length = 256, help_text = ART_GENRE_HINT) - description = models.TextField(blank = True, help_text = ART_DESC_HINT) - artist_type = models.IntegerField(default = 0, help_text = ART_TYPES_HINT) + image = models.ImageField(upload_to='artists') + url_bandcamp = models.URLField(blank=True) + url_soundcloud = models.URLField(blank=True) + genre = models.CharField(max_length=256, help_text=ART_GENRE_HINT) + description = models.TextField(blank=True, help_text=ART_DESC_HINT) + artist_type = models.IntegerField(default=0, help_text=ART_TYPES_HINT) def __str__(self): return self.name class Meta(object): - ordering = ("name",) + ordering = ('name',) + @receiver(pre_save, sender = Artist) def _artist_pre_save(sender, instance, **kwargs): instance.slug = slugify(instance.name) -REL_TYPES_HINT = "full-length (0), EP (1), Split (2), Démo (3)" -REL_EMBED_HINT = "HTML iframe -- for Bandcamp, add the whole tracklist" - class Release(models.Model): """ A release (album, EP, ...) of the label. @@ -49,17 +48,20 @@ class Release(models.Model): cover: image file associated to this release """ + REL_TYPES_HINT = 'full-length (0), EP (1), Split (2), Démo (3)' + REL_EMBED_HINT = 'HTML iframe -- for Bandcamp, add the whole tracklist' + ident = models.IntegerField() - title = models.CharField(max_length = 256) + title = models.CharField(max_length=256) contributors = models.ManyToManyField(Artist) - release_type = models.IntegerField(default = 0, help_text = REL_TYPES_HINT) - cover = models.ImageField(upload_to = "releases") + release_type = models.IntegerField(default=0, help_text=REL_TYPES_HINT) + cover = models.ImageField(upload_to='releases') year = models.IntegerField() - embed = models.TextField(blank = True, help_text = REL_EMBED_HINT) - description = models.TextField(blank = True) + embed = models.TextField(blank=True, help_text=REL_EMBED_HINT) + description = models.TextField(blank=True) def __str__(self): return self.title class Meta(object): - ordering = ("ident", "title") + ordering = ('ident', 'title') diff --git a/label/tools.py b/label/tools.py index 40a2aef..85a5a8c 100644 --- a/label/tools.py +++ b/label/tools.py @@ -1,6 +1,6 @@ def get_catalog_tag_from_id(ident): - return "IDRE{:0>3d}".format(ident) + return 'IDRE{:0>3d}'.format(ident) def get_id_from_catalog_tag(tag): try: @@ -13,7 +13,7 @@ def get_contribs(contributors): contrib_list = [] for contrib in contributors: contrib_list.append({ - "slug": contrib.slug, - "name": contrib.name + 'slug': contrib.slug, + 'name': contrib.name }) return contrib_list diff --git a/label/urls.py b/label/urls.py index ccbfc70..e8e35c4 100644 --- a/label/urls.py +++ b/label/urls.py @@ -4,8 +4,8 @@ import label.views urlpatterns = [ - url(r"^artists/$", label.views.artists_view, name = "artists"), - url(r"^artists/(?P\S+)$", label.views.artist_view, name = "artist"), - url(r"^releases/$", label.views.releases_view, name = "releases"), - url(r"^releases/(?P\S+)$", label.views.release_view, name = "release") + url(r'^artists/$', label.views.artists_view, name='artists'), + url(r'^artists/(?P\S+)$', label.views.artist_view, name='artist'), + url(r'^releases/$', label.views.releases_view, name='releases'), + url(r'^releases/(?P\S+)$', label.views.release_view, name='release'), ] diff --git a/label/views.py b/label/views.py index 54c93dd..6d9d4e5 100644 --- a/label/views.py +++ b/label/views.py @@ -7,8 +7,8 @@ import label.tools as tools def artists_view(request): artists = Artist.objects.all() - context = { "artists": artists } - return render(request, "label/artists.html", context) + context = { 'artists': artists } + return render(request, 'label/artists.html', context) def artist_view(request, slug): artist = get_object_or_404(Artist, slug = slug) @@ -18,8 +18,8 @@ def artist_view(request, slug): for release in releases: release.tag = tools.get_catalog_tag_from_id(release.ident) - context = { "artist": artist, "releases": releases } - return render(request, "label/artist.html", context) + context = { 'artist': artist, 'releases': releases } + return render(request, 'label/artist.html', context) def releases_view(request): artists = Artist.objects.all() @@ -29,20 +29,20 @@ def releases_view(request): for release in releases: release_tag = tools.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": tools.get_contribs(release.contributors.all()), - "year": release.year + 'id': release.id, + 'release_type': release.release_type, + 'tag': release_tag, + 'title': release.title, + 'contribs': tools.get_contribs(release.contributors.all()), + 'year': release.year }) - context = { "releases": releases_and_infos } - return render(request, "label/releases.html", context) + context = { 'releases': releases_and_infos } + return render(request, 'label/releases.html', context) def release_view(request, tag): ident = tools.get_id_from_catalog_tag(tag) release = get_object_or_404(Release, ident = ident) contribs = tools.get_contribs(release.contributors.all()) - context = { "release": release, "contribs": contribs } - return render(request, "label/release.html", context) + context = { 'release': release, 'contribs': contribs } + return render(request, 'label/release.html', context)