Add path property to contentblock

This commit is contained in:
Ramon Wenger 2023-02-06 14:30:41 +01:00
parent afefc7f31e
commit af4f19720b
4 changed files with 14 additions and 3 deletions

View File

@ -36,11 +36,12 @@ from core.wagtail_utils import StrictHierarchyPage
from notes.models import ContentBlockBookmark from notes.models import ContentBlockBookmark
from surveys.models import Survey from surveys.models import Survey
from users.models import SchoolClass, User from users.models import SchoolClass, User
from core.mixins import GraphqlNodeMixin
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class ContentBlock(StrictHierarchyPage): class ContentBlock(StrictHierarchyPage, GraphqlNodeMixin):
class Meta: class Meta:
verbose_name = "Inhaltsblock" verbose_name = "Inhaltsblock"
verbose_name_plural = "Inhaltsblöcke" verbose_name_plural = "Inhaltsblöcke"

View File

@ -43,6 +43,7 @@ class ContentBlockNode(DjangoObjectType, HiddenAndVisibleForMixin):
bookmarks = graphene.List(ContentBlockBookmarkNode) bookmarks = graphene.List(ContentBlockBookmarkNode)
original_creator = graphene.Field('users.schema.PublicUserNode') original_creator = graphene.Field('users.schema.PublicUserNode')
instrument_category = graphene.Field(InstrumentCategoryNode) instrument_category = graphene.Field(InstrumentCategoryNode)
path = graphene.String()
class Meta: class Meta:
model = ContentBlock model = ContentBlock
@ -99,11 +100,17 @@ class ContentBlockNode(DjangoObjectType, HiddenAndVisibleForMixin):
return category return category
return None return None
@staticmethod
def resolve_path(root: ContentBlock, info, **kwargs):
module = root.get_parent().get_parent()
return f'module/{module.slug}#{root.graphql_id}'
def process_module_room_slug_block(content): def process_module_room_slug_block(content):
if content['type'] == 'module_room_slug': if content['type'] == 'module_room_slug':
try: try:
module_room_slug = ModuleRoomSlug.objects.get(title=content['value']['title']) module_room_slug = ModuleRoomSlug.objects.get(
title=content['value']['title'])
content['value'] = { content['value'] = {
'title': content['value']['title'], 'title': content['value']['title'],
'slug': module_room_slug.slug 'slug': module_room_slug.slug

View File

@ -15,7 +15,8 @@ logger = get_logger(__name__)
class BookQuery(object): class BookQuery(object):
node = relay.Node.Field() node = relay.Node.Field()
topic = graphene.Field(TopicOr404Node, slug=graphene.String()) topic = graphene.Field(TopicOr404Node, slug=graphene.String())
module = graphene.Field(ModuleNode, slug=graphene.String(), id=graphene.ID()) module = graphene.Field(
ModuleNode, slug=graphene.String(), id=graphene.ID())
chapter = relay.Node.Field(ChapterNode) chapter = relay.Node.Field(ChapterNode)
content_block = relay.Node.Field(ContentBlockNode) content_block = relay.Node.Field(ContentBlockNode)
snapshot = relay.Node.Field(SnapshotNode) snapshot = relay.Node.Field(SnapshotNode)

View File

@ -300,6 +300,7 @@ type ContentBlockNode implements Node & ContentBlockInterface {
bookmarks: [ContentBlockBookmarkNode] bookmarks: [ContentBlockBookmarkNode]
originalCreator: PublicUserNode originalCreator: PublicUserNode
instrumentCategory: InstrumentCategoryNode instrumentCategory: InstrumentCategoryNode
path: String
} }
type ContentBlockNodeConnection { type ContentBlockNodeConnection {
@ -512,6 +513,7 @@ enum InputTypes {
document_block document_block
content_list_item content_list_item
subtitle subtitle
readonly
} }
type InstrumentBookmarkNode implements Node { type InstrumentBookmarkNode implements Node {