From b57f65cf6bf253bf23dc786a8111a35c7e9170a8 Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Tue, 29 Aug 2023 16:27:37 -0400
Subject: [PATCH] feat: add fields to License model

add `needs_author`, `requires_express_permission_for_publication` and `url`

update LicenseSerializer and license fixture
---
 fixtures/sample/license.json                  | 24 +++++++++++------
 .../0068_license_needs_author_and_more.py     | 27 +++++++++++++++++++
 program/models.py                             |  5 +++-
 program/serializers.py                        |  9 ++++++-
 4 files changed, 55 insertions(+), 10 deletions(-)
 create mode 100644 program/migrations/0068_license_needs_author_and_more.py

diff --git a/fixtures/sample/license.json b/fixtures/sample/license.json
index c2a270e4..a5e54497 100644
--- a/fixtures/sample/license.json
+++ b/fixtures/sample/license.json
@@ -4,7 +4,8 @@
     "pk": 1,
     "fields": {
       "name": "Public Domain",
-      "identifier": "cc-0"
+      "identifier": "cc-0",
+      "url": "https://creativecommons.org/publicdomain/zero/1.0/"
     }
   },
   {
@@ -12,7 +13,8 @@
     "pk": 2,
     "fields": {
       "name": "Creative Commons Attribution",
-      "identifier": "cc-by"
+      "identifier": "cc-by",
+      "url": "https://creativecommons.org/licenses/by/4.0"
     }
   },
   {
@@ -20,7 +22,8 @@
     "pk": 3,
     "fields": {
       "name": "Creative Commons Attribution-ShareAlike",
-      "identifier": "cc-by-sa"
+      "identifier": "cc-by-sa",
+      "url": "https://creativecommons.org/licenses/by-sa/4.0"
     }
   },
   {
@@ -28,7 +31,8 @@
     "pk": 4,
     "fields": {
       "name": "Creative Commons Attribution-NonCommercial",
-      "identifier": "cc-by-nc"
+      "identifier": "cc-by-nc",
+      "url": "https://creativecommons.org/licenses/by-nc/4.0"
     }
   },
   {
@@ -36,7 +40,8 @@
     "pk": 5,
     "fields": {
       "name": "Creative Commons Attribution-NonCommercial-ShareAlike",
-      "identifier": "cc-by-nc-sa"
+      "identifier": "cc-by-nc-sa",
+      "url": "https://creativecommons.org/licenses/by-nc-sa/4.0"
     }
   },
   {
@@ -44,7 +49,8 @@
     "pk": 6,
     "fields": {
       "name": "Creative Commons Attribution-NoDerivatives",
-      "identifier": "cc-by-nd"
+      "identifier": "cc-by-nd",
+      "url": "https://creativecommons.org/licenses/by-nd/4.0"
     }
   },
   {
@@ -52,7 +58,8 @@
     "pk": 7,
     "fields": {
       "name": "Creative Commons Attribution-NonCommercial-NoDerivatives",
-      "identifier": "cc-by-nc-nd"
+      "identifier": "cc-by-nc-nd",
+      "url": "https://creativecommons.org/licenses/by-nc-nd/4.0"
     }
   },
   {
@@ -60,7 +67,8 @@
     "pk": 8,
     "fields": {
       "name": "All Rights Reserved",
-      "identifier": "all-rights-reserved"
+      "identifier": "all-rights-reserved",
+      "url": ""
     }
   }
 ]
\ No newline at end of file
diff --git a/program/migrations/0068_license_needs_author_and_more.py b/program/migrations/0068_license_needs_author_and_more.py
new file mode 100644
index 00000000..51f2da2b
--- /dev/null
+++ b/program/migrations/0068_license_needs_author_and_more.py
@@ -0,0 +1,27 @@
+# Generated by Django 4.2.4 on 2023-08-29 20:24
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("program", "0067_image_license"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="license",
+            name="needs_author",
+            field=models.BooleanField(default=True),
+        ),
+        migrations.AddField(
+            model_name="license",
+            name="requires_express_permission_for_publication",
+            field=models.BooleanField(default=True),
+        ),
+        migrations.AddField(
+            model_name="license",
+            name="url",
+            field=models.URLField(default=""),
+        ),
+    ]
diff --git a/program/models.py b/program/models.py
index 31abd0af..fb7a9196 100644
--- a/program/models.py
+++ b/program/models.py
@@ -114,8 +114,11 @@ class Language(models.Model):
 
 
 class License(models.Model):
-    name = models.CharField(max_length=64, help_text="Name of the license")
     identifier = models.CharField(max_length=32, help_text="Identifier of the license")
+    name = models.CharField(max_length=64, help_text="Name of the license")
+    needs_author = models.BooleanField(default=True)
+    requires_express_permission_for_publication = models.BooleanField(default=True)
+    url = models.URLField(default="")
 
     class Meta:
         ordering = ("name",)
diff --git a/program/serializers.py b/program/serializers.py
index 6add3d5e..1c3d2d83 100644
--- a/program/serializers.py
+++ b/program/serializers.py
@@ -188,7 +188,14 @@ class LinkTypeSerializer(serializers.ModelSerializer):
 class LicenseSerializer(serializers.ModelSerializer):
     class Meta:
         model = License
-        fields = ("id", "name", "identifier")
+        fields = (
+            "id",
+            "identifier",
+            "name",
+            "needs_author",
+            "requires_express_permission_for_publication",
+            "url",
+        )
 
 
 class HostLinkSerializer(serializers.ModelSerializer):
-- 
GitLab