Pre-generate thumbnails in image thumbnails display form to avoid broken thumbnails dur to conflict errors
authorThierry Florac <thierry.florac@onf.fr>
Tue, 12 Sep 2017 12:36:09 +0200
changeset 56 426a8b8538d0
parent 55 3a73f9a24fc5
child 57 37c7e3b785b0
Pre-generate thumbnails in image thumbnails display form to avoid broken thumbnails dur to conflict errors
src/pyams_file/zmi/image.py
--- a/src/pyams_file/zmi/image.py	Tue Sep 12 11:29:48 2017 +0200
+++ b/src/pyams_file/zmi/image.py	Tue Sep 12 12:36:09 2017 +0200
@@ -16,6 +16,7 @@
 # import standard library
 import random
 import sys
+import transaction
 from collections import OrderedDict
 
 # import interfaces
@@ -684,6 +685,13 @@
         adapters = sorted(registry.getAdapters((self.context, ), IThumbnailer),
                           key=lambda x: x[1].weight)
         for name, adapter in adapters:
+            thumbnails = IThumbnail(self.context)
+            if name:
+                selection = thumbnails.get_selection(name)
+                transaction.commit()
+                thumbnails = IThumbnail(selection)
+            thumbnails.get_thumbnail('200x128', 'jpeg')
             thumbnailers.setdefault(translate(adapter.section), []).append({'name': name,
                                                                             'label': translate(adapter.label)})
+        transaction.commit()
         return thumbnailers