-
Notifications
You must be signed in to change notification settings - Fork 16
Added Content License drop down to select license of book #1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d80bd70
Added Content License snippet and drop down to select license of book
edwoodward 8d77ab0
Add missing migrations
edwoodward 05e1816
Fixed missed conflict
edwoodward 6158124
Fixed migration merge issue
edwoodward 2c4cffe
Management command to add license where missing on live books
edwoodward 4dd67a8
Removed License snippet and used constants instead
edwoodward f4f870d
Added default for dropdown
edwoodward f46a47a
Altered default and choices
edwoodward File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.2.5 on 2022-05-11 12:58 | ||
|
||
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), | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,6 +452,11 @@ class BookCategories(Orderable, BookCategory): | |
|
||
|
||
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( | ||
|
@@ -506,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, editable=False, 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( | ||
|
@@ -660,6 +666,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 +888,16 @@ def save(self, *args, **kwargs): | |
if self.support_statement: | ||
Book.objects.filter(locale=self.locale).update(support_statement=self.support_statement) | ||
|
||
# populate license | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I see what you are doing - might want to set the other license fields to uneditable then |
||
if self.license_name: | ||
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: | ||
self.print_isbn_10 = None | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
from wagtail.tests.utils import WagtailPageTests | ||
from wagtail.core.models import Page | ||
|
||
import snippets.models | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused import? |
||
from pages.models import HomePage | ||
from books.models import BookIndex, Book | ||
from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash | ||
|
@@ -117,3 +119,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/') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')}, | ||
}, | ||
), | ||
] |
14 changes: 14 additions & 0 deletions
14
snippets/migrations/0022_merge_0020_contentlicense_0021_blogcollection.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = [ | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,4 +314,5 @@ def __str__(self): | |
return self.name | ||
|
||
|
||
register_snippet(BlogCollection) | ||
register_snippet(BlogCollection) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,4 @@ class Meta: | |
fields = ('name', | ||
'description', | ||
'collection_image') | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do the other license fields not need similar choices?