example mutate hidden/visibility userGroup <-> contentBlock
This commit is contained in:
parent
2ad89ce6ef
commit
4a964b3e81
|
|
@ -0,0 +1,22 @@
|
|||
mutation MutateContentBlock($input: MutateContentBlockInput!) {
|
||||
mutateContentBlock(input: $input) {
|
||||
contentBlock {
|
||||
id
|
||||
title
|
||||
slug
|
||||
}
|
||||
errors
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
# input
|
||||
|
||||
#{"input": {
|
||||
# "id": "Q29udGVudEJsb2NrTm9kZToyMQ==",
|
||||
# "visibility": [{
|
||||
# "userGroupId": "VXNlckdyb3VwTm9kZToy",
|
||||
# "hidden": false
|
||||
# }]
|
||||
#}}
|
||||
|
|
@ -41,9 +41,9 @@
|
|||
"integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg="
|
||||
},
|
||||
"unfetch": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unfetch/-/unfetch-3.0.0.tgz",
|
||||
"integrity": "sha1-jR4FE6Ts0OX/LUGmund3Gq6LZII="
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmjs.org/unfetch/-/unfetch-3.1.1.tgz",
|
||||
"integrity": "sha512-syDl3htvM56w0HC0PTVA5jEEknOCJ3dWgWGDuaEtQUno8ORDCfZQbm12RzfWO3AC3YhWDoP61dlgmo8Z05Y97g=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from graphene import InputObjectType
|
||||
import graphene
|
||||
from graphene import InputObjectType
|
||||
|
||||
|
||||
class InputTypes(graphene.Enum):
|
||||
|
|
@ -28,3 +28,8 @@ class ContentBlockInput(InputObjectType):
|
|||
title = graphene.String(required=True)
|
||||
type = graphene.String()
|
||||
contents = graphene.List(ContentElementInput)
|
||||
|
||||
|
||||
class UserGroupContentBlockVisibility(InputObjectType):
|
||||
user_group_id = graphene.ID(required=True)
|
||||
hidden = graphene.Boolean(required=True)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import json
|
||||
import bleach
|
||||
|
||||
import bleach
|
||||
import graphene
|
||||
from graphene import relay
|
||||
from django.core.exceptions import ValidationError
|
||||
from graphene import relay
|
||||
|
||||
from api.utils import get_object, get_errors
|
||||
from book.models import ContentBlock, Chapter
|
||||
from book.schema.inputs import ContentBlockInput
|
||||
from book.models import ContentBlock, Chapter, UserGroup
|
||||
from book.schema.inputs import ContentBlockInput, UserGroupContentBlockVisibility
|
||||
from book.schema.queries import ContentBlockNode
|
||||
|
||||
|
||||
|
|
@ -55,10 +55,11 @@ def handle_content_blocks(content_data):
|
|||
|
||||
class MutateContentBlock(relay.ClientIDMutation):
|
||||
class Input:
|
||||
id = graphene.ID()
|
||||
id = graphene.ID(required=True)
|
||||
type = graphene.String()
|
||||
title = graphene.String()
|
||||
contents = graphene.String()
|
||||
visibility = graphene.List(UserGroupContentBlockVisibility)
|
||||
|
||||
errors = graphene.List(graphene.String)
|
||||
content_block = graphene.Field(ContentBlockNode)
|
||||
|
|
@ -67,19 +68,31 @@ class MutateContentBlock(relay.ClientIDMutation):
|
|||
def mutate_and_get_payload(cls, *args, **kwargs):
|
||||
try:
|
||||
id_param = kwargs['id']
|
||||
type_param = kwargs['type']
|
||||
title = kwargs['title']
|
||||
contents_data = kwargs['contents']
|
||||
type_param = kwargs.get('type')
|
||||
title = kwargs.get('title')
|
||||
contents_data = kwargs.get('contents')
|
||||
visibility_list = kwargs.get('visibility', [])
|
||||
|
||||
new_content_block = ContentBlock(type=type_param, title=title, contents=contents_data)
|
||||
#new_content_block = ContentBlock(type=type_param, title=title, contents=contents_data)
|
||||
|
||||
content_block = get_object(ContentBlock, id_param)
|
||||
content_block.add_sibling(instance=new_content_block, pos='right')
|
||||
|
||||
for v in visibility_list:
|
||||
user_group = get_object(UserGroup, v.user_group_id)
|
||||
if v.hidden:
|
||||
content_block.hidden_for.add(user_group)
|
||||
else:
|
||||
content_block.hidden_for.remove(user_group)
|
||||
|
||||
content_block.save()
|
||||
|
||||
|
||||
#content_block.add_sibling(instance=new_content_block, pos='right')
|
||||
|
||||
# ContentBlock.objects.get()
|
||||
# cb.add_sibling()
|
||||
|
||||
new_content_block.save()
|
||||
#new_content_block.saveI()
|
||||
|
||||
# image_instance = get_object(Image, kwargs['id'])
|
||||
# if image_instance:
|
||||
|
|
@ -92,7 +105,7 @@ class MutateContentBlock(relay.ClientIDMutation):
|
|||
# tag_slugs = [t for t in tag_slugs if t not in [e.slug for e in tags]]
|
||||
# updated_image.tags.set(*(tags + tag_slugs))
|
||||
|
||||
return cls(content_block=new_content_block)
|
||||
return cls(content_block=content_block)
|
||||
|
||||
except ValidationError as e:
|
||||
errors = get_errors(e)
|
||||
|
|
|
|||
Loading…
Reference in New Issue