Add new chapter visibility properties to model and schema
This commit is contained in:
parent
1f3b6fe40d
commit
8d9761b3ef
|
|
@ -8,7 +8,7 @@ from api import graphene_wagtail # Keep this import exactly here, it's necessar
|
||||||
from assignments.schema.mutations import AssignmentMutations
|
from assignments.schema.mutations import AssignmentMutations
|
||||||
from assignments.schema.queries import AssignmentsQuery, StudentSubmissionQuery
|
from assignments.schema.queries import AssignmentsQuery, StudentSubmissionQuery
|
||||||
from basicknowledge.queries import BasicKnowledgeQuery
|
from basicknowledge.queries import BasicKnowledgeQuery
|
||||||
from books.schema.mutations.main import BookMutations
|
from books.schema.mutations import BookMutations
|
||||||
from books.schema.queries import BookQuery
|
from books.schema.queries import BookQuery
|
||||||
from core.schema.mutations.coupon import CouponMutations
|
from core.schema.mutations.coupon import CouponMutations
|
||||||
from core.schema.mutations.main import CoreMutations
|
from core.schema.mutations.main import CoreMutations
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 2.2.17 on 2021-02-18 13:36
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0025_auto_20210126_1343'),
|
||||||
|
('books', '0023_auto_20200707_1501'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='chapter',
|
||||||
|
name='description_hidden_for',
|
||||||
|
field=models.ManyToManyField(related_name='hidden_chapter_descriptions', to='users.SchoolClass'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='chapter',
|
||||||
|
name='title_hidden_for',
|
||||||
|
field=models.ManyToManyField(related_name='hidden_chapter_titles', to='users.SchoolClass'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -4,6 +4,7 @@ from django.db import models
|
||||||
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList
|
from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList
|
||||||
|
|
||||||
from core.wagtail_utils import StrictHierarchyPage
|
from core.wagtail_utils import StrictHierarchyPage
|
||||||
|
from users.models import SchoolClass
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -34,3 +35,5 @@ class Chapter(StrictHierarchyPage):
|
||||||
parent_page_types = ['books.Module']
|
parent_page_types = ['books.Module']
|
||||||
subpage_types = ['books.ContentBlock']
|
subpage_types = ['books.ContentBlock']
|
||||||
|
|
||||||
|
title_hidden_for = models.ManyToManyField(SchoolClass, related_name='hidden_chapter_titles')
|
||||||
|
description_hidden_for = models.ManyToManyField(SchoolClass, related_name='hidden_chapter_descriptions')
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
# -*- coding: utf-8 -*-
|
from books.schema.mutations.chapter import UpdateChapterVisibility
|
||||||
#
|
from books.schema.mutations.contentblock import MutateContentBlock, AddContentBlock, DeleteContentBlock
|
||||||
# Iterativ GmbH
|
from books.schema.mutations.module import UpdateSolutionVisibility, UpdateLastModule, UpdateLastTopic
|
||||||
# http://www.iterativ.ch/
|
|
||||||
#
|
|
||||||
# Copyright (c) 2018 Iterativ GmbH. All rights reserved.
|
class BookMutations(object):
|
||||||
#
|
mutate_content_block = MutateContentBlock.Field()
|
||||||
# Created on 25.09.18
|
add_content_block = AddContentBlock.Field()
|
||||||
# @author: Ramon Wenger <ramon.wenger@iterativ.ch>
|
delete_content_block = DeleteContentBlock.Field()
|
||||||
|
update_solution_visibility = UpdateSolutionVisibility.Field()
|
||||||
|
update_last_module = UpdateLastModule.Field()
|
||||||
|
update_last_topic = UpdateLastTopic.Field()
|
||||||
|
update_chapter_visibility = UpdateChapterVisibility.Field()
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
import graphene
|
||||||
|
from graphene import relay
|
||||||
|
|
||||||
|
from api.utils import get_object
|
||||||
|
from books.models import Chapter
|
||||||
|
from books.schema.inputs import UserGroupBlockVisibility
|
||||||
|
from books.schema.queries import ChapterNode
|
||||||
|
from users.models import SchoolClass
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateChapterVisibility(relay.ClientIDMutation):
|
||||||
|
class Input:
|
||||||
|
id = graphene.ID(required=True)
|
||||||
|
visibility = graphene.List(UserGroupBlockVisibility)
|
||||||
|
type = graphene.String(required=True)
|
||||||
|
|
||||||
|
chapter = graphene.Field(ChapterNode)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||||
|
id_param = kwargs['id']
|
||||||
|
visibility_list = kwargs.get('visibility', None)
|
||||||
|
mutation_type = kwargs['type']
|
||||||
|
|
||||||
|
chapter = get_object(Chapter, id_param)
|
||||||
|
|
||||||
|
if visibility_list is not None:
|
||||||
|
for v in visibility_list:
|
||||||
|
school_class = get_object(SchoolClass, v.school_class_id)
|
||||||
|
if v.hidden:
|
||||||
|
if mutation_type == 'chapter-title':
|
||||||
|
chapter.title_hidden_for.add(school_class)
|
||||||
|
else:
|
||||||
|
chapter.description_hidden_for.add(school_class)
|
||||||
|
else:
|
||||||
|
if mutation_type == 'chapter-title':
|
||||||
|
chapter.title_hidden_for.remove(school_class)
|
||||||
|
else:
|
||||||
|
chapter.description_hidden_for.remove(school_class)
|
||||||
|
|
||||||
|
chapter.save()
|
||||||
|
|
||||||
|
return cls(chapter=chapter)
|
||||||
|
|
@ -10,7 +10,6 @@ from books.models import ContentBlock, Chapter, SchoolClass
|
||||||
from books.schema.inputs import ContentBlockInput
|
from books.schema.inputs import ContentBlockInput
|
||||||
from books.schema.queries import ContentBlockNode
|
from books.schema.queries import ContentBlockNode
|
||||||
from core.utils import set_hidden_for, set_visible_for
|
from core.utils import set_hidden_for, set_visible_for
|
||||||
from notes.models import ContentBlockBookmark
|
|
||||||
from .utils import handle_content_block, set_user_defined_block_type
|
from .utils import handle_content_block, set_user_defined_block_type
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,7 +18,6 @@ class MutateContentBlock(relay.ClientIDMutation):
|
||||||
id = graphene.ID(required=True)
|
id = graphene.ID(required=True)
|
||||||
content_block = graphene.Argument(ContentBlockInput)
|
content_block = graphene.Argument(ContentBlockInput)
|
||||||
|
|
||||||
errors = graphene.List(graphene.String)
|
|
||||||
content_block = graphene.Field(ContentBlockNode)
|
content_block = graphene.Field(ContentBlockNode)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -52,17 +50,16 @@ class MutateContentBlock(relay.ClientIDMutation):
|
||||||
if contents is not None:
|
if contents is not None:
|
||||||
content_block.contents = json.dumps([handle_content_block(c, info.context, module) for c in contents])
|
content_block.contents = json.dumps([handle_content_block(c, info.context, module) for c in contents])
|
||||||
|
|
||||||
|
|
||||||
content_block.save()
|
content_block.save()
|
||||||
|
|
||||||
return cls(content_block=content_block)
|
return cls(content_block=content_block)
|
||||||
|
|
||||||
except ValidationError as e:
|
except ValidationError as e:
|
||||||
errors = get_errors(e)
|
errors = get_errors(e)
|
||||||
|
raise errors
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
errors = ['Error: {}'.format(e)]
|
errors = ['Error: {}'.format(e)]
|
||||||
|
raise errors
|
||||||
return cls(content_block=None, errors=errors)
|
|
||||||
|
|
||||||
|
|
||||||
class AddContentBlock(relay.ClientIDMutation):
|
class AddContentBlock(relay.ClientIDMutation):
|
||||||
|
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
from books.schema.mutations.contentblock import MutateContentBlock, AddContentBlock, DeleteContentBlock
|
|
||||||
from books.schema.mutations.module import UpdateSolutionVisibility, UpdateLastModule, UpdateLastTopic
|
|
||||||
|
|
||||||
|
|
||||||
class BookMutations(object):
|
|
||||||
mutate_content_block = MutateContentBlock.Field()
|
|
||||||
add_content_block = AddContentBlock.Field()
|
|
||||||
delete_content_block = DeleteContentBlock.Field()
|
|
||||||
update_solution_visibility = UpdateSolutionVisibility.Field()
|
|
||||||
update_last_module = UpdateLastModule.Field()
|
|
||||||
update_last_topic = UpdateLastTopic.Field()
|
|
||||||
|
|
@ -77,7 +77,7 @@ class ChapterNode(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Chapter
|
model = Chapter
|
||||||
only_fields = [
|
only_fields = [
|
||||||
'slug', 'title', 'description',
|
'slug', 'title', 'description', 'title_hidden_for', 'description_hidden_for'
|
||||||
]
|
]
|
||||||
filter_fields = [
|
filter_fields = [
|
||||||
'slug', 'title',
|
'slug', 'title',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue