Re: Django code patterns

2012-02-09 Thread Michael Nacharov
09.02.2012 20:01, Rune Kaagaard пишет: Maybe something like the following untested code: def submit_if_any(a, b, conditions, submit_func): has_any = False for condition in conditions: if condition(a, b):

Re: Django code patterns

2012-02-09 Thread Rune Kaagaard
Maybe something like the following untested code: def submit_if_any(a, b, conditions, submit_func): has_any = False for condition in conditions: if condition(a, b): has_any = True

Re: Django code patterns

2012-02-09 Thread Rune Kaagaard
> Why are you only saving if you've made a change? (Just make sure you > aren't optimizing prematurely.) I have a lot of signals going round, so I wan't to keep saves to a minimum. But nothing bad would happen if I always saved in this case. Thus the code would look: resource.user.email = requ

Re: Django code patterns

2012-02-09 Thread bruno desthuilliers
On Feb 9, 9:41 am, Rune Kaagaard wrote: > Dear django-users > > I keep doing patterns like: > >         has_changed = False >         if resource.user.email != request.POST['email']: >             resource.user.email = request.POST['email'] >             has_changed = True >         if resource.us

Re: Django code patterns

2012-02-09 Thread Jerome Baum
On Feb 9, 9:41 am, Rune Kaagaard wrote: >         has_changed = False >         if resource.user.email != request.POST['email']: >             resource.user.email = request.POST['email'] >             has_changed = True >         if resource.user.is_active != request.POST['is_active']: >          

Django code patterns

2012-02-09 Thread Rune Kaagaard
Dear django-users I keep doing patterns like: has_changed = False if resource.user.email != request.POST['email']: resource.user.email = request.POST['email'] has_changed = True if resource.user.is_active != request.POST['is_active']: re