Fix @meets_deadline.

Makes @meets_deadline and friends check that a permission is valid
(unexpired) before using it.  Note: the line of code this edits should
arguably be removed entirely, but that may require some discussion.
Merge pull request #800 from learning-unlimited/fix-deadlines

Fix @meets_deadline.
Adds .students() for twophase lottery, and uses it in lottery.py

Previously the lottery script only used the lotteried_students from the
old lottery, which did not include StudentSubjectInterests.  This adds a
corresponding twophase_lotteried_students to the twophase lottery
module.  This probably has the side effect of adding some useful numbers
to the dashboard.
Adds missing imports to twophase student reg.
Fix a typo in twophase .students().
Fixes .students() for twophase to not be really slow.

Also fixes the lottery to use the new one.  The changes in 3e8b12ec
resulted in some incredibly slow queries, so we do the logic in python
instead.  Warning: comm panel queries of the form "students who have a
star or marked a choice in twophase" will probably be very slow.
Fix the twophase .students() to match up correctly.
Various fixes to the schedules printing script.

This fixes several bugs with the schedule printing script, including the
one where it hosed the entire site.  Fixes:

1. The printing script would refresh even if the previous response had
not loaded.  If the previous response took longer than 2s to load, this
would build up requests on the server and make it sad.  Now it will
wait.

2. The LaTeX renderer was breaking on PNG output if the document was
more than one page.  Now it will return the first page; I think this is
the most reasonable thing to do.  It's certainly what makes sense here
(since the second page is probably just a barcode), and I think this is
really the only place PNG output is used anyway.  If we ever have
multiple pages of content in the schedule, this script will have to be
rewritten, as it relies on rendering to PNG.

3. The "print schedules" button on the onsite grid was submitting with
the printer in the URL, rather than as a GET parameter.  This was
because the other view that does a similar thing wanted it in the URL.
Now they are consistent (as a GET parameter) and are called correctly by
their respective frontends.

4. The view that adds a PrintRequest was erroring because it was trying
to set the printer as a string, where it should be a Printer object.
This has been fixed.
Forgot to add one file to the previous commit.
And adds an (already-existing) missing import.
Prints only the first schedule (since we can only print one page anyway).
Merge pull request #808 from learning-unlimited/print-schedules-fixes

Various fixes to the schedules printing script.