#20569: Add cleaned_form to supersede cleaned_data -------------------------------+-------------------- Reporter: anonymous | Owner: nobody Type: Uncategorized | Status: new Component: Forms | Version: master Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 1 | UI/UX: 0 -------------------------------+-------------------- The cleaned_data dictionary is not very elegant:
{{{ if form.is_valid(): subject = form.cleaned_data['subject'] }}} First, is_valid needs to be called, and it is not obvious from the naming of the method and the fields that this is what populates cleaned_data. Second, the ORM gives us regular fields rather than dictionary entries accessed as strings. I suggest a cleaner interface (first iteration): {{{ if form.is_valid(): form.cleaning() subject = form.subject # to switch back to the original, use form.cleaning(False) }}} The fields could be defined as getter methods (@property), but since the form is a custom user class, it may be easier to just swap the values upon calling cleaning. cleaning(False) is probably a rare operation. The advantage of this is that client code is less likely to access the original data in lieu of the cleaned data. Also, is_valid does not suggest that anything but a check occurs. To avoid the extra call to cleaning, one could do this: {{{ if form.validate(): subject = form.subject # to switch back to the original, use form.cleaning(False) }}} The change would be backward compatible, as is_valid() and .cleaned_data work as before. -- Ticket URL: <https://code.djangoproject.com/ticket/20569> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.3090c74746a0ca44ccdd4c4965b5064b%40djangoproject.com?hl=en. For more options, visit https://groups.google.com/groups/opt_out.