Example #1
0
    def mutate(self, _, code_id, result_json_dict: MutableMapping):
        if not isinstance(result_json_dict, Mapping):
            raise GraphQLError('`result_json_dict` must be a mapping of graph ids and result jsons')

        code_wrapper: CodeWrapper = get_wrapper_by_id(CodeWrapper, code_id)

        result_json_models = []
        for key, value in result_json_dict.items():
            graph_wrapper: GraphWrapper = get_wrapper_by_id(GraphWrapper, key)
            json_obj = json.loads(value) if isinstance(value, str) else value
            result_wrapper: ExecResultJsonWrapper = process_model_wrapper(ExecResultJsonWrapper,
                                                                          code=code_wrapper, graph=graph_wrapper,
                                                                          json=json_obj)
            result_json_models.append(result_wrapper.model)

        return UpdateResultJson(success=True, models=result_json_models)
Example #2
0
    def mutate(self, _, id: str, name: str, code: str, tutorial: str):
        tutorial_wrapper = get_wrapper_by_id(TutorialAnchorWrapper, tutorial)

        code_wrapper = process_model_wrapper(CodeWrapper,
                                             id=id, name=name, code=code, tutorial=tutorial_wrapper)

        return UpdateCode(success=True, model=code_wrapper.model)
Example #3
0
    def mutate(self, _, lang: str, content: MutableMapping):
        graph_info_translation_table: Optional[Type[GraphTranslationBase]] = get_graph_info_trans_table(lang.strip())

        if not graph_info_translation_table:
            raise GraphQLError(f'Language {lang} is not supported.')

        content['graph_anchor'] = get_wrapper_by_id(GraphWrapper, content['graph_anchor'])

        graph_info_content_wrapper = process_model_wrapper(GraphTranslationContentWrapper,
                                                           model_class=graph_info_translation_table,
                                                           **content)

        return UpdateGraphInfoContent(success=True, model=graph_info_content_wrapper.model)
Example #4
0
    def mutate(self, _, lang: str, content: MutableMapping):
        translation_table: Optional[Type[TranslationBase]] = get_translation_table(lang.strip())

        if not translation_table:
            raise GraphQLError(f'Language {lang} is no supported.')

        content['authors'] = get_wrappers_by_ids(UserWrapper, content['authors'])
        content['tutorial_anchor'] = get_wrapper_by_id(TutorialAnchorWrapper, content['tutorial_anchor'])

        graph_set: QuerySet[Graph] = Graph.objects.filter(id__in=content.pop('graph_set'))

        with transaction.atomic():
            tutorial_content_wrapper = process_model_wrapper(TutorialTranslationContentWrapper,
                                                             model_class=translation_table, **content)

            tutorial_content_wrapper.model.tutorial_anchor.graph_set.set(graph_set)

            if hasattr(tutorial_content_wrapper.model, 'code'):
                code_list = [tutorial_content_wrapper.model.code]
                _result_json_updater(code_list, graph_set)

        return UpdateTutorialContent(success=True, model=tutorial_content_wrapper.model)
Example #5
0
    def mutate(self, _, lang: str, content: MutableMapping):
        translation_table: Optional[
            Type[TranslationBase]] = get_translation_table(lang.strip())

        if not translation_table:
            raise GraphQLError(f'Language {lang} is no supported.')

        content['authors'] = get_wrappers_by_ids(UserWrapper,
                                                 content['authors'])
        content['tutorial_anchor'] = get_wrapper_by_id(
            TutorialAnchorWrapper, content['tutorial_anchor'])

        graph_set: List[str] = content.pop('graph_set')

        tutorial_content_wrapper = process_model_wrapper(
            TutorialTranslationContentWrapper,
            model_class=translation_table,
            **content)

        tutorial_content_wrapper.model.tutorial_anchor.graph_set.set(
            Graph.objects.filter(id__in=graph_set))

        return UpdateTutorialContent(success=True,
                                     model=tutorial_content_wrapper.model)
Example #6
0
    def mutate(self, info, content_type: Type[AbstractWrapper], id: str):
        wrapper = get_wrapper_by_id(content_type, id)
        wrapper.delete_model()

        return DeleteContent(success=True, )