def __call__(self, *args, **kw): portal_url = self.clean_portal_url() view_name = "/@@download-assets?uid=" params = kw.copy() if params.get("uid"): self.target_uid = params.get("uid", None) self.presscontent = self.resolvePressItem(self.target_uid) options = {"items": list()} pressitem = self.presscontent iteminfo = {} if pressitem.imagename: iteminfo["title"] = pressitem.imagename else: iteminfo["title"] = pressitem.Title() uuid = IUUID(pressitem, None) timestamp_string = self.generate_timestamp(pressitem) iteminfo["url"] = portal_url + view_name + uuid + timestamp_string iteminfo["type"] = "MainImage" iteminfo["image"] = self.getImageTag(pressitem) options["items"].append(iteminfo) attachments = self.queryAttachments() for item in attachments: item_obj = item.getObject() item_uuid = IUUID(item_obj, None) item_timestamp = self.generate_timestamp(item_obj) info = {} item_title = item.Title if item_title.startswith("assets-"): item_title = item.Description info["title"] = item_title info["url"] = portal_url + view_name + item_uuid + item_timestamp info["type"] = item.portal_type if IImageAttachment.providedBy(item_obj): image_tag = self.getImageTag(item_obj) info["image"] = image_tag else: info["image"] = "" options["items"].append(info) template = ViewPageTemplateFile("attachments.pt")(self, **options) # clean_template = self.fix_ssl_links(template) return template
def applyChanges(self, data): context = aq_inner(self.context) parent = aq_parent(context) assert IImageAttachment.providedBy(context) fti = getUtility(IDexterityFTI, name='pressapp.presscontent.imageattachment') schema = fti.lookupSchema() fields = getFieldsInOrder(schema) for key, value in fields: try: new_value = data[key] setattr(context, key, new_value) except KeyError: continue context.setDescription(data['description']) modified(context) context.reindexObject(idxs='modified') IStatusMessage(self.request).addStatusMessage( _(u"Image attachment has successfully been updated"), type='info') return self.request.response.redirect(parent.absolute_url() + '/view')