Fix in 'request.user.is_authenticated'

This is a weird bug, but not all requests have a user object attached to them. I was getting crashes when running the otm1 migrator.
Make get_last_visited_instance safe
Fix inconsistency in User save validation

Certain validation checks were only being executed when user.save() was called, leaving save_with_user() unvalidated. Pushing these validation checks into save_with_user()
Fix outdated code in migrate_otm1

Some things in the app have changed since the last time this was executed.
Make less common fields optional

Move defaults into code, out of declarative portion
Merge pull request #1009 from steventlamb/topic/misc_fixups

Topic/misc fixups
Make exception block smaller

This exception block was catching all exceptions, including ones that occured on the second line, which are not adequately explained by the message provided in the except block.
Clean up get_instance_user

Make get_instance_user more readable

By using a get() query, this will run a maximum of one query, whereas previously, for the common case where a single InstanceUser exists, two queries will run.
Add a save() convenience method to InstanceUser

For the same reasons that it exists on User
Move InstanceDataCommand out of underscore module
Comment and minor adjustment

prefern stdout.write over print
Convert nonexistent god_role -> commander_role
Handle duplicate email imports from otm1

This commit also contains the following improvements:
Fix how more_permissions reinstates previous roles
Drop out save with system user
Great big separate app commit
Move otm1 migrator to its own app
Replace the in-memory map of {otm1_pk: otm2_pk} with database models
Make the migrator idempotent
Uniquify duplicate usernames by adding an incremented suffix

Disable species test because species imports are currently broken.
Fix lint
Wrap model+relic saving in a transaction

Additionally, added a missing relic creation statement in the catch-all else block at the bottom of the main worker function. This wasn't a big problem because that code path is never executed.
Merge pull request #1018 from steventlamb/topic/user_migration_dups

Topic/user migration dups
Add index for Audit.current_value. Fixes #981.

This index helps us optimize for the following query:

```sql
SELECT DISTINCT ON ("treemap_audit"."model_id") "treemap_audit"."model_id", "treemap_audit"."updated"
    FROM "treemap_audit"
    WHERE ("treemap_audit"."instance_id" = 12  AND
        "treemap_audit"."model" = Tree  AND
        "treemap_audit"."field" = plot  AND
        "treemap_audit"."current_value" = 143493 )
    ORDER BY "treemap_audit"."model_id" DESC, "treemap_audit"."updated" DESC
```

This query is used to get the tree history for a given plot. The main
sticking point was the whole table sequence scan. Adding the index
dropped the query time by about 20x.

With this new addition, the audit table index represents an overhead of
about 28% of the audit table size. Justin and I decided this is a
worthwhile price to pay for now.
Use a few smaller queries for audits

The large "ORed" query for generic audits had three subqueries that got
planned in a weird way. Since the expected number of audits for each of
these three queries is small this gives us a performance boost.
Cache UDF definitions

We call this method a bunch of times and it is a fairly intensive
operation. UDFDs change pretty rarely so this seem like a good place to
start.
Reduce instance-building database queries

It takes about 60ms to build and execute a query that returns an
instance - since we already do it at the start of the execution cycle we
can reuse it.

Same with "has_itree_region"

Also reduces user loading.