def width_of_image_container(context, plugin): # Based on the plugin settings and placeholder width, calculate image container width # work out native image aspect ratio plugin.has_borders = False # width values # None: use native width # <0: an absolute value # <=100: a percentage of placeholder's width # 1000: automatic, based on placeholder's width placeholder_width = get_placeholder_width(context, plugin) if plugin.width > 0 and plugin.width <= 100: width = placeholder_width / 100.0 * plugin.width auto = False else: width = placeholder_width auto = True # calculate the width of the block the image will be in width = calculate_container_width(context, plugin, width, auto) # return the width of the container print "width_of_image_container", width return width
def get_container_width(self, context): # Based on the plugin settings and placeholder width, calculate image container width # work out native image aspect ratio self.has_borders = False # width values # None: use native width # <0: an absolute value # <=100: a percentage of placeholder's width # 1000: automatic, based on placeholder's width placeholder_width = get_placeholder_width(context, self) if self.width > 0 and self.width <= 100: width = placeholder_width / 100.0 * self.width auto = False else: width = placeholder_width auto = True # calculate the width of the block the image will be in self.container_width = int( calculate_container_width(context, self, width, auto)) return self.container_width # return it for further processing
def width_of_image_container(context, plugin): # Based on the plugin settings and placeholder width, calculate image width # work out native image aspect ratio plugin.has_borders = False # width values # None: use native width # <0: an absolute value # <=100: a percentage of placeholder's width # 1000: automatic, based on placeholder's width placeholder_width = get_placeholder_width(context, plugin) if plugin.width > 0 and plugin.width <= 100: width = placeholder_width/100.0 * plugin.width auto = False else: width = placeholder_width auto = True # calculate the width of the block the image will be in width = calculate_container_width(context, plugin, width, auto) return width
def render(self, context, instance, placeholder): segments = list(instance.carousel_item.all()) if len(segments) < 2: return # because it would be silly to have a carousel with only one segment # TODO: this scaling code needs to be in a common place # use the placeholder width as a hint for sizing # unlike the image plugin, we only use relative widths # widths a fraction of nominal container width (deprecated) placeholder_width = get_placeholder_width(context, instance) if instance.width <= 10: width = placeholder_width/instance.width # widths relative to placeholder width else: # widths a percentage of placeholder width if instance.width <= 100: width = placeholder_width/100.0 * instance.width auto = False # automatic width elif instance.width == 1000: width = placeholder_width auto = True # calculate the width of the block the image will be in width = calculate_container_width(instance, width, auto) width = int(width) -2 # make room for left/right borders label_width = width/len(segments) heights = [] for segment in segments: divider = 1.0/float(segment.image.width) height_multiplier = float(segment.image.height)*divider heights.append(height_multiplier) if ((width * label_width)/100.0) /float(len(segment.link_title)) > 6.0: # if the label width divided by no. of characters in label is > 10 (i.e. we allow about 10px width per character, then we'll assume the label can fit on a single line) segment.line_class = "single-line" else: segment.line_class = "double-line" segment.label_width = int(label_width - 1) heights.sort() height_multiplier = heights[0] segments[-1].label_class = "right" segments[-1].label_width = int(label_width + width%len(segments)) if instance.aspect_ratio: height = width / instance.aspect_ratio else: height = width * height_multiplier size= (int(width),int(height)) context.update({ 'carousel':instance, 'segments':segments, 'size': size, }) return context
def render(self, context, instance, placeholder): segments = list(instance.carousel_item.all()) if len(segments) < 2: return # because it would be silly to have a carousel with only one segment # widths a fraction of nominal container width (deprecated) placeholder_width = get_placeholder_width(context, instance) if instance.width <= 10: width = placeholder_width / instance.width # widths relative to placeholder width else: # widths a percentage of placeholder width if instance.width <= 100: width = placeholder_width / 100.0 * instance.width auto = False # automatic width elif instance.width == 1000: width = placeholder_width auto = True # calculate the width of the block the image will be in width = calculate_container_width(context, instance, width, auto) width = int(width) - 2 # make room for left/right borders label_width = width / len(segments) heights = [] for segment in segments: divider = 1.0 / float(segment.image.width) height_multiplier = float(segment.image.height) * divider heights.append(height_multiplier) if ((width * label_width) / 100.0) / float( len(segment.link_title) ) > 6.0: # if the label width divided by no. of characters in label is > 10 (i.e. we allow about 10px width per character, then we'll assume the label can fit on a single line) segment.line_class = "single-line" else: segment.line_class = "double-line" segment.label_width = int(label_width - 1) heights.sort() height_multiplier = heights[0] segments[-1].label_class = "right" segments[-1].label_width = int(label_width + width % len(segments)) if instance.aspect_ratio: height = width / instance.aspect_ratio else: height = width * height_multiplier size = (int(width), int(height)) context.update({ 'carousel': instance, 'segments': segments, 'size': size, }) return context
def render(self, context, instance, placeholder): segments = list(instance.carousel_item.active_items().exclude(destination_object_id=None)) if len(segments) > 1: # widths a fraction of nominal container width (deprecated) placeholder_width = get_placeholder_width(context, instance) if instance.width <= 10: width = placeholder_width/instance.width # widths relative to placeholder width else: # widths a percentage of placeholder width if instance.width <= 100: width = placeholder_width/100.0 * instance.width auto = False # automatic width elif instance.width == 1000: width = placeholder_width auto = True # calculate the width of the block the image will be in width = calculate_container_width(context, instance, width, auto) width = int(width) -2 # make room for left/right borders label_width = width/len(segments) heights = [] for segment in segments: divider = 1.0/float(segment.image.width) height_multiplier = float(segment.image.height)*divider heights.append(height_multiplier) if ((width * label_width)/100.0) /float(len(segment.link_title)) > 6.0: # if the label width divided by no. of characters in label is > 10 (i.e. we allow about 10px width per character, then we'll assume the label can fit on a single line) segment.line_class = "single-line" else: segment.line_class = "double-line" segment.label_width = int(label_width - 1) heights.sort() height_multiplier = heights[0] segments[-1].label_class = "right" segments[-1].label_width = int(label_width + width%len(segments)) if instance.aspect_ratio: height = width / instance.aspect_ratio else: height = width * height_multiplier size= (int(width),int(height)) context.update({ 'carousel':instance, 'segments':segments, 'size': size, }) else: self.render_template = "null.html" return context
def get_container_width(self, context): # Based on the plugin settings and placeholder width, calculate image container width # work out native image aspect ratio self.has_borders = False # width values # None: use native width # <0: an absolute value # <=100: a percentage of placeholder's width # 1000: automatic, based on placeholder's width placeholder_width = get_placeholder_width(context, self) if self.width > 0 and self.width <= 100: width = placeholder_width/100.0 * self.width auto = False else: width = placeholder_width auto = True # calculate the width of the block the image will be in self.container_width = int(calculate_container_width(context, self, width, auto)) return self.container_width # return it for further processing