Save audiobook project funding info in the model.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 16 Mar 2021 13:55:42 +0000 (14:55 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 16 Mar 2021 13:55:42 +0000 (14:55 +0100)
src/catalogue/api/views.py
src/catalogue/migrations/0031_auto_20210316_1446.py [new file with mode: 0644]
src/catalogue/models/bookmedia.py
src/catalogue/templates/catalogue/snippets/jplayer.html

index 8b0dc1a..faeeb3c 100644 (file)
@@ -135,6 +135,10 @@ class BookList(ListAPIView):
         name = request.POST.get('name', '')
         part_name = request.POST.get('part_name', '')
 
         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)
 
         _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.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)
 
         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 (file)
index 0000000..0188a31
--- /dev/null
@@ -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),
+        ),
+    ]
index 010512a..14483eb 100644 (file)
@@ -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)
     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)
     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)
index 4398746..c82c1e8 100644 (file)
                     {% trans "Artist:" %}&nbsp;<span class='artist'>{{ extra_info.artist_name }}</span>,
                     {% trans "director:" %}&nbsp;<span class='director'>{{ extra_info.director_name }}</span>
                     {% if extra_info.license %}{% license_icon extra_info.license %}{% endif %}
                     {% trans "Artist:" %}&nbsp;<span class='artist'>{{ extra_info.artist_name }}</span>,
                     {% trans "director:" %}&nbsp;<span class='director'>{{ extra_info.director_name }}</span>
                     {% if extra_info.license %}{% license_icon extra_info.license %}{% endif %}
+                    {% if i.mp3.project_icon %}<img src="{{ i.mp3.project_icon }}">{% endif %}
                     <p>
                     <p>
+                     {% 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 %}
                       {% with fb=extra_info.funded_by %}
                         {% if fb %}Dofinansowano ze środków: {{ fb }}.{% endif %}
                       {% endwith %}
+                    {% endif %}
                     </p>
                  {% endwith %}
                   </div>
                     </p>
                  {% endwith %}
                   </div>