Fixes required module bug caused by 2+ main_call

When a required, uncompleted program module is found, the function
ProgramModuleObj.main_view_fn() is called. This function is a wrapper
for that module's main_call method.

Previously, the main_call was determined by self.main_view. When a
module (such as the TeacherEventsModule) has two main_calls,
self.main_view doesn't necessarily return the view you want. The
observed bug was that, when the Teacher Training and Interview Signups
ProgramModuleObj was made required, teachers would be redirected to the
Manage Teacher Training and Interviews view instead.

This commit replaces the reference to self.main_view with a reference to
self.get_main_view(tl), which was introduced in commit b11641b29d and
returns the correct main_call view, even in cases when there are
multiple main_calls.
Makes another get_main_view(tl) substitution

Substitutes module.main_view for module.get_main_view(tl) in
ProgramModuleObj.getCoreURL().

I'm not entirely sure that this change is necessary, since we shouldn't
ever have a CoreModule that has two distinct main_calls. However, it
shouldn't hurt to make this change. Unless we rely on the caching that
module.main_view provides.
Add LaTeX batch mode flags.

Add the following flags.
    -interaction nonstopmode
        This ensures LaTeX quits if a dependency (.sty) is missing.
    -halt-on-error
        This makes LaTeX quit on the first error instead of wasting
        time continuing to render a broken document. Note that this
        alone will stop the compiler on a syntax error but not on a
        missing .sty file.

To see what this commit does, go find studentschedule.tex, replace
"fullpage" with a nonexistent package name, and try to run
    python2 manage.py test modules
(really just the testSchedules programprintables test).
Before this commit, it should stop and wait for user input.
After this commit, it should just error out and move on.

On that note, maybe we should consider replacing os.system with
something like subprocess.check_call--to let us know immediately when
latex fails, rather than later on when we can't find the dvi file it
was supposed to produce.

Fixes #263.
Restore dvips landscape options for ps and svg.

This restores changes from 956521f3699de0bb5978bf36579523d513eef337
clobbered in the merge 7dcf5546fae6bae2bcb77bfa5cc96434eda0ffef
(mit-working into main).

The commit being restored was made in the main branch; its state prior
to the merge can be seen in 510b8d2fecba54e38259e4be6596f54d72823c62.
Partial restoration was previously done in
ea23ef2a46a8e26ca35d6488fd2c91c66a3e3b5a and
a32cb0cded41ecaecaf638370990ebb0bff3368b.

It is my guess that the clobbering was unintentional. So this commit
restores the flags passed to dvips to suppor rendering .ps and .svg
files in landscape mode. (It seems the ps and svg formats were
approximately never requested in landscape mode anyway.)
LaTeX: change os.system to subprocess.check_call.

subprocess.check_call throws an exception upon seeing a nonzero (i.e.
abnormal) exit value. For the price of a little verbosity, we get to
see when one of the commands fails *before* we attempt to run the next
command on its nonexistent output.

Occurrences of os.system in esp/esp/gen_media/inlinelatex.py are left
untouched since with those, we already check the exit value explicitly
and supply a custom message in case of error.
Make texescape safe to run on '\n'.

If x = '\n', then {{ x|texescape }} in its own paragraph causes
some problems because you get an isolated \\. LaTeX complains
at you that "There's no line here to end."

So cheat by putting a ~ (non-stretching, non-line-breaking space)
before every generated newline.

Side effect: generated newlines are no longer idempotent. I refrain
from making any claims about the correctness or desirability of this
side effect.
Fix completion certificates.

* Turn off HTML autoescaping. This is a LaTeX document!
* Replace \\ with ~\\ in case of empty class descriptions or such.
* Refer to parent_class for class descriptions and such.
Security fix: uploaded files are renamed into hashed filename.

This solves unrestricted file upload vulnerability with the Media system (for example, by uploading a class document ending in .php).

Uploaded files are renamed to a hash of their generated URL (which includes the date and the filename; for class documents the class ID is prepended) before saving. When downloading, a response is used that includes file content but also the original filename so that it saves properly.
Various functions for the lottery

.sanitize - for removing SR's that don't make sense, so far.
.generate_screwed_csv - for exporting a csv of students who got screwed over by the lottery
.....arg, how does Python work?
Makes generate_screwed_csv have a default of the user's home directory.
Making default verbosity a thing.
Just adding docstrings
Merge branch 'safemedia' of github.com:uakfdotb/ESP-Website into safemediatmp
Fixes migration issues and the seltest command

The migration fixes might conflict with Taylor's changes when we
get around to merging that. We should be sure to check ./manage.py
syncdb followed by ./manage.py migrate on a clean database to make
sure it works after the merge (which will likely be a manual one).
Merge branch 'main' of github.com:learning-unlimited/ESP-Website into migration_test_fixes_gurtej
Adds several depends_ons and tweaks migrations to get flush working

One of the changes was to actually delete the
modules_satprepadminmoduleinfo table. Commit 64161115 by @pricem
describes why this was not included in migration 0024 initially,
but this was preventing flushing, and at this point I think we can
safely delete this table. Since this is affecting an old migration
we have to replay this migration to actually cause the tables to
delete, so if MIT ESP wants to keep the data around we can just
leave things as they are.
Merge branch 'main' of github.com:learning-unlimited/ESP-Website into safemediatmp
Allow administrators to view all QSDMedia files
Use os.path.join so media files can be fetched on different platforms