Add custom project description.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 12 May 2020 07:26:57 +0000 (09:26 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 12 May 2020 07:26:57 +0000 (09:26 +0200)
src/archive/migrations/0007_project_description.py [new file with mode: 0644]
src/archive/models.py

diff --git a/src/archive/migrations/0007_project_description.py b/src/archive/migrations/0007_project_description.py
new file mode 100644 (file)
index 0000000..dc846c7
--- /dev/null
@@ -0,0 +1,18 @@
+# Generated by Django 3.0.4 on 2020-05-12 09:10
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('archive', '0006_piece'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='project',
+            name='description',
+            field=models.TextField(blank=True, verbose_name='Opis'),
+        ),
+    ]
index 51fc66c..34fc1f4 100644 (file)
@@ -15,6 +15,7 @@ class Project(models.Model):
 
     name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name="Nazwa")
     sponsors = models.TextField(blank=True, null=True, verbose_name="Sponsorzy")
+    description = models.TextField(blank=True, verbose_name="Opis")
 
     class Meta:
         verbose_name = _("project")
@@ -24,6 +25,14 @@ class Project(models.Model):
     def __str__(self):
         return self.name
 
+    def get_description(self):
+        if self.description:
+            return self.description
+        return "Audiobook nagrany w ramach projektu %s%s." % (
+            self.name,
+            " finansowanego przez %s" % self.sponsors if self.sponsors else "",
+        )
+
 
 class Piece(models.Model):
     name = models.CharField(max_length=255)
@@ -116,10 +125,10 @@ class Audiobook(models.Model):
         copyright = "%s %s. Licensed to the public under %s verify at %s" % (
                 self.date, ORGANIZATION, LICENSE, self.url)
 
-        comment = "Audiobook nagrany w ramach projektu %s%s.\n%s" % (
-                    self.project.name,
-                    " finansowanego przez %s" % self.project.sponsors if self.project.sponsors else "",
-                    ADVERT)
+        comment = "\n".join((
+            self.project.get_description(),
+            ADVERT
+        ))
 
         tags = {
             'album': PROJECT,
@@ -136,8 +145,10 @@ class Audiobook(models.Model):
             'organization': ORGANIZATION,
             'title': title,
             'project': self.project.name,
-            'funded_by': self.project.sponsors,
         }
+        if self.project.sponsors:
+            tags['funded_by'] = self.project.sponsors
+
         if self.source_sha1:
             tags['flac_sha1'] = self.source_sha1
         return tags