fixes attachment processing

commit by commit

this and https://github.com/dimagi/commcare-hq/pull/3091 together should fix http://manage.dimagi.com/default.asp?104202

a lot is just formatting and code cleanup

main change is that it doesn't use the "src" property from submissions in any meaningful way since this is just a temporary URI