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
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
Add a migration for existing qsdmedia objects to hashed names

The new naming system applies to all files that get uploaded.  However,
the server has a lot of existing files that need to be converted in order
for links to work.
Update migration to rename instead of re-save files

The qsdmedia migration just added was using target_file.save() to give the
file a new name.  Not only was this leaving the previous file in place, it
was assigning a new directory to the file based on the current date.  That
meant all uploaded files were being moved from their separate directories
(one per month) into just one directory, named for the current month.
Using os.rename() and directly modifying the target_file database field
fixes this.
Move some code to new StudentRegSanityController

There were some functions in the lottery assignment controller that didn't
have much to do with the lottery but were stil useful.  I moved them into
a new controller that can be used similarly to the lottery (instantiate
with a program and any options, then call sanitize()).  I also made the
minor tweaks so the code would run.