Implement chapters / content blocks graphql interface
This commit is contained in:
parent
640af9b047
commit
4a3ffd9eac
|
|
@ -24,6 +24,23 @@ query ModulesQuery($slug: String!) {
|
|||
}
|
||||
}
|
||||
}
|
||||
chapters {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
contentBlocks {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
slug
|
||||
title
|
||||
type
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ class Chapter(Page):
|
|||
parent_page_types = ['book.Module']
|
||||
subpage_types = ['book.ContentBlock']
|
||||
|
||||
def get_child_ids(self):
|
||||
return self.get_children().values_list('id', flat=True)
|
||||
|
||||
@classmethod
|
||||
def get_module_chapters(cls, module):
|
||||
return cls.objects.filter(id__in=module.get_child_ids()).live()
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ class Module(Page):
|
|||
parent_page_types = ['book.Topic']
|
||||
subpage_types = ['book.Chapter']
|
||||
|
||||
def get_child_ids(self):
|
||||
return self.get_children().values_list('id', flat=True)
|
||||
|
||||
@classmethod
|
||||
def get_topic_modules(cls, topic):
|
||||
return cls.objects.filter(id__in=topic.get_child_ids()).live()
|
||||
|
|
|
|||
|
|
@ -3,11 +3,41 @@ from graphene import relay
|
|||
from graphene_django import DjangoObjectType
|
||||
from graphene_django.filter import DjangoFilterConnectionField
|
||||
|
||||
from .models import Book, Topic, Module
|
||||
from .models import Book, Topic, Module, Chapter, ContentBlock
|
||||
|
||||
|
||||
class ContentBlockNode(DjangoObjectType):
|
||||
class Meta:
|
||||
model = ContentBlock
|
||||
only_fields = [
|
||||
'slug', 'title', 'type'
|
||||
]
|
||||
filter_fields = [
|
||||
'slug', 'title',
|
||||
]
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
|
||||
class ChapterNode(DjangoObjectType):
|
||||
content_blocks = DjangoFilterConnectionField(ContentBlockNode)
|
||||
|
||||
class Meta:
|
||||
model = Chapter
|
||||
only_fields = [
|
||||
'slug', 'title',
|
||||
]
|
||||
filter_fields = [
|
||||
'slug', 'title',
|
||||
]
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
def resolve_content_blocks(self, *args, **kwargs):
|
||||
return ContentBlock.get_chapter_content_blocks(self)
|
||||
|
||||
|
||||
class ModuleNode(DjangoObjectType):
|
||||
pk = graphene.Int()
|
||||
chapters = DjangoFilterConnectionField(ChapterNode)
|
||||
hero_image = graphene.String()
|
||||
|
||||
class Meta:
|
||||
|
|
@ -28,6 +58,9 @@ class ModuleNode(DjangoObjectType):
|
|||
if self.hero_image:
|
||||
return self.hero_image.file.url
|
||||
|
||||
def resolve_chapters(self, *args, **kwargs):
|
||||
return Chapter.get_module_chapters(self)
|
||||
|
||||
|
||||
class TopicNode(DjangoObjectType):
|
||||
pk = graphene.Int()
|
||||
|
|
|
|||
Loading…
Reference in New Issue