From 120d1af7c84eba0f9b31315bfcf7c9a0dc544269 Mon Sep 17 00:00:00 2001 From: Marcin Koziej Date: Tue, 11 Oct 2011 12:51:50 +0200 Subject: [PATCH] =?utf8?q?genrowanie=20pdf:=20usni=C4=99cie=20bloku=20try.?= =?utf8?q?.catch;=20xml=20na=20pewno=20jest=20poprawny,=20poniewa=C5=BC=20?= =?utf8?q?zosta=C5=82=20ju=C5=BC=20zparse'owany.=20Nie=20ma=20po=20co=20lo?= =?utf8?q?gowa=C4=87=20i=20powstrzymywa=C4=87=20wyj=C4=85tku=20=20wyst?= =?utf8?q?=C4=85pi=C5=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- apps/catalogue/models.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 930f98d14..0273e47c7 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -514,30 +514,23 @@ class Book(models.Model): """ (Re)builds the pdf file. """ - from librarian import pdf, ParseError + from librarian import pdf from tempfile import NamedTemporaryFile import os + path, fname = os.path.realpath(self.xml_file.path).rsplit('/', 1) try: - path, fname = os.path.realpath(self.xml_file.path).rsplit('/', 1) - try: - pdf_file = NamedTemporaryFile(delete=False) - - pdf.transform(BookImportDocProvider(self), - file_path=str(self.xml_file.path), - output_file=pdf_file, - ) - - self.pdf_file.save('%s.pdf' % self.slug, File(open(pdf_file.name))) - finally: - unlink(pdf_file.name) - - except ParseError, e: - print '%(file)s:%(name)s:%(message)s; use -v to see more output' % { - 'file': self.xml_file.path, - 'name': e.__class__.__name__, - 'message': e - } + pdf_file = NamedTemporaryFile(delete=False) + + pdf.transform(BookImportDocProvider(self), + file_path=str(self.xml_file.path), + output_file=pdf_file, + ) + + self.pdf_file.save('%s.pdf' % self.slug, File(open(pdf_file.name))) + finally: + unlink(pdf_file.name) + def build_epub(self, remove_descendants=True): """ (Re)builds the epub file. -- 2.20.1