def mutate(self, info: ResolveInfo, **kwargs): update_form = UserAttachInfoUpdateForm(kwargs) if update_form.is_valid(): values = update_form.cleaned_data usr = info.context.user assign(usr.attach_info, **values) usr.attach_info.save() return UserAttachInfoUpdate(state=True) else: raise RuntimeError(update_form.errors.as_json())
def mutate(self: None, info: ResolveInfo, **kwargs): update_home_article_form = UpdateHomeArticleForm(kwargs) if update_home_article_form.is_valid(): values = update_home_article_form.cleaned_data article = HomeArticle.objects.get(slug=values.get('slug')) assign(article, **values) article.save() return UpdateHomeArticle(slug=article.slug) else: raise GraphQLError(update_home_article_form.errors.as_json())
def mutate(self, info: ResolveInfo, **kwargs): signup_form = UserSignupForm(kwargs) if signup_form.is_valid(): values = signup_form.cleaned_data usr = User() attach_info = AttachInfo() assign(usr, **values) assign(attach_info, **values) usr.set_password(usr.password) attach_info.save() usr.attach_info = attach_info usr.save() token = get_token(usr) payload = get_payload(token, info.context) return UserRegister(payload=payload, token=token, permission=list(usr.get_all_permissions()), user=usr) else: raise RuntimeError(signup_form.errors.as_json())
def mutate(self, info: ResolveInfo, **kwargs): form = CreateProblemForm(kwargs) if form.is_valid(): values = form.cleaned_data samples = loads(values.get('samples')) prob = Problem() limitation = Limitation() assign(prob, **values) assign(limitation, **values) limitation.save() prob.limitation = limitation prob.save() for each in samples: ProblemSample( input_content=each.get('inputContent'), output_content=each.get('outputContent'), problem=prob ).save() return CreateProblem(slug=prob.slug) else: raise RuntimeError(form.errors.as_json())
def mutate(self, info: ResolveInfo, **kwargs): form = UpdateProblemForm(kwargs) if form.is_valid(): values = form.cleaned_data samples = loads(values.get('samples')) prob = Problem.objects.get(slug=values.get('slug')) assign(prob, **values) assign(prob.limitation, **values) prob.limitation.save() prob.save() ProblemSample.objects.filter(problem=prob).delete() for each in samples: ProblemSample( input_content=each.get('inputContent'), output_content=each.get('outputContent'), problem=prob ).save() # To avoid the slug change, re-fetch the problem object return UpdateProblem(slug=prob.slug) else: raise RuntimeError(form.errors.as_json())