如何使用rt.bulkmodify在Plone中搜索和替换灵巧内容

2024-09-28 01:23:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我们正在从一个旧的静态站点迁移到plone4.3。我们已经从旧网站导入了几个HTML页面,现在面临8000多个硬编码链接,这些链接需要在我们的Plone系统中进行更新,以符合我们新的url标准。这些页面是使用自定义的灵巧类型构建的。我们不想手工编辑这些。在

我们想在Plone中使用批量修改工具。我们正试图使用它来替换所有使用正则表达式的链接。不幸的是,无论我们使用这个工具在Plone中搜索什么,它都找不到单一的结果。在

我觉得我们错过了一步或者走错了方向。在

我们是否缺少了一个过程,或者有更好的方法来搜索和替换我们在灵巧类型内容中的硬编码链接?我们认为我们可能需要某种方式索引的灵巧内容,以便它可以搜索。在

如果这是真的,我们似乎找不到相关文档。在

以下是我们用来尝试实现此功能的参考资料:

Plone.org - rt.bulkmodify

Python - rt.bulkmodify

Plone.org - catalog-indexing-strategies


Tags: 工具org类型内容编码站点网站链接
1条回答
网友
1楼 · 发布于 2024-09-28 01:23:00

对不起,rt.bulkmodify公司现在不支持灵巧。必须提供适当的IBulkModifyContentChanger适配器。在

这里是我们正在开发的未发布版本plone.app.contenttypes/plone5兼容性(没有经过真正的测试,因为现在不可能在Plone 5上真正起作用)。也适用于Plone 4上的纯灵巧定制类型:

from ..interfaces import IBulkModifyContentChanger
from zope.interface import implements


class TextContentAdapters(object):
    """This is OK for every know plone.app.contenttypes dexterity item"""

    implements(IBulkModifyContentChanger)

    def __init__(self, context):
        self.context = context

    def _get_text(self):
        return self._get_utext().encode('utf-8')

    def _set_text(self, text):
        raise NotImplementedError("%s doesn't implements setter for 8-bit string" % self.context.portal_type)

    def _get_utext(self):
        text_data = getattr(self.context, 'text', None)
        if text_data:
            return text_data.raw

    def _set_utext(self, text):
        self.context.text = text
        self.context.reindexObject(idxs=['SearchableText'])

    text = property(_get_text, _set_text)
    utext = property(_get_utext, _set_utext)

相关问题 更多 >

    热门问题