Re: Applying tag to inserted images
Rick Bruch <[email protected]>
| Newsgroups | gmane.comp.web.zope.plone.user |
|---|---|
| Message-ID | <3842b7433b67428fbe1e50314dbcf904@DM2PR0801MB0764.namprd08.prod.outlook.com> |
Hi Alberto,
Not sure if you’re still working on this, but I thought I’d offer an idea of questionable value…
I don’t have any knowledge of q.transmogrifier, so I can’t help you there. It should be possible to programmatically select images from the “body” of pages using LXML, then apply a tag to them.
As part of a different kind of project I wrote a method to select the first image in a page body. Maybe you can use it as a starting point for your project.
In my .py file, I included:
from lxml import html
The method:
def get_body_image(self, brain):
object = brain.getObject()
if base_hasattr(object, 'Text'):
text = object.getText()
tree = html.fromstring(text)
imgs = tree.xpath('//img')
if imgs:
my_img = imgs[0]
my_img_path = my_img.attrib['src']
return my_img_path
return None
return None
The method:
1. Takes a brain
2. Gets the object for the brain
3. If the object has body text
a. Gets the text
b. Uses LXML to build a data object from the text
c. Makes a list of any img items in the object
i. Selects the first image
ii. Gets its path
iii. Returns it
You could modify that to loop through the list of images and apply a tag.
Hope that helps! Good luck!
-Rick
From: Alberto Lopes
Sent: Sunday, September 07, 2014 8:30 PM
To: plone-users
Subject: [Plone-Users] Applying tag to inserted images
Dear all,
I have a site with lots of content items. Many pages have a specific tag.
I am considering migrating all of those items with quintagroup.transmogrifier, but I'd like to select to migrate only the pages with the special tag.
I thought about using the catalogsource blueprint. However, I'd like to select the images inserted within the page for migration too, even if the images themselves don't have the tag too (the idea is to migrate only the pages with the tag, and treat inserted pages as dependencies).
Is it possible to do that with transmogrifier?
If not, I thought about writing a script to automatically apply the tag to all the inserted images in a page, but I have no idea on what could be the strategy for that (is there any catalog nformation I could use to select the images)?
Alberto
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plone-users