Re: Django code patterns
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 break if has_any: submit_func(a, b) def submit(a, b): a.email = b['email'], a.is_active = b['is_active'] submit_if_any( user, request['POST'], ( lambda a,b: a.email == b['email'], lambda a,b: a.is_active == b['is_active'], ), submit ) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Django code patterns
> 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 = request.POST['email'] resource.user.is_active = request.POST['is_active'] resource.user.save() But I meet the pattern I mentioned a lot in different shapes and sizes, allow me to try and describe it in words: 1) Check for a condition, and change a value if true. 2) Goto 1) several times. 3) If any of the conditions is met, perform an action. I'm looking for a better pattern than the very procedural one Im used to using. > *http://code.activestate.com/pypm/django-dirtyfields/ That looks very interesting, thankyou for that. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Django code patterns
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']: resource.user.is_active = request.POST['is_active'] has_changed = True if has_changed: resource.user.save() although it works, I feel like there is a cleaner solution. How would you solve such a problem? Thanks! Rune -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Port of Django Template Language to PHP
@Kenneth Heh, no understood what you meant, but guess I could have separated my answer better. Sorry about that! cheers Rune Kaagaard On Aug 22, 9:10 am, kenneth gonsalves <law...@thenilgiris.com> wrote: > On Sun, 2011-08-21 at 16:22 +0200, Rune Kaagaard wrote: > > @Kenneth+@Masklinn: You are right, there are a lot of template > > languages already, but this particular wheel is - unlike twig - not a > > compiled language but implemented in pure PHP as an Iterator, allowing > > it to blend in as an extension to your existing PHP templates. > > I think you misunderstood me - I meant that continually reinventing the > wheel is a good thing, and leads to better and better wheels of all > sizes and shapes. > -- > regards > Kenneth Gonsalves -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Re: Port of Django Template Language to PHP
@Yaşar: Thanks a lot, would love to see the post if you really do write it! @Kenneth+@Masklinn: You are right, there are a lot of template languages already, but this particular wheel is - unlike twig - not a compiled language but implemented in pure PHP as an Iterator, allowing it to blend in as an extension to your existing PHP templates. Thanks for your interest! On Sun, Aug 21, 2011 at 4:09 AM, kenneth gonsalveswrote: > On Sat, 2011-08-20 at 21:28 +0200, Masklinn wrote: >> > Those of you moonlighting in PHP, might be interested in a pure PHP >> > port of the Django Template Language that I've just released. It's >> > called Chano and has doc pages at http://chano.readthedocs.org and a >> > github account at https://github.com/runekaagaard/php-chano . >> This sounds like a huge duplication of effort: there's already >> Twig[0], >> a port of Jinja2[1] which is basically a reimplementation and >> extension >> of Django's own templating language. > > if people did not keep reinventing the wheel we would be still in the > age of oxcarts. > -- > regards > Kenneth Gonsalves > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-users@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Port of Django Template Language to PHP
Dear Django Users Those of you moonlighting in PHP, might be interested in a pure PHP port of the Django Template Language that I've just released. It's called Chano and has doc pages at http://chano.readthedocs.org and a github account at https://github.com/runekaagaard/php-chano . Thanks for your time! Rune Kaagaard -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.