Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Reset self.object on form_invalid #496

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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