Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
plone.app.redirector.browser.FourOhFourView Class Reference
Inheritance diagram for plone.app.redirector.browser.FourOhFourView:
Inheritance graph
[legend]
Collaboration diagram for plone.app.redirector.browser.FourOhFourView:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def attempt_redirect
def find_first_parent
def search_for_similar

Private Member Functions

def _url
def _path_elements

Detailed Description

Definition at line 14 of file browser.py.


Member Function Documentation

Get the path to the object implied by the current URL, as a list
of elements. Get None if it can't be calculated or it is not under
the current portal path.

Definition at line 93 of file browser.py.

00093 
00094     def _path_elements(self):
00095         """Get the path to the object implied by the current URL, as a list
00096         of elements. Get None if it can't be calculated or it is not under
00097         the current portal path.
00098         """
00099         url = self._url()
00100         if not url:
00101             return None
00102 
00103         try:
00104             path = '/'.join(self.request.physicalPathFromURL(url))
00105         except ValueError:
00106             return None
00107 
00108         portal_state = getMultiAdapter((aq_inner(self.context), self.request), name='plone_portal_state')
00109         portal_path = '/'.join(portal_state.portal().getPhysicalPath())
00110         if not path.startswith(portal_path):
00111             return None
00112 
00113         return path.split('/')

Here is the call graph for this function:

Here is the caller graph for this function:

Get the current, canonical URL

Definition at line 84 of file browser.py.

00084 
00085     def _url(self):
00086         """Get the current, canonical URL
00087         """
00088         return self.request.get('ACTUAL_URL',
00089                  self.request.get('VIRTUAL_URL',
00090                    self.request.get('URL',
00091                      None)))

Here is the caller graph for this function:

Definition at line 17 of file browser.py.

00017 
00018     def attempt_redirect(self):
00019         url = self._url()
00020         if not url:
00021             return False
00022 
00023         try:
00024             old_path_elements = self.request.physicalPathFromURL(url)
00025         except ValueError:
00026             return False
00027 
00028         storage = getUtility(IRedirectionStorage)
00029 
00030         old_path = '/'.join(old_path_elements)
00031         new_path = storage.get(old_path)
00032 
00033         if not new_path:
00034 
00035             # If the last part of the URL was a template name, say, look for
00036             # the parent
00037 
00038             if len(old_path_elements) > 1:
00039                 old_path_parent = '/'.join(old_path_elements[:-1])
00040                 template_id = url.split('/')[-1]
00041                 new_path_parent = storage.get(old_path_parent)
00042                 if new_path_parent:
00043                     new_path = new_path_parent + '/' + template_id
00044 
00045         if not new_path:
00046             return False
00047 
00048         url = self.request.physicalPathToURL(new_path)
00049         self.request.response.redirect(url, status=301, lock=1)
00050         return True

Here is the call graph for this function:

Definition at line 51 of file browser.py.

00051 
00052     def find_first_parent(self):
00053         path_elements = self._path_elements()
00054         if not path_elements:
00055             return None
00056         portal_state = getMultiAdapter((aq_inner(self.context), self.request), name='plone_portal_state')
00057         portal = portal_state.portal()
00058         for i in range(len(path_elements)-1, 0, -1):
00059             obj = portal.restrictedTraverse('/'.join(path_elements[:i]), None)
00060             if obj is not None:
00061                 return obj
00062         return None

Here is the call graph for this function:

Definition at line 63 of file browser.py.

00063 
00064     def search_for_similar(self):
00065         path_elements = self._path_elements()
00066         if not path_elements:
00067             return None
00068         path_elements.reverse()
00069         policy = IRedirectionPolicy(self.context)
00070         ignore_ids = policy.ignore_ids
00071         portal_catalog = getToolByName(self.context, "portal_catalog")
00072         portal_state = getMultiAdapter((aq_inner(self.context), self.request), name='plone_portal_state')
00073         navroot = portal_state.navigation_root_path()
00074         for element in path_elements:
00075             if element not in ignore_ids:
00076                 result_set = portal_catalog(SearchableText=element,
00077                                             path = navroot,
00078                                             portal_type=portal_state.friendly_types(),
00079                                             sort_limit=10)
00080                 if result_set:
00081                     return result_set[:10]
00082         return []

Here is the call graph for this function:


The documentation for this class was generated from the following file: