Products.CMFPlone/plip-1486-redirection: Update redirects.py

Stephan Klinger <jenkins-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.cvs
Message-ID <[email protected]>
Repository: Products.CMFPlone
Branch: refs/heads/plip-1486-redirection
Date: 2017-07-10T09:31:40+03:00
Author: Stephan Klinger (staeff) <[email protected]>
Commit: https://github.com/plone/Products.CMFPlone/commit/4d811c11148dea577eb7a32318b0f5d02c395c63

Update redirects.py

Files changed:
M Products/CMFPlone/controlpanel/browser/redirects.py

diff --git a/Products/CMFPlone/controlpanel/browser/redirects.py b/Products/CMFPlone/controlpanel/browser/redirects.py
index 85447eec1..33294eb52 100644
--- a/Products/CMFPlone/controlpanel/browser/redirects.py
+++ b/Products/CMFPlone/controlpanel/browser/redirects.py
@@ -17,7 +17,7 @@
 _ = MessageFactory('plone')
 
 
-def absolutize_path(path, context=None, is_source=True):
+def absolutize_path(path, context=None, is_alias=True):
     """Check whether object exist to the provided `path`.
        Assume relative paths are relative to `context`;
        reject relative paths if `context` is None.
@@ -26,9 +26,10 @@ def absolutize_path(path, context=None, is_source=True):
     """
 
     portal = getUtility(ISiteRoot)
+    storage = getUtility(IRedirectionStorage)
     err = None
     if path is None or path == '':
-        err = (is_alias and _(u"You have to enter an alias.")
+        err = (is_source and _(u"You have to enter an alias.")
                or _(u"You have to enter a target."))
     else:
         if path.startswith('/'):
@@ -42,16 +43,16 @@ def absolutize_path(path, context=None, is_source=True):
                 # What case should this be?
                 context_path = "/".join(context.getPhysicalPath()[:-1])
                 path = "{0}/{1}".format(context_path, path)
-        if not err and is_source:
+        if not err and not is_alias:
             # Check whether obj exists at source path
             result = api.content.find(path={"query": path})
             if len(result) == 0:
-                err = _(u"The provided source path does not point to an object.")
-        if not err and not is_source:
+                err = _(u"The provided target object does exist.")
+        if not err and is_alias:
             # Check whether obj exists at target path
             result = api.content.find(path={"query": path})
             if len(result) != 0:
-                err = _(u"The provided target path does already exist.")
+                err = _(u"The provided already does already exist.")
     return path, err
 
 class RedirectsView(BrowserView):
@@ -78,7 +79,7 @@ def __call__(self):
         errors = {}
 
         if 'form.button.Add' in form:
-            redirection, err = absolutize_path(form.get('redirection'), is_source=False)
+            redirection, err = absolutize_path(form.get('redirection'), is_alias=True)
             if err:
                 errors['redirection'] = err
                 status.addStatusMessage(err, type='error')
@@ -164,8 +165,8 @@ def __call__(self):
     def add(self, redirection, target, portal, storage, status):
         """Add the redirections from the form. If anything goes wrong, do nothing."""
 
-        abs_redirection, err = absolutize_path(redirection, is_source=True)
-        abs_target, target_err = absolutize_path(target, is_source=False)
+        abs_redirection, err = absolutize_path(redirection, is_alias=True)
+        abs_target, target_err = absolutize_path(target, is_alias=False)
 
         if err and target_err:
             err = "{0} {1}".format(err, target_err)
@@ -178,6 +179,8 @@ def add(self, redirection, target, portal, storage, status):
                 # TODO: detect indirect recursion
 
         if not err:
+            status.addStatusMessage(_(err), type='error')
+        else:
             storage.add(abs_redirection, abs_target)
             status.addStatusMessage(_(u"Alias {0} &rarr; {1} added.").format(abs_redirection, abs_target),
                                     type='info')



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.