28 lines
923 B
Python
28 lines
923 B
Python
import graphene
|
|
from graphene import relay
|
|
|
|
from api.utils import get_object
|
|
from books.models import Module
|
|
from books.models.snapshot import Snapshot
|
|
from books.schema.nodes import SnapshotNode
|
|
from users.models import SchoolClass
|
|
|
|
|
|
class CreateSnapshot(relay.ClientIDMutation):
|
|
class Input:
|
|
module = graphene.ID(required=True)
|
|
selected_class = graphene.ID(required=True)
|
|
|
|
snapshot = graphene.Field(SnapshotNode)
|
|
success = graphene.Boolean()
|
|
|
|
@classmethod
|
|
def mutate_and_get_payload(cls, root, info, **args):
|
|
module_id = args.get('module')
|
|
module = get_object(Module, module_id)
|
|
user = info.context.user
|
|
selected_class_id = args.get('selected_class')
|
|
selected_class = get_object(SchoolClass, selected_class_id)
|
|
snapshot = Snapshot.objects.create_snapshot(module, selected_class, user)
|
|
return cls(snapshot=snapshot, success=True)
|