Reorganized code
authorThierry Florac <thierry.florac@onf.fr>
Fri, 13 Oct 2017 08:57:57 +0200
changeset 64 ec939bc6a1ef
parent 63 c2b008c96f88
child 65 3997cb3dbe6f
Reorganized code
src/pyams_file/zmi/image.py
--- a/src/pyams_file/zmi/image.py	Fri Oct 13 08:57:32 2017 +0200
+++ b/src/pyams_file/zmi/image.py	Fri Oct 13 08:57:57 2017 +0200
@@ -534,11 +534,73 @@
 
 
 #
+# See all thumbnails!!
+#
+
+@viewlet_config(name='display-all-thumbnails.action', context=IImage, layer=IAdminLayer,
+                view=IImageWidget, manager=IContextActions, weight=80)
+class ImageThumbnailsDisplayAction(ToolbarActionItem):
+    """Image thumbnails display action"""
+
+    label = _("Display all thumbnails")
+    label_css_class = 'fa fa-fw fa-th-large text-primary'
+    hint_gravity = 'nw'
+
+    url = 'display-all-thumbnails.html'
+    modal_target = True
+
+
+@pagelet_config(name='display-all-thumbnails.html', context=IImage, layer=IPyAMSLayer, permission=VIEW_PERMISSION)
+class ImageThumbnailsDisplayForm(DialogDisplayForm):
+    """Image thumbnails display form"""
+
+    @property
+    def title(self):
+        info = IFileInfo(self.context)
+        return info.title or info.filename
+
+    legend = _("Display all image thumbnails")
+    icon_css_class = 'fa fa-fw fa-th-large'
+    dialog_class = 'modal-large'
+
+    fields = field.Fields(Interface)
+
+
+@viewlet_config(name='image-thumbnails', context=IImage, layer=IPyAMSLayer,
+                view=ImageThumbnailsDisplayForm, manager=IWidgetsPrefixViewletsManager)
+@template_config(template='templates/image-thumbnails.pt')
+class ImageThumbnailsViewletsPrefix(Viewlet):
+    """Image thumbnails viewlets prefix"""
+
+    @property
+    def random(self):
+        return random.randint(0, sys.maxsize)
+
+    def get_thumbnails(self):
+        registry = self.request.registry
+        translate = self.request.localizer.translate
+        thumbnailers = OrderedDict()
+        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
+
+
+#
 # Image resize
 #
 
 @viewlet_config(name='image.resize.action', context=IImage, layer=IPyAMSLayer, view=IImageWidget,
-                manager=IContextActions, weight=80)
+                manager=IContextActions, weight=90)
 class ImageResizeAction(FileModifierAction):
     """Image resize action"""
 
@@ -633,65 +695,3 @@
 
 This will generate a new image only if requested size is smaller than the original one.""")
     message_format = 'rest'
-
-
-#
-# See all thumbnails!!
-#
-
-@viewlet_config(name='display-all-thumbnails.action', context=IImage, layer=IAdminLayer,
-                view=IImageWidget, manager=IContextActions, weight=90)
-class ImageThumbnailsDisplayAction(ToolbarActionItem):
-    """Image thumbnails display action"""
-
-    label = _("Display all thumbnails")
-    label_css_class = 'fa fa-fw fa-th-large text-primary'
-    hint_gravity = 'nw'
-
-    url = 'display-all-thumbnails.html'
-    modal_target = True
-
-
-@pagelet_config(name='display-all-thumbnails.html', context=IImage, layer=IPyAMSLayer, permission=VIEW_PERMISSION)
-class ImageThumbnailsDisplayForm(DialogDisplayForm):
-    """Image thumbnails display form"""
-
-    @property
-    def title(self):
-        info = IFileInfo(self.context)
-        return info.title or info.filename
-
-    legend = _("Display all image thumbnails")
-    icon_css_class = 'fa fa-fw fa-th-large'
-    dialog_class = 'modal-large'
-
-    fields = field.Fields(Interface)
-
-
-@viewlet_config(name='image-thumbnails', context=IImage, layer=IPyAMSLayer,
-                view=ImageThumbnailsDisplayForm, manager=IWidgetsPrefixViewletsManager)
-@template_config(template='templates/image-thumbnails.pt')
-class ImageThumbnailsViewletsPrefix(Viewlet):
-    """Image thumbnails viewlets prefix"""
-
-    @property
-    def random(self):
-        return random.randint(0, sys.maxsize)
-
-    def get_thumbnails(self):
-        registry = self.request.registry
-        translate = self.request.localizer.translate
-        thumbnailers = OrderedDict()
-        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