Re: ModelForm validation - a better way?

2011-04-29 Thread legutierr
> For reference, here's where we'd be in that case (I still prefer the > context manager over the idea of two separate calls to something named > "validate"): > > def my_view(request): >     form = MyModelForm(request.POST or None) >     try: >         with form.validate(tweak=True) as obj: >    

Re: ModelForm validation - a better way?

2011-04-29 Thread Carl Meyer
On 04/29/2011 10:02 AM, Yishai Beeri wrote: > Of course, cleanup need not be simplistic. In fact, I think the common > coder would never expect a CM to actually save an object on __exit__ - > and will be surprised by the proposed behavior. Could be - the name "finish()" was intended to give the

Re: ModelForm validation - a better way?

2011-04-29 Thread Yishai Beeri
Hi Carl, On Fri, 29 Apr 2011 17:42:32 +0300, Carl Meyer wrote: Hi Yishai, On 04/29/2011 08:53 AM, Yishai Beeri wrote: First, the logic tied into the context manager does not match the idiomatic use of context managers in Python. One expects a context manager to "clean up" on exit, rather tha

Re: ModelForm validation - a better way?

2011-04-29 Thread Carl Meyer
Hi Johannes, On 04/29/2011 09:02 AM, Johannes Dollinger wrote: > Here's my take on the API: > > def my_view(request): > form = MyModelForm(request.POST or None) > try: > with form.finish() as obj: > obj.user = request.user > return redirect(obj) > except Va

Re: ModelForm validation - a better way?

2011-04-29 Thread Carl Meyer
Hi Yishai, On 04/29/2011 08:53 AM, Yishai Beeri wrote: > First, the logic tied into the context manager does not match the > idiomatic use of context managers in Python. One expects a context > manager to "clean up" on exit, rather than *save* a new object. I'd argue it's not totally off base. W

Re: ModelForm validation - a better way?

2011-04-29 Thread Johannes Dollinger
Am 29.04.2011 um 04:13 schrieb Carl Meyer: > Hi all, > > We have a number of tickets open (at least #12028, #13249, #13091, > #15326, and #15860 -- #13091 is the active one) reporting problems with > unique_together constraints in our attempts to validate arbitrary > partial models, when validat

Re: ModelForm validation - a better way?

2011-04-29 Thread Yishai Beeri
Without really suggesting a better alternative, I'd like to highlight two problems I see with this approach: First, the logic tied into the context manager does not match the idiomatic use of context managers in Python. One expects a context manager to "clean up" on exit, rather than *save*

Re: ModelForm validation - a better way?

2011-04-29 Thread Carl Meyer
Hi Lior, thanks for commenting. On 04/29/2011 12:16 AM, Lior Sion wrote: > I think that forcing programmers to remember quite a long process of > for validation each time is a wrong approach, especially if only done > to support backward code that behaves in "unnatural" way. I'm not sure why you

Re: ModelForm validation - a better way?

2011-04-29 Thread Lior Sion
Carl, I also ran into this issue and opened one of the tickets about it, so I do have an interest in it. I think that forcing programmers to remember quite a long process of for validation each time is a wrong approach, especially if only done to support backward code that behaves in "unnatural"

Re: ModelForm validation - a better way?

2011-04-28 Thread Alex Gaynor
On Thu, Apr 28, 2011 at 10:13 PM, Carl Meyer wrote: > Hi all, > > We have a number of tickets open (at least #12028, #13249, #13091, > #15326, and #15860 -- #13091 is the active one) reporting problems with > unique_together constraints in our attempts to validate arbitrary > partial models, when

ModelForm validation - a better way?

2011-04-28 Thread Carl Meyer
Hi all, We have a number of tickets open (at least #12028, #13249, #13091, #15326, and #15860 -- #13091 is the active one) reporting problems with unique_together constraints in our attempts to validate arbitrary partial models, when validating a ModelForm with some fields excluded. Eduardo Gutie