1
0
Fork 0

Minor refactoring

This commit is contained in:
Shgck 2017-08-15 15:26:32 +02:00
parent 9601776aa9
commit 20dac82f18
7 changed files with 94 additions and 42 deletions

View file

@ -4,7 +4,7 @@ from label.models import Artist, Release
class ArtistAdmin(admin.ModelAdmin):
exclude = ("slug",)
exclude = ('slug',)
admin.site.register(Artist, ArtistAdmin)

View file

@ -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'),
},
),
]

View file

View file

@ -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')

View file

@ -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

View file

@ -4,8 +4,8 @@ import label.views
urlpatterns = [
url(r"^artists/$", label.views.artists_view, name = "artists"),
url(r"^artists/(?P<slug>\S+)$", label.views.artist_view, name = "artist"),
url(r"^releases/$", label.views.releases_view, name = "releases"),
url(r"^releases/(?P<tag>\S+)$", label.views.release_view, name = "release")
url(r'^artists/$', label.views.artists_view, name='artists'),
url(r'^artists/(?P<slug>\S+)$', label.views.artist_view, name='artist'),
url(r'^releases/$', label.views.releases_view, name='releases'),
url(r'^releases/(?P<tag>\S+)$', label.views.release_view, name='release'),
]

View file

@ -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)