def tabs(self): request = self.request context = self.context root = request.virtual_root performer = request.performer tab_data = [] songs = root.get('songs') performers = root.get('performers') for (title, section, exact, q) in ( ( 'Songs', songs, None, None ), ( 'Performers', performers, lambda c: performer is None or not inside(c, performer), None ), ( 'Recordings', '@@recordings', lambda c: c is root and request.view_name == 'recordings', None, ), ( 'My Profile', performer, None, None ), ): d = {} if isinstance(section, str): d['url'] = request.resource_url(root, section, query=q) d['title'] = title active = exact(context) and 'active' or None d['class'] = active tab_data.append(d) elif section is not None: d['url'] = request.resource_url(section, query=q) d['title'] = title active = inside(context, section) and 'active' or None if exact and active: active = exact(context) and 'active' or None d['class'] = active tab_data.append(d) return tab_data
def tabs(self): request = self.request context = self.context root = request.virtual_root user = request.user performer = None if user: performer = getattr(user, 'performer', None) tab_data = [] songs = root.get('songs') performers = root.get('performers') recordings = root.get('recordings') for (title, section, exact) in ( ('Songs', songs, None), ('Performers', performers, lambda s: context is not performer), ('Recordings', recordings, None), ('My Profile', performer, None), ): if section is not None: d = {} d['url'] = request.resource_url(section) d['title'] = title active = inside(context, section) and 'active' or None if exact and active: active = exact(section) and 'active' or None d['class'] = active tab_data.append(d) return tab_data
def getsitemenu(request): """ В меню попадают обекты первого уровня дерева ресурсов. """ sitemenu = [] root = request.root sitemenu.append(root) for v in root.values(): sitemenu.append(v) # make hrefs hrefs = [] for i, menuitem in enumerate(sitemenu): # надо пропустить корневой объект, если запрашиваемый # объект лежит глубже первого уровня дерева ресурсов # if (request.context == menuitem) or \ (inside(request.context, menuitem) and i > 0): hrefs.append('[<a href="' + request.resource_url(menuitem) + '">' + menuitem.title + '</a>]') else: hrefs.append('<a href="' + request.resource_url(menuitem) + '">' + menuitem.title + '</a>') return '<p>' + ' '.join(hrefs) + '</p>'
def get_paste_item(context, request): info = request.session.get('kotti.paste') if info: id, action = info item = DBSession().query(Node).get(id) if item is None or not item.type_info.addable(context, request): return if action == 'cut' and inside(context, item): return if context == item: return return item
def get_paste_item(context, request): info = request.session.get('kotti.paste') if info: id, action = info item = DBSession().query(Node).get(id) if not item.type_info.addable(context, request): return if action == 'cut' and inside(context, item): return if context == item: return return item
def get_paste_items(context, request): items = [] info = request.session.get('kotti.paste') if info: ids, action = info for id in ids: item = DBSession.query(Node).get(id) if item is None or not item.type_info.addable(context, request): continue if action == 'cut' and inside(context, item): continue if context == item: continue items.append(item) return items
def get_paste_items(context, request): from kotti.resources import Node items = [] info = request.session.get("kotti.paste") if info: ids, action = info for id in ids: item = DBSession.query(Node).get(id) if item is None or not item.type_info.addable(context, request): continue if action == "cut" and inside(context, item): continue if context == item: continue items.append(item) return items
def __call__(self, toplevel, register): context = self.context # We can't register for a more specific interface than IPersistent so # we have to check for __parent__ here (signifiying that the object is # located) and do something special rather than just registering a copy # hook for things that are guaranteed to have a __parent__ (such as # Zope's ILocation) if hasattr(context, '__parent__'): if not inside(self.context, toplevel): # Return the object if we *don't* want it copied. I don't # really quite understand why we return it instead of returning # None, and why we raise an exception if we *do* want it copied # but mine is not to wonder why. return context # Otherwise, it's a persistent object that does live inside the object # we're copying or a nonpersistent object. In such cases, we # definitely want to copy them and we signify this desire by raising # ResumeCopy. raise ResumeCopy
def tabs(self): root = self.request.virtual_root home_data = { 'url':self.request.resource_url(root), 'title':'Home', 'class':self.context is root and 'active' or None } tab_data = [ home_data ] songs = root.get('songs') performers = root.get('performers') recordings = root.get('recordings') for (title, section) in ( ('Songs', songs), ('Performers', performers), ('Recordings', recordings), ): if section is not None: d = {} d['url'] = self.request.resource_url(section) d['title'] = title d['class'] = inside(self.context, section) and 'active' or None tab_data.append(d) return tab_data
def _callFUT(self, one, two): from pyramid.location import inside return inside(one, two)
def test_branch_loading_lineage(root): """Objects from collection is in lineage of Root and Collection.""" leaf = root['objects']['any'] assert location.inside(leaf, root) assert location.inside(leaf, root['objects'])
def test_branch_lineage(root): """Leaf is a child resource of Root according to Pyramid lineage.""" assert location.inside(root['leaf'], root)