diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000000000000000000000000000000000000..48346b643ab33b8fec36979cb2eeb5644f0806fe --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,8 @@ +Changelog +========= + + +0.2.4 (unreleased) +------------------ + +Models: now store relese group mbid on Album model (#7) diff --git a/api/funkwhale_api/music/migrations/0013_auto_20171213_2211.py b/api/funkwhale_api/music/migrations/0013_auto_20171213_2211.py new file mode 100644 index 0000000000000000000000000000000000000000..00ccbb6218d303d95b65273c058f596dbd7e3da6 --- /dev/null +++ b/api/funkwhale_api/music/migrations/0013_auto_20171213_2211.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2017-12-13 22:11 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('music', '0012_auto_20161122_1905'), + ] + + operations = [ + migrations.AlterModelOptions( + name='importjob', + options={'ordering': ('id',)}, + ), + migrations.AlterModelOptions( + name='track', + options={'ordering': ['album', 'position']}, + ), + migrations.AddField( + model_name='album', + name='release_group_id', + field=models.UUIDField(blank=True, null=True), + ), + ] diff --git a/api/funkwhale_api/music/models.py b/api/funkwhale_api/music/models.py index 596f890b7e43b609d036c4a46040973544eaf2fd..d87da1eb7cb4b8a59dbb45dd195d660ba2230655 100644 --- a/api/funkwhale_api/music/models.py +++ b/api/funkwhale_api/music/models.py @@ -110,13 +110,14 @@ class Album(APIModelMixin): title = models.CharField(max_length=255) artist = models.ForeignKey(Artist, related_name='albums') release_date = models.DateField(null=True) + release_group_id = models.UUIDField(null=True, blank=True) cover = VersatileImageField(upload_to='albums/covers/%Y/%m/%d', null=True, blank=True) TYPE_CHOICES = ( ('album', 'Album'), ) type = models.CharField(choices=TYPE_CHOICES, max_length=30, default='album') - api_includes = ['artist-credits', 'recordings', 'media'] + api_includes = ['artist-credits', 'recordings', 'media', 'release-groups'] api = musicbrainz.api.releases musicbrainz_model = 'release' musicbrainz_mapping = { @@ -127,6 +128,10 @@ class Album(APIModelMixin): 'musicbrainz_field_name': 'release-list', 'converter': lambda v: int(v[0]['medium-list'][0]['position']), }, + 'release_group_id': { + 'musicbrainz_field_name': 'release-group', + 'converter': lambda v: v['id'], + }, 'title': { 'musicbrainz_field_name': 'title', }, diff --git a/api/funkwhale_api/music/tests/factories.py b/api/funkwhale_api/music/tests/factories.py index ea680b3bd5d4da58e63f5ee4c861fec7972117f4..d3cd625b3da554920d3b2932ef7e08d51c2a517c 100644 --- a/api/funkwhale_api/music/tests/factories.py +++ b/api/funkwhale_api/music/tests/factories.py @@ -18,6 +18,7 @@ class AlbumFactory(factory.django.DjangoModelFactory): release_date = factory.Faker('date') cover = factory.django.ImageField() artist = factory.SubFactory(ArtistFactory) + release_group_id = factory.Faker('uuid4') class Meta: model = 'music.Album' diff --git a/api/funkwhale_api/music/tests/test_models.py b/api/funkwhale_api/music/tests/test_models.py new file mode 100644 index 0000000000000000000000000000000000000000..a652676d7d40c03ee3bd1a5b5665f6fa4fcb52c0 --- /dev/null +++ b/api/funkwhale_api/music/tests/test_models.py @@ -0,0 +1,41 @@ +import pytest + +from funkwhale_api.music import models +from funkwhale_api.music import importers +from . import factories + + +def test_can_store_release_group_id_on_album(db): + album = factories.AlbumFactory() + assert album.release_group_id is not None + + +def test_import_album_stores_release_group(db): + + album_data = { + "artist-credit": [ + { + "artist": { + "disambiguation": "George Shaw", + "id": "62c3befb-6366-4585-b256-809472333801", + "name": "Adhesive Wombat", + "sort-name": "Wombat, Adhesive" + } + } + ], + "artist-credit-phrase": "Adhesive Wombat", + "country": "XW", + "date": "2013-06-05", + "id": "a50d2a81-2a50-484d-9cb4-b9f6833f583e", + "status": "Official", + "title": "Marsupial Madness", + 'release-group': {'id': '447b4979-2178-405c-bfe6-46bf0b09e6c7'} + } + artist = factories.ArtistFactory( + mbid=album_data['artist-credit'][0]['artist']['id'] + ) + cleaned_data = models.Album.clean_musicbrainz_data(album_data) + album = importers.load(models.Album, cleaned_data, album_data, import_hooks=[]) + + assert album.release_group_id == album_data['release-group']['id'] + assert album.artist == artist diff --git a/dev.yml b/dev.yml index 54bc62d874d00c5ec9e740f8240027dad36cbad4..c71298cfc8932c1b7874a906b582fe85a59ee4bd 100644 --- a/dev.yml +++ b/dev.yml @@ -33,9 +33,12 @@ services: - redis command: python manage.py celery worker environment: - - C_FORCE_ROOT=true - - "DATABASE_URL=postgresql://postgres@postgres/postgres" - - "CACHE_URL=redis://redis:6379/0" + - "DJANGO_ALLOWED_HOSTS=localhost" + - "DJANGO_SETTINGS_MODULE=config.settings.local" + - "DJANGO_SECRET_KEY=dev" + - C_FORCE_ROOT=true + - "DATABASE_URL=postgresql://postgres@postgres/postgres" + - "CACHE_URL=redis://redis:6379/0" volumes: - ./api:/app - ./data/music:/music @@ -49,6 +52,9 @@ services: - ./api:/app - ./data/music:/music environment: + - "DJANGO_ALLOWED_HOSTS=localhost" + - "DJANGO_SETTINGS_MODULE=config.settings.local" + - "DJANGO_SECRET_KEY=dev" - "DATABASE_URL=postgresql://postgres@postgres/postgres" - "CACHE_URL=redis://redis:6379/0" ports: