def __call__(self): self.request.response.setHeader('Content-type', 'application/json') cutils = Utils(self.context, self.request) data = { 'title': self.context.title, 'id': self.context.id, 'has_image': utils.has_image(self.context), 'youtube_url': None } rendered = None if self.context.portal_type in ('Image',): pass elif self.context.portal_type == 'Video': fi = getattr(self.context, 'file', None) data.update({ 'youtube_url': cutils.get_youtube_url(self.context), 'content_type': getattr( fi, 'original_content_type', getattr(fi, 'contentType', None)) }) else: feed = SearchFeed(api.portal.get()) adapter = queryMultiAdapter((self.context, feed), IFeedItem) if adapter is not None: rendered = adapter.render_content_core().strip() return json.dumps({ 'portal_type': self.context.portal_type, 'url': self.context.absolute_url(), 'data': data, 'rendered': rendered })
def _init(self): """ moved here just so we can wrap it in exception block more nicely """ try: primary = IPrimaryFieldInfo(self.context, None) if (INamedField.providedBy(primary.field) and hasattr(primary.field, 'getSize') and primary.field.getSize() > 0): self.file = primary.field self.field_name = primary.fieldname except TypeError: pass if has_image(self.context): self.image = self.file = self.context.image self.field_name = 'image'
def find_image_in_annotation(data): if type(data) in (dict, PersistentMapping, PersistentDict): for field_name in ('content', 'video', 'image', 'images', 'audio'): if field_name not in data: continue val = data[field_name] if not val: continue if isinstance(data, list): val = val[0] if not isinstance(val, basestring): continue val = val.strip() if '<' in val: # possible html... return find_image_in_html(val) else: im = uuidToObject(val) if im is not None and has_image(im): return im
def check_lead_image(obj, request=None): original_obj = obj if request is not None: # if request is passed in, we check for current draft to use... draft = getCurrentDraft(request) if draft is not None: obj = draft if has_image(obj): return image = find_image(obj) if image is not None: try: try: ct = image.image.contentType except AttributeError: ct = None value = NamedBlobImage(contentType=ct) alsoProvides(value, IReferenceNamedImage) value.reference = IUUID(image) original_obj.image = value except AttributeError: pass
def has_image(self, obj): return utils.has_image(obj)