def repl_type_vocabulary(self): results = [{'title': _('default_replacement_type_label', default=u'Default replacement'), 'description': _('default_replacement_type_help', default=u'Default replacement method. Use the replacement string ' u'from the field below'), 'value': ''}] utilities = self.utilities for hname, hobj in utilities: results.append(dict(title=hobj.name, description=hobj.description, value=hname)) return results
class InternalLinkToUIDUtility(object): implements(IBulkModifyReplacementHandler) context = None name = _('utility_internal_link_to_uid_name', default=u"Convert internal links to resolveuid usage") description = _('utility_internal_link_to_uid_description', default=u"If the match contains a group called <url> and this group is an internal link to " u"a site content, let's transform it to a link using resolveuid.\n" u"A good example: <a [^>]*href=\"(?P<url>[^\"]+)\"[^>]+>") @classmethod def repl(cls, match): groups = match.groupdict() if groups.get('url'): old_url = groups.get('url') if not old_url.startswith('resolveuid/'): site = getSite() portal_url = site.portal_url site_url = site.absolute_url() if portal_url.isURLInPortal(old_url, cls.context or None): path = old_url.replace('%s/' % site_url, '', 1).encode('utf-8') suffix = [] content = None while path: content = site.unrestrictedTraverse(path, default=None) if IUUIDAware.providedBy(content): break suffix.insert(0, path.split('/')[-1]) path = '/'.join(path.split('/')[:-1]) if content and IUUIDAware.providedBy(content): uuid = IUUID(content) suffix.insert(0, '') new_url = 'resolveuid/%s' % uuid + '/'.join(suffix) return match.string[match.start():match.end()].replace(old_url, new_url) return match.string[match.start():match.end()]
def _createNewVersion(self, obj): _ = getToolByName(self.context, 'translation_service').utranslate if isObjectChanged(obj) and isObjectVersioned(obj): maybeSaveVersion(obj, comment=_(msgid="Bulk text replacement", domain="rt.bulkmodify", context=obj))