Open ale-rt opened 8 years ago
Related to #20. I do not know a reasonable way to fix this, but this worries me: renaming Plone sites from the ZMI should work. In addition I am wondering that renaming a Plone site contained in another Plone site will lead to an error because api.portal.get will return the "wrong" portal...
With the wide adoption of plone.api I suspect that the renaming of Plone sites will be impossible :)
A good thing is that the global request is still available.
With this patch to plone.api I was able to rename the Plone site:
diff --git a/src/plone/api/portal.py b/src/plone/api/portal.py
index dbce214..99bd78d 100644
--- a/src/plone/api/portal.py
+++ b/src/plone/api/portal.py
@@ -60,6 +60,11 @@ def get():
for potential_portal in closest_site.aq_chain:
if ISiteRoot in providedBy(potential_portal):
return potential_portal
+ else:
+ from zope.globalrequest import getRequest
+ request = getRequest()
+ for new_id in request.form['new_ids']:
+ return request.traverse('').aq_parent[new_id]
raise CannotGetPortalError(
"Unable to get the portal object. More info on "
Could we work around this adding a form on the Plone site that has to be removed?
AFAIK, renaming a plone site has never been supported. I could look up references to back up my claim, but I'm pretty sure.
On Wed, Nov 25, 2015 at 9:29 AM Alessandro Pisa notifications@github.com wrote:
A good thing is that the global request is still available.
With this patch to plone.api I was able to rename the Plone site:
diff --git a/src/plone/api/portal.py b/src/plone/api/portal.py index dbce214..99bd78d 100644--- a/src/plone/api/portal.py+++ b/src/plone/api/portal.py@@ -60,6 +60,11 @@ def get(): for potential_portal in closest_site.aq_chain: if ISiteRoot in providedBy(potential_portal): return potential_portal+ else:+ from zope.globalrequest import getRequest+ request = getRequest()+ for new_id in request.form['new_ids']:+ return request.traverse('').aq_parent[new_id]
raise CannotGetPortalError( "Unable to get the portal object. More info on "
Could we work around this adding a form on the Plone site that has to be removed?
— Reply to this email directly or view it on GitHub https://github.com/plone/plone.api/issues/285#issuecomment-159681796.
iirc Although not recommended, it would work most of the times (eg: if there weren't too many or too complex addons). You'd "only" lose relations between items, even if clearing & rebuilding catalog. Not sure about collections/portlets paths.
With proposed fix, I am getting an error when deleting plone site. This patch fixes both problems:
diff --git a/src/plone/api/portal.py b/src/plone/api/portal.py
index dbce214..99bd78d 100644
--- a/src/plone/api/portal.py
+++ b/src/plone/api/portal.py
@@ -60,6 +60,11 @@ def get():
for potential_portal in closest_site.aq_chain:
if ISiteRoot in providedBy(potential_portal):
return potential_portal
+ else:
+ from zope.globalrequest import getRequest
+ request = getRequest()
+ if 'new_ids' in request.form:
+ for new_id in request.form['new_ids']:
+ return request.traverse('').aq_parent[new_id]
+ if 'ids' in request.form:
+ for id in request.form['ids']:
+ return None
+
raise CannotGetPortalError(
"Unable to get the portal object. More info on "
This is the traceback I got:
The line calling plone.api is this one: