Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
#6845 - model validation status
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Honza Král  
View profile  
 More options Oct 14 2008, 9:13 am
From: "Honza Král" <honza.k...@gmail.com>
Date: Tue, 14 Oct 2008 06:13:22 -0700
Local: Tues, Oct 14 2008 9:13 am
Subject: #6845 - model validation status
Hi,
I took a great email from Gary Wilson to get me started on the status structure.

Some of the core design decisions were finalised by Jacob, Malcolm
(please scream if I have misunderstood or don't remember things
correctly) and me at DjangoCon.

Honza Král
E-Mail: Honza.K...@gmail.com
ICQ#:   107471613
Phone:  +420 606 678585

* The ValidationError class has moved from forms.utils to
django.core.exceptions now that it is used for more than just forms.
ErrorList has been kept in forms.utils

validators
==========

not yet implemented - talking about plans here

* New validators (replacements for many, but not all of the old validators)
have been put in ``django.core.validators``
* the new validator is a function like:

def validate_something( value, all_values={}, instance=None ):
  if i_dont_like( value ):
    raise ValidationError( 'I dont like %r' % value,
error_code=validators.SOME_CODE )

the error_code can be used later in Forms to look up custom error messages.

django.db.models.Model class
============================

 * validate_unique has been moved here from ModelForm

 * clean and validate methods were added, the idea is that any
__validation__ should never alter the data, that's why the top-level
function that can result in data change is clean() and not validate()

    * clean() calls clean() on individual fields and then calls
validate(), ValidationError with message_dict containing the errors is
raised when errors occur
    * validate() calls validate_unique() and is a hook to add custom
instance-wide validation (just raise ValidationError from it)

 * no validate_FIELD or clean_FIELD hooks on models
 * validate is run even if some errors occur on the fields' clean() methods

Model fields (django.db.models.fields)
======================================
 * clean and validate methods were added, see Model for function

Form Fields (django.forms.fields)
=================================

 * form fields haven't been changed yet, I will probably try and do
the same thinng the old patch did:

   * The to_python() method remains and a validate() method have been added.
   Fields have had their clean() methods split into to_python() and validate()
   methods.

  * clean() now calls to_python() then validate().

django.forms.forms.BaseForm class
=================================

 * no changes here either, so far. Will probably also try and do:

   * Form gets a new validate() method, which is meant to replace clean(), and
    full_clean() now looks for validate_<field> methods, which are meant to
    replace clean_<field> methods.  full_clean() also uses the Form.validate()
    instead of Form.clean() to set the cleaned_data.

    - The validate_<field> methods are passed the Field.clean()'ed value (yea
   for fixing #3896).

django.forms.models.BaseModelForm class
=======================================
 * save_instance has been split into two functions:
   * make_instance(form, instance, fields=None, exclude=None) which
return unsaved instance with populated fields
   * save_maked_instance(form, instance, fields=None, commit=True,
fail_message='saved') which saves the populated instance (and it's m2m
data)
  save_instance remains and calls the two new functions

 * in it's clean() method constructs the instance with make_instance,
then runs validation on it

 * the validate_unique method has been moved to Model

 * the form's save() method only calls save_maked_instance

 django.forms.models.BaseModelFormset class
 ===========================================

 * calls form.save() in save_new and save_existing

known Issues
=========================

 * InlineFormSet.save_as_new is broken

unknown Issues
==========================
 * I am fairly sure there are many since I only wrote minimal tests

I would appreciate any feedback on this, especially on:
 should we change the current Form validation? - split to_python and
validate, etc..
 how big an effort should we make to get all the validation to one
place - the validators (ie remove the logic from FormFields and just
have them call the validators where possible)
 testing - anybody willing to write tests and/or have a piece of code
that I broke, please contact me


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »