2018/09/04

Archetypes Migration to Dexterity

Link Integrity Check

Be sure to set it disabled

Image Attributes in RichText Fields

<p><img class="image-inline" title="開基武廟外觀" src="kjwm-wg.jpg/@@images/c57ff855-3d5e-4eaf-8e5c-5e32db58867e.jpeg" alt="開基武廟外觀" /></p>
<p>開基武廟外觀   謝奇峰拍攝2011.8.6</p>
<p><img class="image-inline" title="開基武廟前殿" src="kjwm-qd.jpg/@@images/9c0d6de5-3295-49a5-970d-e26f51b117d6.jpeg" alt="開基武廟前殿" /></p>
<p>開基武廟前殿   謝奇峰拍攝2011.8.6</p>
<p><img class="image-inline" title="開基武廟前殿神龕" src="kjwm-qdsz.jpg/@@images/42c54979-0cad-4244-b692-80d736e25f77.jpeg" alt="開基武廟前殿神龕" /></p>
<p>開基武廟前殿神龕    謝奇峰拍攝2011.8.6</p>
<p> </p>
<p><img class="image-inline" title="開基武廟後殿" src="kjwm-hd.jpg/@@images/e74bc633-d278-47bd-8c13-223c16c1e5eb.jpeg" alt="開基武廟後殿" /></p>
<p>開基武廟後殿   謝奇峰拍攝2011.8.6</p>
<p><img class="image-inline" title="開基武廟後殿之三川殿" src="kjwm-hdscd.jpg/@@images/4919cf95-a664-48c1-a0d7-5cef3b91c4a3.jpeg" alt="開基武廟後殿之三川殿" /></p>
<p>開基武廟後殿之三川殿   謝奇峰拍攝2011.8.6</p>
<p><img class="image-inline" title="開基武廟後殿之拜殿" src="kjwm-hdbd.jpg/@@images/66b3e3e9-7be7-4513-beff-53b1a70bba18.jpeg" alt="開基武廟後殿之拜殿" /></p>
<p>開基武廟後殿之拜殿   謝奇峰拍攝2011.8.6</p>
<p><img class="image-inline" title="開基武廟後殿之正殿" src="kjwm-hdzd.jpg/@@images/76e89581-2bf4-4410-b08e-05882fada26d.jpeg" alt="開基武廟後殿之正殿" /></p>
<p>開基武廟後殿之正殿  謝奇峰拍攝2011.8.6</p>
import re

text_list = html_doc.split('\n')
result = []

for text in text_list:
    find = re.search(r'(^.* src\s*=\s*")(.*\.jpg/@@images/)(.*\.jpeg")( alt=.*$)', text)
    if find:
        result.append(find.group(1) + find.group(2) + 'image/preview"' + find.group(4))
    else:
        result.append(text)
print '\n'.join(result)

利用 bin/plonectl run update.py 來更新 RichText 內容

#!/usr/bin/python
# -*- coding: utf-8 -*-

from Testing import makerequest
from AccessControl.SecurityManagement import newSecurityManager
from Products.CMFCore.utils import getToolByName

root = makerequest.makerequest(app)
site = root.mysite
admin = root.acl_users.getUserById('admin')
admin = admin.__of__(site.acl_users)

newSecurityManager(None, admin)

from zope.site.hooks import setHooks
from zope.component.hooks import setSite
setHooks()
setSite(site)
site.setupCurrentSkin(site.REQUEST)


import re
from plone import api
from plone.app.textfield.value import RichTextValue
import transaction

for item in api.content.find(Type='MyType'):
    obj = item.getObject()
    if obj.myfield == None:
        text = []
    else:
        text = obj.myfield.raw.split('\n')
    result = []
    for line in text:
        find = re.search(r'(^.* src\s*=\s*")(.*\.jpg/@@images/)(.*\.jpeg")( .*$)', line)
        if find:
            result.append(find.group(1)+find.group(2)+'image/preview"'+find.group(4))
        else:
            result.append(line)
    result = '\n'.join(result)
    obj.myfield = RichTextValue(result, 'text/html', 'text/x-html-safe', 'utf-8')

    obj.reindexObject()

transaction.commit()

No comments: