Use slug to identify instruments on server

This commit is contained in:
Ramon Wenger 2020-01-16 09:48:38 +01:00
parent ef6711965f
commit 5f6817ebbe
2 changed files with 21 additions and 11 deletions

View File

@ -4,7 +4,8 @@ from graphene import InputObjectType
class AddNoteArgument(InputObjectType):
content = graphene.UUID()
content_block = graphene.ID()
block = graphene.String()
type = graphene.String()
parent = graphene.ID()
text = graphene.String(required=True)

View File

@ -59,18 +59,27 @@ class AddNote(relay.ClientIDMutation):
note = kwargs.get('note')
content_uuid = note.get('content', '')
content_block_id = note.get('content_block', '')
content_block_id = note.get('block', '')
parent = note.get('parent')
text = note.get('text')
if content_uuid != '':
content_block = get_object(ContentBlock, content_block_id)
type = note.get('type')
if type == 'ContentBlockNode':
content_block = get_object(ContentBlock, content_block_id)
bookmark = ContentBlockBookmark.objects.get(
content_block=content_block,
uuid=content_uuid,
user=user
)
bookmark = ContentBlockBookmark.objects.get(
content_block=content_block,
uuid=content_uuid,
user=user
)
else:
instrument = BasicKnowledge.objects.get(slug=content_block_id)
bookmark = InstrumentBookmark.objects.get(
instrument=instrument,
uuid=content_uuid,
user=user
)
else:
type, id = from_global_id(parent)
if type == 'ModuleNode':
@ -176,7 +185,7 @@ class UpdateModuleBookmark(relay.ClientIDMutation):
class UpdateInstrumentBookmark(relay.ClientIDMutation):
class Input:
uuid = graphene.UUID(required=True)
instrument = graphene.ID(required=True)
instrument = graphene.String(required=True)
bookmarked = graphene.Boolean(required=True)
success = graphene.Boolean()
@ -184,11 +193,11 @@ class UpdateInstrumentBookmark(relay.ClientIDMutation):
@classmethod
def mutate_and_get_payload(cls, root, info, **kwargs):
user = info.context.user
instrument_id = kwargs.get('instrument')
instrument_slug = kwargs.get('instrument')
uuid = kwargs.get('uuid')
bookmarked = kwargs.get('bookmarked')
instrument = get_object(BasicKnowledge, instrument_id)
instrument = BasicKnowledge.objects.get(slug=instrument_slug)
if bookmarked:
InstrumentBookmark.objects.create(