Hi Loic, That's nice! It looks very powerful, saving lines of code and being more clear.
How about: form.add_errors(dictionary) ? Because then we can either add one or more errors at the same time. Wim On Wednesday, 21 August 2013 02:31:07 UTC+2, Simon Litchfield wrote: > > An improvement for sure. Any reason it can't be a little more pythonic, ie > using optional kwargs etc? > > My only concern is in having two ways of achieving the same thing. If the > latter is simpler and more flexible, does this place our entire > ValidationError approach to handling form and model errors in question? > Hmmm. Maybe we can come back to that later :-/ > > > On Tuesday, 20 August 2013 14:11:44 UTC+10, Loic Bistuer wrote: >> >> There is a ticket with a PR to address the issue of targeting specific >> fields when raising errors; I'm awaiting feedback on what should be the >> documented API. >> >> https://code.djangoproject.com/ticket/20867. >> >> This patch enables two patterns: >> >> - Raising ValidationError({'field': 'error'}) from `Form.clean()`. >> >> - Calling Form.add_errors('field', 'error') from anywhere. >> >> The former is actually something that existed for a long time; only it >> couldn't be used from `Form.clean()`. This pattern allows targeting >> specific fields from the `Model` layer (see #16986). >> >> The later has been proposed by @akaariai and @mjtamlyn, it's easier to >> use for the simple cases and it's accessible from outside the form, from a >> view for example. >> >> The current patch only documents the dict construct for `ValidationError` >> since `Form.add_errors` was a private method in my original patch; should >> both be documented or only `Form.add_errors`? >> >> -- >> Loic >> >> On Aug 20, 2013, at 7:58 AM, Simon Litchfield <[email protected]> >> wrote: >> >> > Lack of clean control over field-specific form errors is an issue that >> has been raised and discussed many times over the years, but still the >> solution seems pretty inadequate. We're even directing people hack around >> with _errors and making excuses for it in the documentation. >> > >> https://docs.djangoproject.com/en/dev/ref/forms/validation/#form-subclasses-and-modifying-field-errors >> >> >> -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. For more options, visit https://groups.google.com/groups/opt_out.
