Skip to content

Commit f5083cb

Browse files
author
Grant McConnaughey
committed
Change form valid method names
1 parent 5072464 commit f5083cb

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

docs/form-mutations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Form validation
6060

6161
Form mutations will call ``is_valid()`` on your forms.
6262

63-
If the form is valid then ``perform_mutate(form, info)`` is called on the mutation. Override this method to change how
63+
If the form is valid then ``form_valid(form, info)`` is called on the mutation. Override this method to change how
6464
the form is saved or to return a different Graphene object type.
6565

6666
If the form is *not* valid then a list of errors will be returned. These errors have two fields: ``field``, a string

graphene_django/forms/mutation.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ def mutate(cls, root, args, context, info):
6464
form = cls.get_form(root, args, context, info)
6565

6666
if form.is_valid():
67-
return cls.perform_mutate(form, info)
67+
return cls.form_valid(form, info)
6868
else:
69-
errors = [
70-
ErrorType(field=key, messages=value)
71-
for key, value in form.errors.items()
72-
]
73-
return cls(errors=errors)
69+
return cls.form_invalid(form, info)
7470

7571
@classmethod
76-
def perform_mutate(cls, form, info):
72+
def form_valid(cls, form, info):
7773
form.save()
7874
return cls(errors=[])
7975

76+
@classmethod
77+
def form_invalid(cls, form, info):
78+
errors = [
79+
ErrorType(field=key, messages=value)
80+
for key, value in form.errors.items()
81+
]
82+
return cls(errors=errors)
83+
8084
@classmethod
8185
def get_form(cls, root, args, context, info):
8286
form_data = args.get(cls._meta.input_field_name)
@@ -151,7 +155,7 @@ class ModelFormMutation(six.with_metaclass(ModelFormMutationMeta, BaseFormMutati
151155
errors = graphene.List(ErrorType)
152156

153157
@classmethod
154-
def perform_mutate(cls, form, info):
158+
def form_valid(cls, form, info):
155159
obj = form.save()
156160
kwargs = {cls.return_field_name: obj}
157161
return cls(errors=[], **kwargs)

0 commit comments

Comments
 (0)