def render(self, context, instance, placeholder): gallery_instances = [] options = dict(instance.get_complete_glossary()) for inline_element in instance.sortinline_elements.all(): # since inline_element requires the property `image`, add ImagePropertyMixin # to its class during runtime try: ProxyModel = create_proxy_model('GalleryImage', (ImagePropertyMixin, ), SortableInlineCascadeElement, module=__name__) inline_element.__class__ = ProxyModel options.update( inline_element.glossary, **{ 'image_width_fixed': options['thumbnail_width'], 'image_height': options['thumbnail_height'], 'is_responsive': False, }) thumbnail_tags = utils.get_image_tags(context, inline_element, options) for key, val in thumbnail_tags.items(): setattr(inline_element, key, val) gallery_instances.append(inline_element) except (KeyError, AttributeError): pass inline_styles = instance.glossary.get('inline_styles', {}) inline_styles.update(width=options['thumbnail_width']) instance.glossary['inline_styles'] = inline_styles context.update( dict(instance=instance, placeholder=placeholder, gallery_instances=gallery_instances)) return context
def render(self, context, instance, placeholder): gallery_instances = [] options = dict(instance.get_complete_glossary()) for inline_element in instance.inline_elements.all(): # since inline_element requires the property `image`, add ImagePropertyMixin # to its class during runtime try: ProxyModel = create_proxy_model('GalleryImage', 'cmsplugin_cascade', (ImagePropertyMixin,), InlineCascadeElement) inline_element.__class__ = ProxyModel options.update(inline_element.glossary, **{ 'image-width-fixed': options['thumbnail-width'], 'image-height': options['thumbnail-height'], 'is_responsive': False, }) thumbnail_tags = utils.get_image_tags(context, inline_element, options) for key, val in thumbnail_tags.items(): setattr(inline_element, key, val) gallery_instances.append(inline_element) except (KeyError, AttributeError): pass inline_styles = instance.glossary.get('inline_styles', {}) inline_styles.update(width=options['thumbnail-width']) instance.glossary['inline_styles'] = inline_styles context.update(dict(instance=instance, placeholder=placeholder, gallery_instances=gallery_instances)) return context
def render(self, context, instance, placeholder): marker_instances = [] for inline_element in instance.inline_elements.all(): try: ProxyModel = create_proxy_model( 'LeafletMarker', (ImagePropertyMixin, MarkerModelMixin), InlineCascadeElement, module=__name__) marker = ProxyModel(id=inline_element.id, glossary=inline_element.glossary) try: aspect_ratio = compute_aspect_ratio(marker.image) width = parse_responsive_length( marker.glossary.get('marker_width') or '25px') marker.size = list( get_image_size(width[0], (None, None), aspect_ratio)) marker.size2x = 2 * marker.size[0], 2 * marker.size[1] except Exception: # if accessing the image file fails, skip size computations pass else: try: marker_anchor = marker.glossary['marker_anchor'] top = parse_responsive_length(marker_anchor['top']) left = parse_responsive_length(marker_anchor['left']) if top[0] is None or left[0] is None: left = width[0] * left[1] top = width[0] * aspect_ratio * top[1] else: left, top = left[0], top[0] marker.anchor = [left, top] except Exception: pass marker_instances.append(marker) except (KeyError, AttributeError): pass context.update( dict(instance=instance, placeholder=placeholder, settings=self.settings, config=app_settings.CMSPLUGIN_CASCADE['leaflet'], markers=marker_instances)) return context
def render(self, context, instance, placeholder): marker_instances = [] for inline_element in instance.inline_elements.all(): try: ProxyModel = create_proxy_model('LeafletMarker', (ImagePropertyMixin, MarkerModelMixin), InlineCascadeElement, module=__name__) marker = ProxyModel(id=inline_element.id, glossary=inline_element.glossary) try: aspect_ratio = compute_aspect_ratio(marker.image) width = parse_responsive_length(marker.glossary.get('marker_width') or '25px') marker.size = list(get_image_size(width[0], (None, None), aspect_ratio)) marker.size2x = 2 * marker.size[0], 2 * marker.size[1] except Exception: # if accessing the image file fails, skip size computations pass else: try: marker_anchor = marker.glossary['marker_anchor'] top = parse_responsive_length(marker_anchor['top']) left = parse_responsive_length(marker_anchor['left']) if top[0] is None or left[0] is None: left = width[0] * left[1] top = width[0] * aspect_ratio * top[1] else: left, top = left[0], top[0] marker.anchor = [left, top] except Exception: pass marker_instances.append(marker) except (KeyError, AttributeError): pass context.update(dict(instance=instance, placeholder=placeholder, settings=self.settings, config=app_settings.CMSPLUGIN_CASCADE['leaflet'], markers=marker_instances)) return context