def __call__(self): ids = getUtility(IIntIds) data = [] for name, image in IAttachmentsExtension(self.context).items(): if IImage.providedBy(image) and image: id = ids.queryId(removeAllProxies(image)) title = image.title or getName(image) data.append((title, '@@content.attachment/%s' % id)) data.sort() js_encoded = encoder.encode(data) return """tinyMCEImageList = new Array(%s);""" % js_encoded[1:-1]
def update(self): super(TaskCommentView, self).update() changes = [] for field, data in self.context.changes.items(): if field in ITask: title = ITask[field].title elif field in ITaskAttributes: title = ITaskAttributes[field].title elif field == 'status': title = _('Workflow state') else: continue oldvalue = data[0] if type(data[0]) in (types.TupleType, types.ListType): oldvalue = u', '.join(data[0]) newvalue = data[1] if type(data[1]) in (types.TupleType, types.ListType): newvalue = u', '.join(data[1]) changes.append( (title, {'title': title, 'old': oldvalue, 'new': newvalue})) changes.sort() self.data = [info for _t, info in changes] # attachments attachments = [] for attach in self.context.getAttachments(): info = {'id': attach.__name__, 'title': attach.title or attach.__name__, 'description': attach.description, 'size': ISized(attach).sizeForDisplay(), 'image': False, 'attach': attach, } if IImage.providedBy(attach): attach.preview.generatePreview(70, 70) info['image'] = True self.hasImages = True attachments.append(info) self.attachments = attachments
def getImages(self): context = self.context extension = IAttachmentsExtension(context) ids = getUtility(IIntIds) url = '%s/@@content.attachment'%absoluteURL(getSite(), self.request) for imageId in self.model.images: image = extension.get(imageId) if IImage.providedBy(image) and image: img_url = '%s/%s'%(url, ids.getId(removeAllProxies(image))) preview = image.preview.generatePreview(100, 100) yield {'name': image.__name__, 'title': image.title or image.__name__, 'url': img_url, 'purl': '%s/preview/100x100'%img_url}
def getImage(self): context = self.context extension = IAttachmentsExtension(context) image = extension.get(self.__parent__.model.primaryImage) if IImage.providedBy(image) and image: preview = image.preview.generatePreview(100, 100) url = "%s/@@content.attachment/%s" % ( absoluteURL(getSite(), self.request), getUtility(IIntIds).queryId(image), ) return { "name": image.__name__, "title": image.title or image.__name__, "url": url, "purl": "%s/preview/100x100" % url, }
def getImages(self): context = self.context extension = IAttachmentsExtension(context) url = absoluteURL(context, self.request) ids = getUtility(IIntIds) url = "%s/@@content.attachment" % absoluteURL(getSite(), self.request) for imageId in self.model.additionalImages: image = extension.get(imageId) if IImage.providedBy(image) and image: preview = image.preview.generatePreview(100, 100) img_url = "%s/%s" % (url, ids.getId(image)) yield { "name": imageId, "title": image.title or imageId, "url": img_url, "purl": "%s/preview/100x100" % img_url, }
def update(self): attachments = [] for attach in IAttachmentsExtension(self.context).values(): ownership = IOwnership(attach) info = {'id': attach.__name__, 'title': attach.title or attach.__name__, 'description': attach.description, 'size': translate(ISized(attach).sizeForDisplay()), 'created': IDCTimes(attach).created, 'owner': ownership.owner and ownership.owner.title or _('Unknown'), 'image': False, 'attach': attach, } if IImage.providedBy(attach): attach.preview.generatePreview(70, 70) info['image'] = True attachments.append((info['created'], info)) attachments.sort() self.attachments = [attach for _c, attach in attachments]
def getInfo(self, contentId): content = self.container[contentId] name = content.__name__ item = IItem(content, None) item = {'id': name, 'url': '%s/%s/'%(self.url, name), 'title': getattr(item, 'title', _('No title')) or _('No title'), 'description': getattr(item, 'description', ''), 'image': None} if self.showImage: image = None ids = getUtility(IIntIds) url = '%s/@@content.attachment'%absoluteURL(getSite(), self.request) extension = IAttachmentsExtension(content, None) if extension is None: item['image'] = None else: for attach in extension.values(): if IImage.providedBy(attach) and attach: img_url = '%s/%s'%( url, ids.getId(removeAllProxies(attach))) preview = attach.preview.generatePreview(100, 100) image = {'name': attach.__name__, 'title': attach.title, 'image': attach, 'url': img_url, 'purl': '%s/preview/100x100'%img_url} break item['image'] = image return item