Fix issue with migration cal:0003

Perhaps because the migration both adds and removes a column, the SET CONSTRAINTS
ALL IMMEDIATE SQL command needs to be run beforehand.
Add django_extensions.tests to INSTALLED_APPS to fix test failure
Use 'datetime.datetime.now()' in Users migrations

It looks like South is set up to assume that the datetime module has been imported.
In a couple of migrations we were doing a "from datetime import datetime" which
conflicts with this.  The easiest solution is to harmonize with what South is
expecting.

Thanks to Eric for identifying the problem and providing the solution in 5e1fd83.
Avoid relying on DataTree methods in migrations

Several of our migrations rely on information from the DataTree.
This is fine, but now that the DataTree has been crippled we can't use
functions like children() and tree_encode() anymore.  So, update
the migrations to use the DB fields only.
Fix memory leak in accounting migration for some setups

On my 32-bit Python 2.7 install it was running out of memory.  I found
that this was caused by Django caching database queries, and could be
fixed by flushing that cache.  I also moved the migration for individual
programs into a separate function.

Reminder: this migration takes a long time, and existing accounting data
may be very messed up.
(cherry picked from commit 14765c976dab1478f631c2d8a611c639309238cf)
Fix cache dependency for ESPUser.getTaughtClassesAll()

This needed to be an m2m, but fortunately that is easy to implement now.

This regression was caught by our TeacherClassRegModuleTest.
Fix incorrect use of Permission in TeacherClassRegModuleTest
Fix Program.teachers()['taught_before'] with new schema

Now we can't represent whether a teacher has taught before using a
Q object.  Maybe this feature should be removed... but for now it is
at least partly useful (it selects teachers of previous programs,
and you have to chain it with a query to select teachers of the
current program).
Harmonize use of deadline_met() by program modules

The program modules were fetching user objects from a few different places
when checking deadlines, leading to incorrect results during testing.
This change centralizes checks in the base class, in
ProgramModuleObj.deadline_met(); it allows self.user (if set somewhere
else, like in a unit test) to override the user from the request if it
is set.

This bug (/regression?) was identified by our TeacherClassRegTest.
(Permissions were being checked against some random user from the request
object that didn't even exist anymore.)