Am 17.09.2007 um 04:17 schrieb Malcolm Tredinnick: > On Mon, 2007-09-17 at 00:23 +0200, Christopher Lenz wrote: >> Hey all, >> >> I've created a ticket which has been closed as wontfix, and was told >> to bring it here. So here I am. >> >> <http://code.djangoproject.com/ticket/5153> > > I'm somewhere between -0 and -1 on this, for a couple of reasons. I > don't like the design and you can achieve the same functionality > without > any changes to core. Explanations below... > > [...] >> Now, that use case may sound crazy to you (I don't know why it would, >> but hey). But the point is that there is currently NO WAY to do this >> with newforms. Honestly, the design of newforms.Form.clean(), where >> it deletes its own "cleaned_data" attribute as soon as there's a >> single validation error, is totally backwards and unpythonic. There >> should be *some* way to get at the cleaned_data values, even if some >> of the fields failed to validate. > > If that was how the code worked, you would have a point. However, > Form.full_clean() fills cleaned_data with the normalised forms of any > fields that validated and puts any errors into the internal error > list. > So fields that are correct *do* appear in cleaned_data and it is not > erased when an error is encountered.
Um, yes they are erased: <http://code.djangoproject.com/browser/django/trunk/django/ newforms/forms.py#L205> Am I missing something? > Reading your patch, it looks like you are actually going through > form_for_model or form_for_instance, since your real data flow changes > are in newforms/models.py. Since saving data into models absolutely > requires valid data, being able to disable data validation there would > be illogical. Saving data to the database should enforce valid data, simply populating a model instance from forms data doesn't really need to. It should by the default, sure. > I also don't like the change to disable validation in > Form.full_clean(), > because that makes it kind of a no-op: cleaning is all about > validation > and normalisation. Normalisation has to happen after or in parallel > with > validation, otherwise the normalisation code would have to be prepared > to handle every possible input format under the sun, instead of > just the > valid types. So once you disable validation, normalisation also > doesn't > occur and there's nothing for cleaning to do. We'd be adding an extra > code path in a few places that has be maintained and kept correct > in the > future and it's only purpose is to subvert the whole cleaning process. > Feels less neat than it should be to me. "Subvert the whole cleaning process"? No, the point is to be able to get the results from the cleaning process even when some validation fails. That may mean that cleaned_data is empty, or that fields are missing, etc. That doesn't matter, I can check form.is_valid() or form.errors to check whether the data is valid, I just want a way to still get at the data that's available so far! Seriously, this shouldn't require any of the workarounds you describe. Cheers, Chris -- Christopher Lenz cmlenz at gmx.de http://www.cmlenz.net/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---
