ednapiranha/webtools-workermgmt — comment on commit 51c8e16f28af282a71a445e4096f4dcc133f1164
File: apps/webtools/utils.py line 181
By fwenzel:

I found a beautiful way to avoid all this repeated ``form.cleaned_data`` stuff: use the if/else stuff to define the summary strings, but use:

``summary = 'New Hire Notification - {firstname} {lastname}`'`

and then later do:

``summary = summary.format(firstname=form.cleaned_data.get('first_name'), lastname=...)``.

Here's more info about advanced string formatting: http://docs.python.org/whatsnew/2.6.html#pep-3101-advanced-string-formatting

And the cool thing is that you don't need to use all the things in the string that you pass into ``format()``, so you can only show the things that are relevant to the form.