mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-06-15 02:53:11 +03:00
Change form valid method names
This commit is contained in:
parent
507246468b
commit
f5083cb190
|
@ -60,7 +60,7 @@ Form validation
|
||||||
|
|
||||||
Form mutations will call ``is_valid()`` on your forms.
|
Form mutations will call ``is_valid()`` on your forms.
|
||||||
|
|
||||||
If the form is valid then ``perform_mutate(form, info)`` is called on the mutation. Override this method to change how
|
If the form is valid then ``form_valid(form, info)`` is called on the mutation. Override this method to change how
|
||||||
the form is saved or to return a different Graphene object type.
|
the form is saved or to return a different Graphene object type.
|
||||||
|
|
||||||
If the form is *not* valid then a list of errors will be returned. These errors have two fields: ``field``, a string
|
If the form is *not* valid then a list of errors will be returned. These errors have two fields: ``field``, a string
|
||||||
|
|
|
@ -64,19 +64,23 @@ class BaseFormMutation(graphene.Mutation):
|
||||||
form = cls.get_form(root, args, context, info)
|
form = cls.get_form(root, args, context, info)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
return cls.perform_mutate(form, info)
|
return cls.form_valid(form, info)
|
||||||
else:
|
else:
|
||||||
|
return cls.form_invalid(form, info)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def form_valid(cls, form, info):
|
||||||
|
form.save()
|
||||||
|
return cls(errors=[])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def form_invalid(cls, form, info):
|
||||||
errors = [
|
errors = [
|
||||||
ErrorType(field=key, messages=value)
|
ErrorType(field=key, messages=value)
|
||||||
for key, value in form.errors.items()
|
for key, value in form.errors.items()
|
||||||
]
|
]
|
||||||
return cls(errors=errors)
|
return cls(errors=errors)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def perform_mutate(cls, form, info):
|
|
||||||
form.save()
|
|
||||||
return cls(errors=[])
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_form(cls, root, args, context, info):
|
def get_form(cls, root, args, context, info):
|
||||||
form_data = args.get(cls._meta.input_field_name)
|
form_data = args.get(cls._meta.input_field_name)
|
||||||
|
@ -151,7 +155,7 @@ class ModelFormMutation(six.with_metaclass(ModelFormMutationMeta, BaseFormMutati
|
||||||
errors = graphene.List(ErrorType)
|
errors = graphene.List(ErrorType)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def perform_mutate(cls, form, info):
|
def form_valid(cls, form, info):
|
||||||
obj = form.save()
|
obj = form.save()
|
||||||
kwargs = {cls.return_field_name: obj}
|
kwargs = {cls.return_field_name: obj}
|
||||||
return cls(errors=[], **kwargs)
|
return cls(errors=[], **kwargs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user