Move book schema into a package and files: queries and mutations
This commit is contained in:
parent
12d8d2375c
commit
e007482e46
|
|
@ -0,0 +1,75 @@
|
||||||
|
import graphene
|
||||||
|
|
||||||
|
|
||||||
|
class MutateContentBlock(graphene.relay.ClientIDMutation):
|
||||||
|
class Input:
|
||||||
|
id = None
|
||||||
|
|
||||||
|
title = graphene.String()
|
||||||
|
type = graphene.String()
|
||||||
|
|
||||||
|
module_slug = graphene.String(required=True)
|
||||||
|
# text params
|
||||||
|
# learnings_text = graphene.String()
|
||||||
|
# impact_text = graphene.String()
|
||||||
|
# measurement_text = graphene.String()
|
||||||
|
# measures_text = graphene.String()
|
||||||
|
# time_frame_text = graphene.String()
|
||||||
|
# resources_skills_text = graphene.String()
|
||||||
|
# commitment_support_text = graphene.String()
|
||||||
|
|
||||||
|
# user_module_progress = graphene.Field(UserModuleProgressNode)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def mutate_and_get_payload(cls, *args, **kwargs):
|
||||||
|
# user_module_progress = get_object_or_404(
|
||||||
|
# UserModuleProgress,
|
||||||
|
# user=get_current_user(),
|
||||||
|
# module__slug=kwargs.pop('module_slug')
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# for k, v in kwargs.items():
|
||||||
|
# setattr(user_module_progress, k, v)
|
||||||
|
#
|
||||||
|
# user_module_progress.save()
|
||||||
|
return cls(user_module_progress=user_module_progress)
|
||||||
|
|
||||||
|
|
||||||
|
# class UpdateImage(relay.ClientIDMutation):
|
||||||
|
# class Input:
|
||||||
|
# image = graphene.Argument(ImageUpdateInput)
|
||||||
|
# id = graphene.String(required=True)
|
||||||
|
#
|
||||||
|
# errors = graphene.List(graphene.String)
|
||||||
|
# updated_image = graphene.Field(ImageNode)
|
||||||
|
# tags = graphene.List(TagNode)
|
||||||
|
#
|
||||||
|
# @classmethod
|
||||||
|
# def mutate_and_get_payload(cls, *args, **kwargs):
|
||||||
|
# try:
|
||||||
|
# image_instance = get_object(Image, kwargs['id'])
|
||||||
|
# if image_instance:
|
||||||
|
# image_data = kwargs.get('image')
|
||||||
|
# updated_image = update_create_instance(image_instance, image_data, exception=['id', 'tags'])
|
||||||
|
# tag_slugs = image_data.get('tag_slugs', '')
|
||||||
|
# if tag_slugs is not None:
|
||||||
|
# tag_slugs = [t.strip() for t in tag_slugs.split(',') if t.strip()]
|
||||||
|
# tags = list(Tag.objects.filter(slug__in=tag_slugs))
|
||||||
|
# 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(updated_image=updated_image, tags=Tag.objects.all())
|
||||||
|
# except ValidationError as e:
|
||||||
|
# errors = get_errors(e)
|
||||||
|
# except Exception as e:
|
||||||
|
# errors = ['Error: {}'.format(e)]
|
||||||
|
# else:
|
||||||
|
# errors = ['image not found']
|
||||||
|
#
|
||||||
|
# return cls(updated_image=None, tags=None, errors=errors)
|
||||||
|
|
||||||
|
|
||||||
|
class BookMutations(object):
|
||||||
|
# start_module_progress = StartModuleProgress.Field()
|
||||||
|
# delete_module_progress = DeleteModuleProgress.Field()
|
||||||
|
define_action_plan = MutateContentBlock.Field()
|
||||||
|
|
@ -3,7 +3,7 @@ from graphene import relay
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
|
|
||||||
from .models import Book, Topic, Module, Chapter, ContentBlock
|
from ..models import Book, Topic, Module, Chapter, ContentBlock
|
||||||
|
|
||||||
|
|
||||||
class ContentBlockNodeType(DjangoObjectType):
|
class ContentBlockNodeType(DjangoObjectType):
|
||||||
|
|
@ -121,4 +121,3 @@ class BookQuery(object):
|
||||||
|
|
||||||
def resolve_modules(self, *args, **kwargs):
|
def resolve_modules(self, *args, **kwargs):
|
||||||
return Module.objects.filter(**kwargs).live()
|
return Module.objects.filter(**kwargs).live()
|
||||||
|
|
||||||
|
|
@ -4,12 +4,19 @@ import factory
|
||||||
|
|
||||||
from user.models import UserGroup
|
from user.models import UserGroup
|
||||||
|
|
||||||
|
class_types = ['DA', 'KV', 'INF', 'EE']
|
||||||
|
class_suffix = ['A', 'B', 'C', 'D', 'E']
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: refactor to use a trait synching the year with the infix year
|
||||||
|
# TODO: refactor to have non-overlapping user groups?
|
||||||
|
|
||||||
|
|
||||||
class UserGroupFactory(factory.django.DjangoModelFactory):
|
class UserGroupFactory(factory.django.DjangoModelFactory):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserGroup
|
model = UserGroup
|
||||||
|
|
||||||
name = factory.Sequence(lambda n: 'Klasse {}{}'.format(n+1, random.choice(['a', 'b', 'c'])))
|
name = factory.Sequence(lambda n: '{}{}{}'.format(random.choice(class_types), '18', class_suffix[n % len(class_suffix)]))
|
||||||
year = factory.LazyAttribute(lambda x: random.choice([2017, 2018, 2019]))
|
year = factory.LazyAttribute(lambda x: random.choice([2017, 2018, 2019]))
|
||||||
is_deleted = False
|
is_deleted = False
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue