mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
help: Don't uncompress the PDF manual
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
0b6006968e
commit
d15e6b22f1
@ -18,12 +18,11 @@
|
|||||||
Help module for Plinth.
|
Help module for Plinth.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import gzip
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from apt.cache import Cache
|
from apt.cache import Cache
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import File
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import Http404, HttpResponse
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
@ -87,22 +86,22 @@ def manual(request):
|
|||||||
|
|
||||||
def download_manual(request):
|
def download_manual(request):
|
||||||
"""Serve the PDF version of the manual from the 'doc' directory"""
|
"""Serve the PDF version of the manual from the 'doc' directory"""
|
||||||
manual_name = 'freedombox-manual.pdf.gz'
|
files = [
|
||||||
try:
|
os.path.join(cfg.doc_dir, file_name)
|
||||||
with gzip.open(os.path.join(cfg.doc_dir, manual_name), 'rb') as f:
|
for file_name in ['freedombox-manual.pdf.gz', 'freedombox-manual.pdf']
|
||||||
content = f.read()
|
if os.path.isfile(os.path.join(cfg.doc_dir, file_name))
|
||||||
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))
|
|
||||||
|
|
||||||
return HttpResponse(
|
if not files:
|
||||||
ContentFile(content),
|
raise Http404
|
||||||
content_type=mimetypes.guess_type(manual_name)[0])
|
|
||||||
|
(content_type, encoding) = mimetypes.guess_type(files[0])
|
||||||
|
with open(files[0], 'rb') as file_handle:
|
||||||
|
response = HttpResponse(File(file_handle), content_type=content_type)
|
||||||
|
if encoding:
|
||||||
|
response['Content-Encoding'] = encoding
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def status_log(request):
|
def status_log(request):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user