From abb9629739d07883b3e7219fcd52f083094ada9f Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Fri, 29 May 2026 10:50:52 +0200 Subject: [PATCH] simplify again --- lib/pdfannotator | 2 +- .../teleforma-import-conferences-4.py | 47 ++++++++----------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/pdfannotator b/lib/pdfannotator index 70e1f183..1f161760 160000 --- a/lib/pdfannotator +++ b/lib/pdfannotator @@ -1 +1 @@ -Subproject commit 70e1f1833f63cb9105659b431357be580cdfc659 +Subproject commit 1f161760779798d79a9c0c073f15044c2bcc6e46 diff --git a/teleforma/management/commands/teleforma-import-conferences-4.py b/teleforma/management/commands/teleforma-import-conferences-4.py index 78de6cdd..bf7e8e8c 100644 --- a/teleforma/management/commands/teleforma-import-conferences-4.py +++ b/teleforma/management/commands/teleforma-import-conferences-4.py @@ -33,6 +33,13 @@ class Command(BaseCommand): def add_arguments(self, parser): parser.add_argument('args', nargs='*') + def find_format(self, conf_dir, file_format): + files = os.listdir(conf_dir) + for file in files: + name, ext = os.path.splitext(file) + if ext[1:] in file_format: + return conf_dir + os.sep + file + def handle(self, *args, **options): organization_name = args[0] department_name = args[1] @@ -58,42 +65,28 @@ class Command(BaseCommand): str(conference.course_type)]), conference.public_id]) - if (os.path.exists(conf_dir) and - not conference.media.all() - ): - - files = os.listdir(conf_dir) + if (os.path.exists(conf_dir) and not conference.media.all()): - for file in files: - name, ext = os.path.splitext(file) - if ext[1:] in self.image_formats: - full_path = conf_dir + os.sep + file - rel_path = full_path.replace(settings.MEDIA_ROOT, "") - poster_file = rel_path + for image_format in image_formats: + poster_file = self.find_format(conf_dir, image_format) for media_format in self.media_formats: + media_file = find_format(conf_dir, media_format) media = Media(conference=conference) media.course = conference.course media.period = conference.period media.course_type = conference.course_type media.type = media_format media.is_published = False - - for file in files: - name, ext = os.path.splitext(file) - full_path = conf_dir + os.sep + file - rel_path = full_path.replace(settings.MEDIA_ROOT, "") - - if ext[1:] in self.media_formats: - media.file = rel_path - media.save() - filename = os.path.split(full_path)[1] - with open(full_path, 'rb') as f: - media.file_s3.save(filename, File(f)) - media.set_mime_type() - media.poster_file = poster_file - media.save() - logger.logger.info(rel_path) + media.file = media_file.replace(settings.MEDIA_ROOT, "") + media.save() + filename = os.path.split(media_file)[1] + with open(media_file, 'rb') as f: + media.file_s3.save(filename, File(f)) + media.set_mime_type() + media_file = find_format(conf_dir, media_format)media.poster_file = poster_file.replace(settings.MEDIA_ROOT, "") + media.save() + logger.logger.info(media_file) conference.imported = True conference.save() -- 2.47.3