Comments (3)
We won't implement this, as we needed a quick script.
For anyone interested, here is the code we used. In our case, we needed to change old email addresses into new ones. This is a browser view (Python 2 / Plone 4 compatible) :
from plone.portlets.interfaces import IPortletAssignmentMapping
from plone.portlets.interfaces import IPortletManager
from Products.CMFCore.interfaces._content import IFolderish
from Products.Five import BrowserView
from zope.component import getMultiAdapter
from zope.component import getUtility
import re
class MigrateEmailsView(BrowserView):
def __call__(self):
self.count = 0
self.handle_portlets(self.context)
return "Handled {} portlets with emails !".format(self.count)
def convert_classic_porlets(self, portlet):
match = re.findall(r"[\w.+-]+@[\w-]+\.[\w.-]+", portlet.text)
if not match:
return
text = portlet.text
text = text.replace("@oldemail.com", "@newemail.com")
portlet.text = text
self.count += 1
def handle_portlets(self, content):
for manager_name in ["plone.leftcolumn", "plone.rightcolumn"]:
manager = getUtility(IPortletManager, name=manager_name, context=content)
assignments = getMultiAdapter((content, manager), IPortletAssignmentMapping)
for portlet in assignments:
if hasattr(assignments[portlet], "text"):
self.convert_classic_porlets(assignments[portlet])
if not IFolderish.providedBy(content):
return
childs = content.listFolderContents()
for child in childs:
self.handle_portlets(child)
I close this issue (for now ?).
from collective.searchandreplace.
At first, I do not see any reason why this would not be acceptable here.
Except maybe if you cannot use any part of the existing code.
from collective.searchandreplace.
Thanks for the code share! Can always be useful.
from collective.searchandreplace.
Related Issues (16)
- Remove maintainer note HOT 3
- Search and (Replace + Remove) HOT 1
- Restrict searching and replacing to portal_type instead of interface HOT 2
- Allow replacing in all text fields HOT 1
- UnicodeEncodeError HOT 4
- Removed behavior searchandreplace from type Document HOT 4
- plone 5.1* HOT 1
- leaving the "Find What" and "Replace With" field blank results in error HOT 8
- Control panel configlet icon broken in Plone 6 HOT 1
- Uninstall profile? HOT 1
- Can the form look a little nicer? HOT 3
- deprecationwarning: isDefaultPage HOT 6
- Traceback when searching for text with parentheses HOT 2
- ParseError when searching for a space
- Affected content label has unexpected behavior
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collective.searchandreplace.