Skip to content

Commit

Permalink
adding k12 pages, subjects (#1374)
Browse files Browse the repository at this point in the history
* adding k12 pages, subjects

* fix class naming convention

* added student and instructor resources to k12 subject pages

* Tidy pages/model.py

* remove seo title and search description from snippets/models

Co-authored-by: dmoreno <[email protected]>
  • Loading branch information
dmoreno27 and dmoreno authored Jan 12, 2023
1 parent c97731b commit 3a4a4e3
Show file tree
Hide file tree
Showing 8 changed files with 503 additions and 9 deletions.
32 changes: 32 additions & 0 deletions books/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@
(YELLOW, 'Yellow'),
)

MATH = 'math'
SOCIAL_STUDIES='social-studies'
SCIENCE = 'science'
ENGLISH = 'english'
CAREER_TECHNICAL = 'career-technical'
COLLEGE_READINESS = 'college_readiness'
FINE_ARTS = 'fine_arts'
HEALTH = 'health'
LANGUAGES = 'languages'
PHYSICAL_ED = 'physical_education'
TECHNOLOGY_APPLICATIONS = 'technology_applications'
OTHER = 'other'
NONE = 'none'


K12_CATEGORIES = (
(MATH, 'Math'),
(SOCIAL_STUDIES, 'Social Studies'),
(SCIENCE, 'Science'),
(ENGLISH, 'English Language Areas & Reading'),
(CAREER_TECHNICAL, 'Career and Technical Education'),
(COLLEGE_READINESS, 'College Readiness'),
(FINE_ARTS, 'Fine Arts'),
(HEALTH, 'Health Education'),
(LANGUAGES, 'Languages other than English'),
(PHYSICAL_ED, 'Physical Education'),
(TECHNOLOGY_APPLICATIONS, 'Technology Applications'),
(OTHER, 'Other'),
(NONE, 'None'),
)


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/'
Expand Down
31 changes: 29 additions & 2 deletions books/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from openstax.functions import build_document_url, build_image_url
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
CC_BY_LICENSE_URL, CC_NC_SA_LICENSE_URL, CC_NC_SA_LICENSE_VERSION, CC_BY_LICENSE_VERSION, K12_CATEGORIES
import snippets.models as snippets


Expand Down Expand Up @@ -387,6 +387,22 @@ def get_subject_meta(self):
APIField('subject_search_description')
]

class K12SubjectBooks(models.Model):
subject = models.ForeignKey(snippets.K12Subject, on_delete=models.SET_NULL, null=True, related_name='k12subjects_subject')

def get_subject_name(self):
return self.subject.name
subject_name = property(get_subject_name)

def get_subject_category(self):
return self.subject.subject_category
subject_category = property(get_subject_category)

api_fields = [
APIField('subject_name'),
APIField('subject_category'),
]


class BookCategory(models.Model):
category = models.ForeignKey(snippets.SubjectCategory, on_delete=models.SET_NULL, null=True, related_name='subjects_subjectcategory')
Expand Down Expand Up @@ -441,10 +457,12 @@ class OrientationFacultyResources(Orderable, OrientationFacultyResource):
class BookStudentResources(Orderable, StudentResources):
book_student_resource = ParentalKey('books.Book', related_name='book_student_resources')


class BookSubjects(Orderable, SubjectBooks):
book_subject = ParentalKey('books.Book', related_name='book_subjects')

class K12BookSubjects(Orderable, K12SubjectBooks):
k12book_subject = ParentalKey('books.Book', related_name='k12book_subjects')


class BookCategories(Orderable, BookCategory):
book_category = ParentalKey('books.Book', related_name='book_categories')
Expand All @@ -466,6 +484,7 @@ class Book(Page):
salesforce_book_id = models.CharField(max_length=255, blank=True, null=True,
help_text='No tracking and not included on adoption and interest forms if left blank)')
updated = models.DateTimeField(blank=True, null=True, help_text='Late date web content was updated')
k12_subject = models.CharField(max_length=255, choices=K12_CATEGORIES, default='none')
is_ap = models.BooleanField(default=False, help_text='Whether this book is an AP (Advanced Placement) book.')
description = RichTextField(
blank=True, help_text="Description shown on Book Detail page.")
Expand Down Expand Up @@ -650,6 +669,7 @@ def get_community_resource_feature_link_url(self):
FieldPanel('publish_date'),
InlinePanel('book_subjects', label='Subjects'),
InlinePanel('book_categories', label='Subject Categories'),
InlinePanel('k12book_subjects', label='K12 Subjects'),
FieldPanel('is_ap'),
FieldPanel('description', classname="full"),
DocumentChooserPanel('cover'),
Expand Down Expand Up @@ -744,6 +764,7 @@ def get_community_resource_feature_link_url(self):
APIField('salesforce_book_id'),
APIField('book_subjects'),
APIField('book_categories'),
APIField('k12book_subjects'),
APIField('is_ap'),
APIField('description'),
APIField('cover_url'),
Expand Down Expand Up @@ -834,6 +855,12 @@ def subjects(self):
subject_list.append(subject.subject_name)
return subject_list

def k12subjects(self):
k12subject_list = []
for k12subject in self.k12book_subjects.all():
k12subject_list.append(k12subject.subject_name)
return k12subject_list

@property
def subject_categories(self):
category_list = []
Expand Down
10 changes: 9 additions & 1 deletion pages/custom_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class CardImageBlock(blocks.StructBlock):
class Meta:
icon = 'image'


class StoryBlock(blocks.StructBlock):
image = APIImageChooserBlock(required=False)
story_text = blocks.TextBlock(required=False)
Expand Down Expand Up @@ -133,7 +132,16 @@ class InfoBoxBlock(blocks.StructBlock):
class Meta:
icon = 'placeholder'

class TestimonialBlock(blocks.StructBlock):
author_icon = APIImageChooserBlock(required=False)
author = blocks.CharBlock(required=True)
testimonial = blocks.RichTextBlock(required=True)

class Meta:
author_icon = 'image'
max_num = 4


class AllyLogoBlock(blocks.StructBlock):
image = APIImageChooserBlock()

Expand Down
Loading

0 comments on commit 3a4a4e3

Please sign in to comment.