Hello everybody, I have been quite productive this weekend so I finally have some code to show. I have been leveraging the hell out of git cherry-pick, git rebase -i and various other questionable dark magic ([0]) to get my previous work in some shape and create a nice set of commits which I was hoping to get into the official SVN repo (my former commits weren't up to the task). The last part didn't work (SVN access, waiting for jacob's magic), so I published my new branch at github ([1]).
What is done/working: ------------------------- * ValidationError has been moved to django.core.exceptions, decoupled from ErrorList and can also accept dicts (there will probably be some refactoring in the future) * we now have hooks on DbFields where you can add your own validation and some basic validation (blank/null, choices, foreign keys) with some basic tests ([2], [3]) * new method on Model that call these methods on fields and also provide a hook for model-wide validation * some code on ModelForms that call these methods and add their errors to the FormFields' * form.instance is constructed in clean() What's broken: ------------------------- * nothing so far - all tests pass (probably just missing tests for stuff I broke :) ) Design decisisons made: ------------------------- * Incomplete forms (forms with excluded required fields) will never validate unless they inject the fields' values or are only used for editting (since the underlying model won't otherwise validate) * flag was added to ModelForm to indicate whether the Form is for edit or add to be able to validate uniqueness (=to know whether or not to do exclude(pk=self.instance.pk) ) * ModelAdmin now save()s the main model before validating the inlines so that they can use the parent FK for their validation (this may break save() with side effects), the model is being deleted if inline validation fails * manipulating cleaned_data in form's save() method won't work - the instance is constructed/updated in clean() Note that stuff that changed is usually reflected in changes to existing tests, that's a good place to start looking. Design decisions comming: ------------------------- * signature of validators - most likely def validate_sthing(value, all_values={}, model_instance=None) * how custom error messages should work - probably will reside on fields and models/forms (for form/model level errors) and will be translated when aggregating individual ValidationError in the model or form based on a dictionary on that field What do I want to work on next: ------------------------- * moving validate_unique from ModelForm to Model (this is for next week hopefully) * introducing validators * more validation * moving validation logic into validators * more tests Questions for the community: ------------------------- I have been toying with the idea of abstract validating object that both Forms and Models would extend. The reason for that is that some of the code is shared and could probably be abstracted into a set of methods. These abstract objects could later be used for example by REST resources or some othe arbitrary code. I will not post my ideas on the API since they don't make any sense yet (if they ever will), just interested in people's opinions. Tip of the day (vim users today): ------------------------- try this in a doctest file: :%s/^>>> .*/& # XXXX/ :%s/XXXX/\=line(".") It will append # line number to every line starting with >>> and thus enable you to see which test fails. That's probably all for this week (it's technically Monday here already anyway), hope I will have some more to show next week. Enjoy 0 - http://dpaste.com/hold/49889/ 1 - http://github.com/HonzaKral/django/tree/gsoc 2 - http://github.com/HonzaKral/django/blob/8ee1fe70c955c037176fa3b8ac0580b41eddbf12/tests/modeltests/validation/tests.py 3 - http://github.com/HonzaKral/django/blob/8ee1fe70c955c037176fa3b8ac0580b41eddbf12/tests/regressiontests/model_fields/tests.py#L135 Honza Král E-Mail: honza.k...@gmail.com Phone: +420 606 678585 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---