parent
ca5e5bed0c
commit
ab3c1934d5
|
@ -1,6 +1,7 @@
|
||||||
"""
|
"""
|
||||||
Utilities that manipulate pdf files
|
Utilities that manipulate pdf files
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
import requests
|
import requests
|
||||||
from xhtml2pdf import pisa # import python module
|
from xhtml2pdf import pisa # import python module
|
||||||
from PyPDF2 import PdfFileMerger,PdfFileReader
|
from PyPDF2 import PdfFileMerger,PdfFileReader
|
||||||
|
@ -9,6 +10,7 @@ from tempfile import NamedTemporaryFile
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from regluit import settings
|
from regluit import settings
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Utility function
|
# Utility function
|
||||||
def ask_pdf(context={}):
|
def ask_pdf(context={}):
|
||||||
|
@ -35,7 +37,7 @@ def pdf_append( file1, file2, file_out ):
|
||||||
def test_pdf(pdf_file):
|
def test_pdf(pdf_file):
|
||||||
temp = None
|
temp = None
|
||||||
try:
|
try:
|
||||||
if isinstance(pdf_file , str):
|
if isinstance(pdf_file , (str, unicode)):
|
||||||
if pdf_file.startswith('http:') or pdf_file.startswith('https:'):
|
if pdf_file.startswith('http:') or pdf_file.startswith('https:'):
|
||||||
temp = NamedTemporaryFile(delete=False)
|
temp = NamedTemporaryFile(delete=False)
|
||||||
test_file_content = requests.get(pdf_file).content
|
test_file_content = requests.get(pdf_file).content
|
||||||
|
@ -53,7 +55,9 @@ def test_pdf(pdf_file):
|
||||||
except:
|
except:
|
||||||
success = False
|
success = False
|
||||||
return success
|
return success
|
||||||
except:
|
except Exception:
|
||||||
|
pdf_file = unicode(pdf_file)
|
||||||
|
logger.exception('error testing a pdf: %s' % pdf_file[:100])
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def test_test_pdf(self):
|
def test_test_pdf(self):
|
||||||
|
|
|
@ -1119,7 +1119,8 @@ class EbookFileTests(TestCase):
|
||||||
#test the ask-appender
|
#test the ask-appender
|
||||||
c.add_ask_to_ebfs()
|
c.add_ask_to_ebfs()
|
||||||
if settings.AWS_SECRET_ACCESS_KEY:
|
if settings.AWS_SECRET_ACCESS_KEY:
|
||||||
assert test_pdf(c.work.ebookfiles().filter(asking=True)[0].file.url)
|
askingpdfurl = c.work.ebookfiles().filter(asking=True)[0].file.url
|
||||||
|
assert test_pdf(askingpdfurl)
|
||||||
else:
|
else:
|
||||||
assert test_pdf(c.work.ebookfiles().filter(asking=True)[0].file)
|
assert test_pdf(c.work.ebookfiles().filter(asking=True)[0].file)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue