From d80bd7027ed17693842c6c42a9868b14434e8660 Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Tue, 10 May 2022 08:01:17 -0500 Subject: [PATCH 1/8] Added Content License snippet and drop down to select license of book --- books/models.py | 17 ++++++++++++++++- books/tests.py | 27 +++++++++++++++++++++++++++ snippets/models.py | 24 +++++++++++++++++++++++- snippets/serializers.py | 13 +++++++++++++ snippets/urls.py | 1 + snippets/views.py | 18 ++++++++++++++++++ 6 files changed, 98 insertions(+), 2 deletions(-) diff --git a/books/models.py b/books/models.py index 6deba14a2..0b60a73c8 100644 --- a/books/models.py +++ b/books/models.py @@ -450,6 +450,14 @@ class BookCategories(Orderable, BookCategory): book_category = ParentalKey('books.Book', related_name='book_categories') +def content_license_choices(): + licenses = snippets.ContentLicense.objects.all() + choices = [] + for l in licenses: + choices.append((str(l.license_name),str(l.license_name))), + return choices + + class Book(Page): created = models.DateTimeField(auto_now_add=True) book_state = models.CharField(max_length=255, choices=BOOK_STATES, default='live', help_text='The state of the book.') @@ -506,7 +514,7 @@ def get_title_image_url(self): license_text = models.TextField( blank=True, null=True, help_text="Overrides default license text.") license_name = models.CharField( - max_length=255, blank=True, null=True, editable=False, help_text="Name of the license.") + max_length=255, blank=True, null=True, choices=content_license_choices(), help_text="Name of the license.") license_version = models.CharField( max_length=255, blank=True, null=True, editable=False, help_text="Version of the license.") license_url = models.CharField( @@ -660,6 +668,7 @@ def get_community_resource_feature_link_url(self): FieldPanel('ibook_volume_2_isbn_10'), FieldPanel('ibook_volume_2_isbn_13'), FieldPanel('license_text'), + FieldPanel('license_name'), FieldPanel('webview_rex_link'), FieldPanel('rex_callout_title'), FieldPanel('rex_callout_blurb'), @@ -881,6 +890,12 @@ def save(self, *args, **kwargs): if self.support_statement: Book.objects.filter(locale=self.locale).update(support_statement=self.support_statement) + # populate license + if self.license_name: + book_license = snippets.ContentLicense.objects.filter(license_name=self.license_name) + self.license_url = book_license[0].license_url + self.license_version = book_license[0].version + # if book is new, clear out isbn 10 fields if self._state.adding: self.print_isbn_10 = None diff --git a/books/tests.py b/books/tests.py index afca43bd3..52d2bc3b9 100644 --- a/books/tests.py +++ b/books/tests.py @@ -1,5 +1,7 @@ from wagtail.tests.utils import WagtailPageTests from wagtail.core.models import Page + +import snippets.models from pages.models import HomePage from books.models import BookIndex, Book from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash @@ -39,6 +41,13 @@ def setUpTestData(cls): cls.book_index = Page.objects.get(id=book_index.id) + content_license = snippets.models.ContentLicense(license_code='by', + version='4.0', + license_name='Creative Commons Attribution License', + license_url='https://creativecommons.org/licenses/by/4.0/') + content_license.save() + + def test_can_create_book(self): book_index = BookIndex.objects.all()[0] root_page = Page.objects.get(title="Root") @@ -117,3 +126,21 @@ def test_cannot_create_book_under_homepage(self): def test_slashless_apis_are_good(self): assertPathDoesNotRedirectToTrailingSlash(self, '/apps/cms/api/books') assertPathDoesNotRedirectToTrailingSlash(self, '/apps/cms/api/books/slug') + + def test_can_create_book_with_cc_license(self): + book_index = BookIndex.objects.all()[0] + root_page = Page.objects.get(title="Root") + book = Book(title="University Physics", + slug="university-physics", + cnx_id='031da8d3-b525-429c-80cf-6c8ed997733a', + salesforce_abbreviation='University Phys (Calc)', + salesforce_name='University Physics', + description="Test Book", + cover=self.test_doc, + title_image=self.test_doc, + publish_date=datetime.date.today(), + locale=root_page.locale, + license_name='Creative Commons Attribution License', + ) + book_index.add_child(instance=book) + self.assertEqual(book.license_url, 'https://creativecommons.org/licenses/by/4.0/') diff --git a/snippets/models.py b/snippets/models.py index 219d84a54..5be1f9fea 100644 --- a/snippets/models.py +++ b/snippets/models.py @@ -314,4 +314,26 @@ def __str__(self): return self.name -register_snippet(BlogCollection) \ No newline at end of file +register_snippet(BlogCollection) + + +class ContentLicense(TranslatableMixin, models.Model): + license_code = models.CharField(max_length=255, blank=True, null=True) + version = models.CharField(max_length=255, blank=True, null=True) + license_name = models.CharField(max_length=255, blank=True, null=True) + license_url = models.URLField(null=True, blank=True) + + panels = [ + FieldPanel('license_code'), + FieldPanel('version'), + FieldPanel('license_name'), + FieldPanel('license_url') + ] + + api_fields = ('license_code', 'version', 'license_name', 'license_url') + + def __str__(self): + return self.license_name + + +register_snippet(ContentLicense) diff --git a/snippets/serializers.py b/snippets/serializers.py index 5070ec367..4f861500c 100644 --- a/snippets/serializers.py +++ b/snippets/serializers.py @@ -1,4 +1,8 @@ +<<<<<<< HEAD from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection +======= +from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, ContentLicense +>>>>>>> Added Content License snippet and drop down to select license of book from rest_framework import serializers, generics @@ -62,3 +66,12 @@ class Meta: fields = ('name', 'description', 'collection_image') + + +class ContentLicenseSerializer(serializers.ModelSerializer): + class Meta: + model = ContentLicense + fields = ('license_code', + 'version', + 'license_name', + 'license_url') diff --git a/snippets/urls.py b/snippets/urls.py index c9f6196bb..b644cdec9 100644 --- a/snippets/urls.py +++ b/snippets/urls.py @@ -9,4 +9,5 @@ router.register(r'givebanner', views.GiveBannerViewSet, basename="GiveBanner") router.register(r'blogcontenttype', views.BlogContentTypeViewSet, basename="BlogContentType") router.register(r'blogcollection', views.BlogCollectionViewSet, basename="BlogCollection") +router.register(r'contentlicenses', views.ContentLicenseViewSet, basename="ContentLicense") urlpatterns = router.urls diff --git a/snippets/views.py b/snippets/views.py index 0f74ade1f..7ff1388d5 100644 --- a/snippets/views.py +++ b/snippets/views.py @@ -1,7 +1,13 @@ from rest_framework import viewsets +<<<<<<< HEAD from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection from .serializers import RoleSerializer, SubjectSerializer, ErrataContentSerializer, SubjectCategorySerializer, GiveBannerSerializer, BlogContentTypeSerializer, BlogCollectionSerializer +======= +from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, ContentLicense +from .serializers import RoleSerializer, SubjectSerializer, ErrataContentSerializer, SubjectCategorySerializer, \ + GiveBannerSerializer, ContentLicenseSerializer +>>>>>>> Added Content License snippet and drop down to select license of book from rest_framework import generics, viewsets from django_filters.rest_framework import DjangoFilterBackend @@ -77,6 +83,18 @@ class BlogCollectionViewSet(viewsets.ModelViewSet): serializer_class = BlogCollectionSerializer +class ContentLicenseViewSet(viewsets.ModelViewSet): + serializer_class = ContentLicenseSerializer + filter_backends = (DjangoFilterBackend,) + + def get_queryset(self): + queryset = ContentLicense.objects.all() + locale = self.request.query_params.get('locale', None) + if locale is not None: + queryset = queryset.filter(locale=convert_locale(locale)) + return queryset + + def convert_locale(locale): if locale == 'es': return SPANISH_LOCALE_ID From 8d77ab0cfd79f76c9f9f75aedb0414fb16b8fe57 Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Tue, 10 May 2022 08:19:39 -0500 Subject: [PATCH 2/8] Add missing migrations --- .../0134_alter_book_license_name.py | 18 +++++++++++ snippets/migrations/0020_contentlicense.py | 32 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 books/migrations/0134_alter_book_license_name.py create mode 100644 snippets/migrations/0020_contentlicense.py diff --git a/books/migrations/0134_alter_book_license_name.py b/books/migrations/0134_alter_book_license_name.py new file mode 100644 index 000000000..a6dcb1c61 --- /dev/null +++ b/books/migrations/0134_alter_book_license_name.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.5 on 2022-05-09 20:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0133_bookcategories_bookcategory'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='license_name', + field=models.CharField(blank=True, choices=[('Creative Commons Attribution License', 'Creative Commons Attribution License'), ('Creative Commons Attribution-NonCommercial-ShareAlike License', 'Creative Commons Attribution-NonCommercial-ShareAlike License')], help_text='Name of the license.', max_length=255, null=True), + ), + ] diff --git a/snippets/migrations/0020_contentlicense.py b/snippets/migrations/0020_contentlicense.py new file mode 100644 index 000000000..711537a74 --- /dev/null +++ b/snippets/migrations/0020_contentlicense.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.5 on 2022-05-09 15:39 + +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailcore', '0066_collection_management_permissions'), + ('snippets', '0019_givebanner'), + ] + + operations = [ + migrations.CreateModel( + name='ContentLicense', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('translation_key', models.UUIDField(default=uuid.uuid4, editable=False)), + ('license_code', models.CharField(blank=True, max_length=255, null=True)), + ('version', models.CharField(blank=True, max_length=255, null=True)), + ('license_name', models.CharField(blank=True, max_length=255, null=True)), + ('license_url', models.URLField(blank=True, null=True)), + ('locale', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='wagtailcore.locale')), + ], + options={ + 'abstract': False, + 'unique_together': {('translation_key', 'locale')}, + }, + ), + ] From 05e18164c6b853b36ead46c586cae06eed4eda5a Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Tue, 10 May 2022 10:29:24 -0500 Subject: [PATCH 3/8] Fixed missed conflict --- snippets/serializers.py | 6 +----- snippets/views.py | 9 ++------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/snippets/serializers.py b/snippets/serializers.py index 4f861500c..d04db049a 100644 --- a/snippets/serializers.py +++ b/snippets/serializers.py @@ -1,8 +1,4 @@ -<<<<<<< HEAD -from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection -======= -from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, ContentLicense ->>>>>>> Added Content License snippet and drop down to select license of book +from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection, ContentLicense from rest_framework import serializers, generics diff --git a/snippets/views.py b/snippets/views.py index 7ff1388d5..e59bccf14 100644 --- a/snippets/views.py +++ b/snippets/views.py @@ -1,13 +1,8 @@ from rest_framework import viewsets -<<<<<<< HEAD -from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection -from .serializers import RoleSerializer, SubjectSerializer, ErrataContentSerializer, SubjectCategorySerializer, GiveBannerSerializer, BlogContentTypeSerializer, BlogCollectionSerializer -======= -from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, ContentLicense +from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, ContentLicense, BlogContentType, BlogCollection from .serializers import RoleSerializer, SubjectSerializer, ErrataContentSerializer, SubjectCategorySerializer, \ - GiveBannerSerializer, ContentLicenseSerializer ->>>>>>> Added Content License snippet and drop down to select license of book + GiveBannerSerializer, ContentLicenseSerializer, BlogContentTypeSerializer, BlogCollectionSerializer from rest_framework import generics, viewsets from django_filters.rest_framework import DjangoFilterBackend From 615812404ade4b0442b9f65f1fc7261301e814f4 Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Tue, 10 May 2022 10:38:34 -0500 Subject: [PATCH 4/8] Fixed migration merge issue --- ...erge_0020_contentlicense_0021_blogcollection.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 snippets/migrations/0022_merge_0020_contentlicense_0021_blogcollection.py diff --git a/snippets/migrations/0022_merge_0020_contentlicense_0021_blogcollection.py b/snippets/migrations/0022_merge_0020_contentlicense_0021_blogcollection.py new file mode 100644 index 000000000..5c275d08b --- /dev/null +++ b/snippets/migrations/0022_merge_0020_contentlicense_0021_blogcollection.py @@ -0,0 +1,14 @@ +# Generated by Django 3.2.5 on 2022-05-10 15:37 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('snippets', '0020_contentlicense'), + ('snippets', '0021_blogcollection'), + ] + + operations = [ + ] From 2c4cffee5427e581be2078e8a63a984dfd90ffdf Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Tue, 10 May 2022 14:17:52 -0500 Subject: [PATCH 5/8] Management command to add license where missing on live books --- .../commands/add_missing_licenses.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 books/management/commands/add_missing_licenses.py diff --git a/books/management/commands/add_missing_licenses.py b/books/management/commands/add_missing_licenses.py new file mode 100644 index 000000000..48f02bcf4 --- /dev/null +++ b/books/management/commands/add_missing_licenses.py @@ -0,0 +1,18 @@ +from django.core.management.base import BaseCommand + +from snippets.models import ContentLicense +from books.models import Book + +class Command(BaseCommand): + help="add CC license to live books that do not have one" + + def handle(self, *args, **options): + nc_sa_books = ['Cálculo volumen 1', 'Cálculo volumen 2', 'Cálculo volumen 3'] + books = Book.objects.filter(license_name=None, book_state='live') + for book in books: + if book.book_title in nc_sa_books: + book.license_name = 'Creative Commons Attribution-NonCommercial-ShareAlike License' + else: + book.license_name = 'Creative Commons Attribution License' + book.save() + print('Updated license for ' + str(book.book_title)) From 4dd67a83b119ce905b7a6ffc6a4f9df87f99bc17 Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Tue, 10 May 2022 16:29:44 -0500 Subject: [PATCH 6/8] Removed License snippet and used constants instead --- books/constants.py | 7 +++++++ books/models.py | 18 +++++++++------- books/tests.py | 7 ------- .../migrations/0023_delete_contentlicense.py | 16 ++++++++++++++ snippets/models.py | 21 ------------------- snippets/serializers.py | 10 +-------- snippets/urls.py | 1 - snippets/views.py | 16 ++------------ 8 files changed, 37 insertions(+), 59 deletions(-) create mode 100644 snippets/migrations/0023_delete_contentlicense.py diff --git a/books/constants.py b/books/constants.py index a12c5761d..f4821302f 100644 --- a/books/constants.py +++ b/books/constants.py @@ -66,3 +66,10 @@ (RED, 'Red'), (YELLOW, 'Yellow'), ) + +CC_BY_LICENSE_NAME = 'Creative Commons Attribution License' +CC_BY_LICENSE_VERSION = '4.0' +CC_BY_LICENSE_URL = 'https://creativecommons.org/licenses/by/4.0/' +CC_NC_SA_LICENSE_NAME = 'Creative Commons Attribution-NonCommercial-ShareAlike License' +CC_NC_SA_LICENSE_VERSION = '4.0' +CC_NC_SA_LICENSE_URL = 'https://creativecommons.org/licenses/by-nc-sa/4.0/' \ No newline at end of file diff --git a/books/models.py b/books/models.py index 0b60a73c8..ba62435de 100644 --- a/books/models.py +++ b/books/models.py @@ -29,7 +29,8 @@ from wagtail.core.models import Site from openstax.functions import build_document_url, build_image_url -from books.constants import BOOK_STATES, BOOK_COVER_TEXT_COLOR, COVER_COLORS +from books.constants import BOOK_STATES, BOOK_COVER_TEXT_COLOR, COVER_COLORS, CC_NC_SA_LICENSE_NAME, CC_BY_LICENSE_NAME, \ + CC_BY_LICENSE_URL, CC_NC_SA_LICENSE_URL, CC_NC_SA_LICENSE_VERSION, CC_BY_LICENSE_VERSION import snippets.models as snippets @@ -451,10 +452,9 @@ class BookCategories(Orderable, BookCategory): def content_license_choices(): - licenses = snippets.ContentLicense.objects.all() choices = [] - for l in licenses: - choices.append((str(l.license_name),str(l.license_name))), + choices.append((str(CC_BY_LICENSE_NAME),str(CC_BY_LICENSE_NAME))) + choices.append((str(CC_NC_SA_LICENSE_NAME), str(CC_NC_SA_LICENSE_NAME))) return choices @@ -892,9 +892,13 @@ def save(self, *args, **kwargs): # populate license if self.license_name: - book_license = snippets.ContentLicense.objects.filter(license_name=self.license_name) - self.license_url = book_license[0].license_url - self.license_version = book_license[0].version + if self.license_name == CC_BY_LICENSE_NAME: + self.license_url = CC_BY_LICENSE_URL + self.license_version = CC_BY_LICENSE_VERSION + else: + self.license_url = CC_NC_SA_LICENSE_URL + self.license_version = CC_NC_SA_LICENSE_VERSION + # if book is new, clear out isbn 10 fields if self._state.adding: diff --git a/books/tests.py b/books/tests.py index 52d2bc3b9..8c20a8a17 100644 --- a/books/tests.py +++ b/books/tests.py @@ -41,13 +41,6 @@ def setUpTestData(cls): cls.book_index = Page.objects.get(id=book_index.id) - content_license = snippets.models.ContentLicense(license_code='by', - version='4.0', - license_name='Creative Commons Attribution License', - license_url='https://creativecommons.org/licenses/by/4.0/') - content_license.save() - - def test_can_create_book(self): book_index = BookIndex.objects.all()[0] root_page = Page.objects.get(title="Root") diff --git a/snippets/migrations/0023_delete_contentlicense.py b/snippets/migrations/0023_delete_contentlicense.py new file mode 100644 index 000000000..43cc75979 --- /dev/null +++ b/snippets/migrations/0023_delete_contentlicense.py @@ -0,0 +1,16 @@ +# Generated by Django 3.2.5 on 2022-05-10 21:12 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('snippets', '0022_merge_0020_contentlicense_0021_blogcollection'), + ] + + operations = [ + migrations.DeleteModel( + name='ContentLicense', + ), + ] diff --git a/snippets/models.py b/snippets/models.py index 5be1f9fea..5a4bba929 100644 --- a/snippets/models.py +++ b/snippets/models.py @@ -316,24 +316,3 @@ def __str__(self): register_snippet(BlogCollection) - -class ContentLicense(TranslatableMixin, models.Model): - license_code = models.CharField(max_length=255, blank=True, null=True) - version = models.CharField(max_length=255, blank=True, null=True) - license_name = models.CharField(max_length=255, blank=True, null=True) - license_url = models.URLField(null=True, blank=True) - - panels = [ - FieldPanel('license_code'), - FieldPanel('version'), - FieldPanel('license_name'), - FieldPanel('license_url') - ] - - api_fields = ('license_code', 'version', 'license_name', 'license_url') - - def __str__(self): - return self.license_name - - -register_snippet(ContentLicense) diff --git a/snippets/serializers.py b/snippets/serializers.py index d04db049a..7a27742af 100644 --- a/snippets/serializers.py +++ b/snippets/serializers.py @@ -1,4 +1,4 @@ -from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection, ContentLicense +from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection from rest_framework import serializers, generics @@ -63,11 +63,3 @@ class Meta: 'description', 'collection_image') - -class ContentLicenseSerializer(serializers.ModelSerializer): - class Meta: - model = ContentLicense - fields = ('license_code', - 'version', - 'license_name', - 'license_url') diff --git a/snippets/urls.py b/snippets/urls.py index b644cdec9..c9f6196bb 100644 --- a/snippets/urls.py +++ b/snippets/urls.py @@ -9,5 +9,4 @@ router.register(r'givebanner', views.GiveBannerViewSet, basename="GiveBanner") router.register(r'blogcontenttype', views.BlogContentTypeViewSet, basename="BlogContentType") router.register(r'blogcollection', views.BlogCollectionViewSet, basename="BlogCollection") -router.register(r'contentlicenses', views.ContentLicenseViewSet, basename="ContentLicense") urlpatterns = router.urls diff --git a/snippets/views.py b/snippets/views.py index e59bccf14..4c0e2bcfa 100644 --- a/snippets/views.py +++ b/snippets/views.py @@ -1,8 +1,8 @@ from rest_framework import viewsets -from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, ContentLicense, BlogContentType, BlogCollection +from .models import Role, Subject, ErrataContent, SubjectCategory, GiveBanner, BlogContentType, BlogCollection from .serializers import RoleSerializer, SubjectSerializer, ErrataContentSerializer, SubjectCategorySerializer, \ - GiveBannerSerializer, ContentLicenseSerializer, BlogContentTypeSerializer, BlogCollectionSerializer + GiveBannerSerializer, BlogContentTypeSerializer, BlogCollectionSerializer from rest_framework import generics, viewsets from django_filters.rest_framework import DjangoFilterBackend @@ -78,18 +78,6 @@ class BlogCollectionViewSet(viewsets.ModelViewSet): serializer_class = BlogCollectionSerializer -class ContentLicenseViewSet(viewsets.ModelViewSet): - serializer_class = ContentLicenseSerializer - filter_backends = (DjangoFilterBackend,) - - def get_queryset(self): - queryset = ContentLicense.objects.all() - locale = self.request.query_params.get('locale', None) - if locale is not None: - queryset = queryset.filter(locale=convert_locale(locale)) - return queryset - - def convert_locale(locale): if locale == 'es': return SPANISH_LOCALE_ID From f4f870d6a781978563adce690d63649fdefa0dc6 Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Wed, 11 May 2022 07:41:46 -0500 Subject: [PATCH 7/8] Added default for dropdown --- .../migrations/0135_alter_book_license_name.py | 18 ++++++++++++++++++ books/models.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 books/migrations/0135_alter_book_license_name.py diff --git a/books/migrations/0135_alter_book_license_name.py b/books/migrations/0135_alter_book_license_name.py new file mode 100644 index 000000000..775fb6663 --- /dev/null +++ b/books/migrations/0135_alter_book_license_name.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.5 on 2022-05-11 12:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0134_alter_book_license_name'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='license_name', + field=models.CharField(blank=True, choices=[('Creative Commons Attribution License', 'Creative Commons Attribution License'), ('Creative Commons Attribution-NonCommercial-ShareAlike License', 'Creative Commons Attribution-NonCommercial-ShareAlike License')], default='Creative Commons Attribution License', help_text='Name of the license.', max_length=255, null=True), + ), + ] diff --git a/books/models.py b/books/models.py index ba62435de..e81ed48aa 100644 --- a/books/models.py +++ b/books/models.py @@ -514,7 +514,7 @@ def get_title_image_url(self): license_text = models.TextField( blank=True, null=True, help_text="Overrides default license text.") license_name = models.CharField( - max_length=255, blank=True, null=True, choices=content_license_choices(), help_text="Name of the license.") + max_length=255, blank=True, null=True, choices=content_license_choices(),default='Creative Commons Attribution License', help_text="Name of the license.") license_version = models.CharField( max_length=255, blank=True, null=True, editable=False, help_text="Version of the license.") license_url = models.CharField( From f46a47afa5ed8c7ab5c080594a14cd0405a28a92 Mon Sep 17 00:00:00 2001 From: Ed Woodward Date: Wed, 11 May 2022 08:12:41 -0500 Subject: [PATCH 8/8] Altered default and choices --- books/migrations/0135_alter_book_license_name.py | 2 +- books/models.py | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/books/migrations/0135_alter_book_license_name.py b/books/migrations/0135_alter_book_license_name.py index 775fb6663..034aa7d7b 100644 --- a/books/migrations/0135_alter_book_license_name.py +++ b/books/migrations/0135_alter_book_license_name.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.5 on 2022-05-11 12:39 +# Generated by Django 3.2.5 on 2022-05-11 12:58 from django.db import migrations, models diff --git a/books/models.py b/books/models.py index e81ed48aa..a242490d2 100644 --- a/books/models.py +++ b/books/models.py @@ -451,14 +451,12 @@ class BookCategories(Orderable, BookCategory): book_category = ParentalKey('books.Book', related_name='book_categories') -def content_license_choices(): - choices = [] - choices.append((str(CC_BY_LICENSE_NAME),str(CC_BY_LICENSE_NAME))) - choices.append((str(CC_NC_SA_LICENSE_NAME), str(CC_NC_SA_LICENSE_NAME))) - return choices - - class Book(Page): + licenses = ( + (CC_BY_LICENSE_NAME, CC_BY_LICENSE_NAME), + (CC_NC_SA_LICENSE_NAME, CC_NC_SA_LICENSE_NAME) + ) + created = models.DateTimeField(auto_now_add=True) book_state = models.CharField(max_length=255, choices=BOOK_STATES, default='live', help_text='The state of the book.') cnx_id = models.CharField( @@ -514,7 +512,7 @@ def get_title_image_url(self): license_text = models.TextField( blank=True, null=True, help_text="Overrides default license text.") license_name = models.CharField( - max_length=255, blank=True, null=True, choices=content_license_choices(),default='Creative Commons Attribution License', help_text="Name of the license.") + max_length=255, blank=True, null=True, choices=licenses,default=CC_BY_LICENSE_NAME, help_text="Name of the license.") license_version = models.CharField( max_length=255, blank=True, null=True, editable=False, help_text="Version of the license.") license_url = models.CharField(