def _is_default_page(container, context): is_default_page = False browser_default = IBrowserDefault(container, None) if browser_default is not None: is_default_page = browser_default.getDefaultPage() == context.getId() return is_default_page
def test_is_view_template_alias(self): browserDefault = IBrowserDefault(self.folder, None) fti = browserDefault.getTypeInfo() aliases = fti.getMethodAliases() aliases['foo_alias'] = '(Default)' fti.setMethodAliases(aliases) self.app.REQUEST[ 'ACTUAL_URL'] = self.folder.absolute_url() + '/foo_alias' self.assertEqual(self.fview.is_view_template(), True) self.assertEqual(self.dview.is_view_template(), False)
def getRootPath(context, currentFolderOnly, topLevel, root_path): """Helper function to calculate the real root path""" context = aq_inner(context) if currentFolderOnly: folderish = getattr( aq_base(context), "isPrincipiaFolderish", False) and not INonStructuralFolder.providedBy(context) parent = aq_parent(context) is_default_page = False browser_default = IBrowserDefault(parent, None) if browser_default is not None: is_default_page = browser_default.getDefaultPage( ) == context.getId() if not folderish or is_default_page: return "/".join(parent.getPhysicalPath()) else: return "/".join(context.getPhysicalPath()) # root = uuidToObject(root) root = get_root(context, root_path) if root is not None: rootPath = "/".join(root.getPhysicalPath()) else: rootPath = getNavigationRoot(context) # Adjust for topLevel if topLevel > 0: contextPath = "/".join(context.getPhysicalPath()) if not contextPath.startswith(rootPath): return contextSubPathElements = contextPath[len(rootPath) + 1:] if contextSubPathElements: contextSubPathElements = contextSubPathElements.split("/") if len(contextSubPathElements) < topLevel: return rootPath = rootPath + "/" + "/".join( contextSubPathElements[:topLevel]) else: return return rootPath
def getObjectDefaultView(context): """Get the id of an object's default view """ # courtesy of Producs.CacheSetup browserDefault = IBrowserDefault(context, None) if browserDefault is not None: try: return browserDefault.defaultView() except AttributeError: # Might happen if FTI didn't migrate yet. pass if not IDynamicType.providedBy(context): return None fti = context.getTypeInfo() try: # XXX: This isn't quite right since it assumes the action starts with ${object_url} action = fti.getActionInfo('object/view')['url'].split('/')[-1] except ValueError: # If the action doesn't exist, stop return None # Try resolving method aliases because we need a real template_id here if action: action = fti.queryMethodID(action, default=action, context=context) else: action = fti.queryMethodID('(Default)', default=action, context=context) # Strip off leading / and/or @@ if action and action[0] == '/': action = action[1:] if action and action.startswith('@@'): action = action[2:] return action
def is_view_template(self): current_url = self.current_base_url() canonical_url = self.canonical_object_url() object_url = self.object_url() if current_url.endswith('/'): current_url = current_url[:-1] if current_url == canonical_url or current_url == object_url: return True if not current_url.startswith(object_url): # Cut short. return False # Get the part of the current_url minus the object_url. last_part = current_url.split(object_url)[-1] if not last_part.startswith('/'): # Unexpected return False # Remove the slash from the front: last_part = last_part[1:] if last_part == 'view': return True context = aq_inner(self.context) browserDefault = IBrowserDefault(context, None) if browserDefault is not None: fti = browserDefault.getTypeInfo() if fti.getMethodAliases().get(last_part) == '(Default)': return True template_id = self.view_template_id() if last_part == template_id: return True elif last_part == '@@%s' % template_id: return True return False