From 8505074633ff2e2194b7f845fc84f2040686e570 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 16 Mar 2021 14:55:42 +0100 Subject: [PATCH 1/1] Save audiobook project funding info in the model. --- src/catalogue/api/views.py | 6 +++++ .../migrations/0031_auto_20210316_1446.py | 27 +++++++++++++++++++ src/catalogue/models/bookmedia.py | 2 ++ .../templates/catalogue/snippets/jplayer.html | 3 +++ 4 files changed, 38 insertions(+) create mode 100644 src/catalogue/migrations/0031_auto_20210316_1446.py diff --git a/src/catalogue/api/views.py b/src/catalogue/api/views.py index 8b0dc1afc..faeeb3c08 100644 --- a/src/catalogue/api/views.py +++ b/src/catalogue/api/views.py @@ -135,6 +135,10 @@ class BookList(ListAPIView): name = request.POST.get('name', '') part_name = request.POST.get('part_name', '') + project_data = request.POST.get('project', {}) + project_description = project_data.get('description', '') + project_icon = project_data.get('icon', '') + _rest, slug = request.POST['book'].rstrip('/').rsplit('/', 1) book = Book.objects.get(slug=slug) @@ -146,6 +150,8 @@ class BookList(ListAPIView): bm.name = name bm.part_name = part_name bm.index = index + bm.project_description = project_description + bm.project_icon = project_icon bm.file.save(None, request.data['file'], save=False) bm.save(parts_count=parts_count) diff --git a/src/catalogue/migrations/0031_auto_20210316_1446.py b/src/catalogue/migrations/0031_auto_20210316_1446.py new file mode 100644 index 000000000..0188a31d0 --- /dev/null +++ b/src/catalogue/migrations/0031_auto_20210316_1446.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.16 on 2021-03-16 13:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('catalogue', '0030_collection_role'), + ] + + operations = [ + migrations.AlterModelOptions( + name='bookmedia', + options={'ordering': ('type', 'index'), 'verbose_name': 'book media', 'verbose_name_plural': 'book media'}, + ), + migrations.AddField( + model_name='bookmedia', + name='project_description', + field=models.CharField(blank=True, max_length=2048), + ), + migrations.AddField( + model_name='bookmedia', + name='project_icon', + field=models.CharField(blank=True, max_length=2048), + ), + ] diff --git a/src/catalogue/models/bookmedia.py b/src/catalogue/models/bookmedia.py index 010512ad2..14483eb83 100644 --- a/src/catalogue/models/bookmedia.py +++ b/src/catalogue/models/bookmedia.py @@ -38,6 +38,8 @@ class BookMedia(models.Model): index = models.IntegerField(_('index'), default=0) file = models.FileField(_('file'), max_length=600, upload_to=_file_upload_to, storage=OverwriteStorage()) uploaded_at = models.DateTimeField(_('creation date'), auto_now_add=True, editable=False, db_index=True) + project_description = models.CharField(max_length=2048, blank=True) + project_icon = models.CharField(max_length=2048, blank=True) extra_info = models.TextField(_('extra information'), default='{}', editable=False) book = models.ForeignKey('Book', models.CASCADE, related_name='media') source_sha1 = models.CharField(null=True, blank=True, max_length=40, editable=False) diff --git a/src/catalogue/templates/catalogue/snippets/jplayer.html b/src/catalogue/templates/catalogue/snippets/jplayer.html index 4398746b6..c82c1e826 100644 --- a/src/catalogue/templates/catalogue/snippets/jplayer.html +++ b/src/catalogue/templates/catalogue/snippets/jplayer.html @@ -36,10 +36,13 @@ {% trans "Artist:" %} {{ extra_info.artist_name }}, {% trans "director:" %} {{ extra_info.director_name }} {% if extra_info.license %}{% license_icon extra_info.license %}{% endif %} + {% if i.mp3.project_icon %}{% endif %}

+ {% if i.mp3.project_description %}{{ i.mp3.project_description }}{% else %} {% with fb=extra_info.funded_by %} {% if fb %}Dofinansowano ze środków: {{ fb }}.{% endif %} {% endwith %} + {% endif %}

{% endwith %} -- 2.20.1