Added app reference to SQLAlchemy DB instance. Fixes #736, fixes #737
Refactor: added setup_db function
Merge pull request #739 from PyBossa/issues-736-737-export-error

closes #736 closes #737