def hasContentLeadImage(obj, portal, **kw): if ILeadImageable.providedBy(obj): field = obj.getField(IMAGE_FIELD_NAME) if field is not None: value = field.get(obj) return not not value return False
def handle_scales_action(self, action, data): CheckAuthenticator(self.request) number = 0 ctool = getToolByName(self.context, 'portal_catalog') items = ctool(hasContentLeadImage=True) for i in items: obj = i.getObject() if obj is None: continue if not ILeadImageable.providedBy(obj): continue try: state = obj._p_changed except (ConflictError, KeyboardInterrupt): raise except: state = 0 field = obj.getField(config.IMAGE_FIELD_NAME) if field is not None: field.removeScales(obj) field.createScales(obj) number = number + 1 if state is None: obj._p_deactivate() self.status = _(u"text_scales_recreated", default=u"${number} scales recreated.", mapping={'number':number})
def getImage(self): if not ILeadImageable.providedBy(self.context): return '' else: caption = self.getCaption() field = self.context.getField(IMAGE_FIELD_NAME) return field.tag(self.context, title=caption, scale=SIZE)
def handle_scales_action(self, action, data): CheckAuthenticator(self.request) number = 0 ctool = getToolByName(self.context, 'portal_catalog') items = ctool(hasContentLeadImage=True) for i in items: obj = i.getObject() if obj is None: continue if not ILeadImageable.providedBy(obj): continue try: state = obj._p_changed except (ConflictError, KeyboardInterrupt): raise except: state = 0 field = obj.getField(config.IMAGE_FIELD_NAME) if field is not None: field.removeScales(obj) field.createScales(obj) number = number + 1 if state is None: obj._p_deactivate() self.status = _(u"text_scales_recreated", default=u"${number} scales recreated.", mapping={'number': number})
def getCaption(self): if not ILeadImageable.providedBy(self.context): return self.context.title_or_id() field = self.context.getField(IMAGE_CAPTION_FIELD_NAME) caption = field.get_size(self.context) != 0 if not caption: return self.context.title_or_id() else: return field.get(self.context)
def get_lead_image(content, size='preview'): url = None caption = None if ILeadImageable.providedBy(content): field = content.getField(IMAGE_FIELD_NAME) if field is not None and field.get(content): url = ''.join((content.absolute_url(), '/leadImage_', size)) field_caption = content.getField( IMAGE_CAPTION_FIELD_NAME) if field_caption is not None: caption = field_caption.get(content) return {'url': url, 'caption': caption}
def addLeadImageCaption(self, item, caption): #set the caption if necessary and if lead image product is installed if LEADIMAGE_EXISTS and caption != "": #add the caption try: if ILeadImageable.providedBy(item): field = aq_inner(item).getField(IMAGE_CAPTION_FIELD_NAME) field.set(item, caption) else: print("Item type does not accept leadImage therefore captions will be ignored") except: print "Error adding leadImage caption: ", sys.exc_info()[1] return
def og_image(self): default = super(LeadImageSeoContextAdapter, self).og_image if not ILeadImageable.providedBy(self.context): return default field = self.context.getField(IMAGE_FIELD_NAME) if not field: return default value = field.get(self.context) if not value: return default return self.get("og_image") or "%s/leadImage_preview" % self.context.absolute_url()
def addLeadImageCaption(self, item, caption): #set the caption if necessary and if lead image product is installed if LEADIMAGE_EXISTS and caption != "": #add the caption try: if ILeadImageable.providedBy(item): field = aq_inner(item).getField(IMAGE_CAPTION_FIELD_NAME) field.set(item, caption) else: print( "Item type does not accept leadImage therefore captions will be ignored" ) except: print "Error adding leadImage caption: ", sys.exc_info()[1] return
def addLeadImage(self, item, image): #set the lead image if necessary and if lead image product is installed if LEADIMAGE_EXISTS and image != "": #download and create the image try: imageFile = urllib2.urlopen(image) imageData = imageFile.read() urlSplit = image.split("/") filename = urlSplit[len(urlSplit)-1] #add the image as leadImage if ILeadImageable.providedBy(item): field = aq_inner(item).getField(IMAGE_FIELD_NAME) field.set(item, imageData, filename=filename) else: print("Item type does not accept leadImage") #release the image file imageFile.close() return except: print "LeadImage URL not available. LeadImage not created because: (" + image + ")", sys.exc_info()[1] return
def addLeadImage(self, item, image): #set the lead image if necessary and if lead image product is installed if LEADIMAGE_EXISTS and image != "": #download and create the image try: imageFile = urllib2.urlopen(image) imageData = imageFile.read() urlSplit = image.split("/") filename = urlSplit[len(urlSplit) - 1] #add the image as leadImage if ILeadImageable.providedBy(item): field = aq_inner(item).getField(IMAGE_FIELD_NAME) field.set(item, imageData, filename=filename) else: print("Item type does not accept leadImage") #release the image file imageFile.close() return except: print "LeadImage URL not available. LeadImage not created because: (" + image + ")", sys.exc_info( )[1] return