-
-
Save mattparrilla/210d05850d16d8053b781af187f61783 to your computer and use it in GitHub Desktop.
Form/FormSet cleaned_data handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cleaned_data = ( | |
[self.process_cleaned_data(form_data) for form_data in cleaned_data] if isinstanced(cleaned_data, list) | |
else self.process_cleaned_data(cleaned_data) | |
) |
So, I almost want to put this array/object login inside of process_cleaned_data
, since it's part of the process.
def process_cleaned_data(self, cleaned_data):
if isinstance(cleaned_data, list):
return [self.process_cleaned_data(form_data) for form_data in cleaned_data
if bool(form_data)]
# Do my cleaned_data processing
return cleaned_data
def post(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
all_forms_valid = all(context[form.__name__].is_valid() for form in self.form_list)
if (all_forms_valid):
# Save forms to session
for form in self.form_list:
cleaned_data = context[form.__name__].cleaned_data
cleaned_data = self.process_cleaned_data(cleaned_data)
request.session[self.session_key][form.__name__] = cleaned_data
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably less readable