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

the main content changes are in 1c74dd71bb738e2f5978d99d8b35e1babcbbfb87 and 00619eb2f2d9d6f59b4485eb41330e577558d075