manual: Download can serve either pdf or pdf.gz file

Fixes the problem where an installation might not have a gzipped version of the
manual (like the Plinth development VM for example).

Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati 2017-12-05 11:26:43 +05:30
parent 3bafdb3789
commit 0b6006968e
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35

View File

@ -91,6 +91,12 @@ def download_manual(request):
try:
with gzip.open(os.path.join(cfg.doc_dir, manual_name), 'rb') as f:
content = f.read()
except IOError:
try:
# pdf.gz doesn't exist. Try with .pdf
manual_name = manual_name.rpartition('.')[0]
with open(os.path.join(cfg.doc_dir, manual_name), 'rb') as f:
content = f.read()
except IOError:
raise Http404('File {} does not exist.'.format(manual_name))