From abd66021256d14b8d3ac7a09d9673f5c0b7cc174 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 15 Feb 2013 16:56:10 +0100 Subject: [PATCH] fix relative paths issue in import; two kinds of pdf --- catalogue/management/commands/importlessons.py | 15 +++++++++------ catalogue/models.py | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/catalogue/management/commands/importlessons.py b/catalogue/management/commands/importlessons.py index 87fd16e..4e7a38c 100755 --- a/catalogue/management/commands/importlessons.py +++ b/catalogue/management/commands/importlessons.py @@ -29,7 +29,7 @@ class Command(BaseCommand): def import_book(self, file_path, options, attachments): verbose = options.get('verbose') - iofile = IOFile.from_filename(file_path) + iofile = IOFile.from_filename(os.path.join(self.curdir, file_path)) iofile.attachments = attachments lesson = Lesson.publish(iofile) @@ -57,6 +57,8 @@ class Command(BaseCommand): self.style = color_style() verbose = options.get('verbose') + self.curdir = os.path.abspath(os.curdir) + # Start transaction management. transaction.commit_unless_managed() @@ -67,18 +69,19 @@ class Command(BaseCommand): files_skipped = 0 for dir_name in directories: - if not os.path.isdir(dir_name): - print self.style.ERROR("%s: Not a directory. Skipping." % dir_name) + abs_dir = os.path.join(self.curdir, dir_name) + if not os.path.isdir(abs_dir): + print self.style.ERROR("%s: Not a directory. Skipping." % abs_dir) else: - att_dir = os.path.join(dir_name, options['attachments']) + att_dir = os.path.join(abs_dir, options['attachments']) attachments = self.all_attachments(att_dir) # files queue - files = sorted(os.listdir(dir_name)) + files = sorted(os.listdir(abs_dir)) postponed = {} while files: file_name = files.pop(0) - file_path = os.path.join(dir_name, file_name) + file_path = os.path.join(abs_dir, file_name) file_base, ext = os.path.splitext(file_path) # Skip files that are not XML files diff --git a/catalogue/models.py b/catalogue/models.py index 5d9b121..d052d67 100644 --- a/catalogue/models.py +++ b/catalogue/models.py @@ -164,11 +164,12 @@ class Lesson(models.Model): wldoc = WLDocument.from_file(self.xml_file.path, provider=OrmDocProvider) else: wldoc = WLDocument(infile, provider=OrmDocProvider()) - pdf = PdfFormat(wldoc).build() if student: + pdf = PdfFormat(wldoc).build() self.student_pdf.save("%s.pdf" % self.slug, File(open(pdf.get_filename()))) else: + pdf = PdfFormat(wldoc, teacher=True).build() self.pdf.save("%s.pdf" % self.slug, File(open(pdf.get_filename()))) -- 2.20.1