Skip to content

Commit

Permalink
[BUGFIX] Reset self.object on form_invalid #496
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Apr 16, 2024
2 parents 92493c0 + fd1eda4 commit 600732c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions promgen/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,12 +773,13 @@ def get_context_data(self, **kwargs):
return context

def form_invalid(self, **kwargs):
"""If the form is invalid, render the invalid form."""
# Typically self.form will get a copy of self.object stored as self.form.instance, but if
# we have an invalid form, we want to ensure a clean copy of self.object when rendering the
# page (and we can leave the dirty copy as part of self.form.instance).
self.object = self.get_object()
return self.render_to_response(self.get_context_data(**kwargs))

def post(self, request, *args, **kwargs):
self.object = self.get_object()

# Save a copy of our forms into a context var that we can use
# to re-render our form properly in case of errors
context = {}
Expand Down

0 comments on commit 600732c

Please sign in to comment.