Various fixes to lottery script, mostly to do with multiple priority levels.

* Sections will now be filled from longest to shortest (which was
  previously the case according to a comment but not in reality), and
  rerandomized for each priority level.
* The code that imports preferences will not import any preferences
  corresponding to non-accepted sections.  If it somehow otherwise
  imports preferences for sections it doesn't know about, it will error.
* The code deals more carefully with which things should apply to all
  priority levels (including possibly the one for grade range
  exceptions), and which things should be done only on "real" priority
  levels.
* The error message when classes are full is now correct.
* The try/except for importing preferences is now an actual
  QuerySet.exists() check.
* A test was added for running the lottery with multiple priority
  levels.
Merge pull request #1045 from learning-unlimited/lottery-fixes

Various fixes to lottery script