@@ -80,78 +80,68 @@ def images(self):
8080 context = aq_inner (self .context )
8181 imgs = get_related_media (context , portal_type = "Image" )
8282 show_caption = rm_behavior .show_titles_as_caption
83- first_img_title = ""
84- first_img_scales = None
85- first_img_description = ""
86- first_img_uuid = ""
8783 large_scale = getattr (rm_behavior , "large_image_scale" , "large" )
88- further_images = []
8984 gallery = {}
9085
91- if rm_behavior .include_leadimage and ILeadImage .providedBy (context ):
92- # include leadimage if no related images are defined
93- first_img_scales = context .restrictedTraverse ("@@images" )
94- first_img_title = ILeadImage (context ).image_caption
95- first_img_uuid = context .UID ()
96- further_images = imgs
97-
98- if not first_img_scales and len (imgs ):
99- first_img = imgs [0 ]
100- if first_img :
101- first_img_scales = first_img .restrictedTraverse ("@@images" )
102- first_img_title = first_img .Title ()
103- first_img_description = first_img .Description ()
104- first_img_uuid = first_img .UID ()
105- further_images = imgs [1 :]
106-
107- if first_img_scales :
108- scale = first_img_scales .scale (
86+ def add_to_gallery (obj , ** kw ):
87+ if obj is None :
88+ return
89+ first = kw .get ("first" , False )
90+ scales = obj .restrictedTraverse ("@@images" )
91+ if obj .image is None or scales is None :
92+ return
93+ filename = obj .image .filename
94+ if filename in gallery :
95+ # deduplicate leadimage and related images
96+ return
97+ scale = scales .scale (
10998 "image" ,
110- scale = rm_behavior .first_image_scale ,
111- direction = rm_behavior .first_image_scale_direction
112- and "down"
113- or "thumbnail" ,
99+ scale = (
100+ rm_behavior .first_image_scale
101+ if first
102+ else rm_behavior .preview_scale
103+ ),
104+ mode = (
105+ "cover"
106+ if (
107+ rm_behavior .first_image_scale_direction
108+ if first
109+ else rm_behavior .preview_scale_direction
110+ )
111+ else "contain"
112+ ),
113+ )
114+ uuid = obj .UID ()
115+ title = kw .get ("title" , obj .Title ())
116+ gallery [filename ] = dict (
117+ url = scales .scale ("image" , scale = large_scale ).url ,
118+ tag = scale .tag (
119+ title = title ,
120+ alt = title ,
121+ css_class = "img-fluid" ,
122+ ),
123+ show_caption = show_caption ,
124+ caption = title ,
125+ title = title ,
126+ description = kw .get ("description" , obj .Description ()),
127+ uuid = uuid ,
128+ order = kw .get ("order" , 0 ),
114129 )
115- if scale :
116- large_scale_url = first_img_scales .scale ("image" , scale = large_scale ).url
117- gallery [first_img_uuid ] = dict (
118- url = large_scale_url ,
119- tag = scale .tag (
120- title = first_img_title ,
121- alt = first_img_title ,
122- css_class = "img-fluid" ,
123- ),
124- caption = first_img_title ,
125- show_caption = show_caption ,
126- title = first_img_title ,
127- description = first_img_description ,
128- uuid = first_img_uuid ,
129- order = 0 ,
130- )
131130
132- for idx , img in enumerate (further_images , 1 ):
133- if img :
134- scales = img .restrictedTraverse ("@@images" )
135- scale = scales .scale (
136- "image" ,
137- scale = rm_behavior .preview_scale ,
138- direction = rm_behavior .preview_scale_direction
139- and "down"
140- or "thumbnail" ,
141- )
142- uuid = img .UID ()
143- if scale :
144- large_scale_url = scales .scale ("image" , scale = large_scale ).url
145- gallery [uuid ] = dict (
146- url = large_scale_url ,
147- tag = scale .tag (css_class = "img-fluid" ),
148- caption = img .Title (),
149- show_caption = show_caption ,
150- title = img .Title (),
151- description = img .Description (),
152- uuid = uuid ,
153- order = idx ,
154- )
131+ if ILeadImage .providedBy (context ):
132+ # include leadimage
133+ add_to_gallery (
134+ context ,
135+ first = True ,
136+ title = ILeadImage (context ).image_caption ,
137+ description = "" ,
138+ )
139+ elif len (imgs ):
140+ # no leadimage there but related images
141+ add_to_gallery (imgs [0 ], first = True )
142+
143+ for idx , img in enumerate (imgs , 1 ):
144+ add_to_gallery (img , order = idx )
155145
156146 # pattern feature to filter special uuids to display with ?uuids=uuid1,uuid2,...
157147 uuid_filter = self .request .get ("uuids" )
0 commit comments