From bf53ff5277dc60336c2f56d37538390b5dd5d1ec Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Thu, 29 Aug 2024 15:01:42 +0200 Subject: [PATCH] [IMP] attachment_synchronize: add hook The goal is to be able easy overrides to pass custom parameters to the fsspec open method --- attachment_synchronize/models/attachment_queue.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/attachment_synchronize/models/attachment_queue.py b/attachment_synchronize/models/attachment_queue.py index 9f9861e5305..c3d60b2426d 100644 --- a/attachment_synchronize/models/attachment_queue.py +++ b/attachment_synchronize/models/attachment_queue.py @@ -21,6 +21,12 @@ class AttachmentQueue(models.Model): selection_add=[("export", "Export File (External location)")] ) + def _write_file_to_remote(self, fs, full_path): + self.ensure_one() + data = base64.b64decode(self.datas) + with fs.open(full_path, "wb") as f: + f.write(data) + def _run(self): res = super()._run() if self.file_type == "export": @@ -32,9 +38,7 @@ def _run(self): # create missing folders if necessary : if folder_path and not fs.exists(folder_path): fs.makedirs(folder_path) - data = base64.b64decode(self.datas) - with fs.open(full_path, "wb") as f: - f.write(data) + self._write_file_to_remote(fs, full_path) return res def _get_failure_emails(self):