def related_items(self): context = aq_inner(self.context) res = () # Archetypes if base_hasattr(context, 'getRawRelatedItems'): catalog = getToolByName(context, 'portal_catalog') related = context.getRawRelatedItems() if not related: return () brains = catalog(UID=related) if brains: # build a position dict by iterating over the items once positions = dict([(v, i) for (i, v) in enumerate(related)]) # We need to keep the ordering intact res = list(brains) def _key(brain): return positions.get(brain.UID, -1) res.sort(key=_key) # Dexterity if HAS_RELATIONFIELD and IRelatedItems.providedBy(context): related = context.relatedItems if not related: return () res = self.related2brains(related) return res
def related_items(self): context = aq_inner(self.context) res = () # Archetypes if base_hasattr(context, 'getRawRelatedItems'): catalog = getToolByName(context, 'portal_catalog') related = context.getRawRelatedItems() if not related: return () brains = catalog(UID=related) if brains: # build a position dict by iterating over the items once positions = dict([(v, i) for (i, v) in enumerate(related)]) # We need to keep the ordering intact res = list(brains) def _key(brain): return positions.get(brain.UID, -1) res.sort(key=_key) # Dexterity if has_relationfield_installed: if IRelatedItems.providedBy(context): related = context.relatedItems if not related: return () res = [self.rel2brain(rel) for rel in related] return res
def __call__(self, context): terms = [SimpleTerm(title=u'Disabled', value=u'disabled', token='disabled')] if ISyndicatableCollection.providedBy(context): terms.append(SimpleTerm(title=u'From Criteria', value=u'criteria', token='criteria')) if IRelatedItems.providedBy(context): terms.append(SimpleTerm(title=u'From Related Items', value=u'related', token='related')) return SimpleVocabulary(terms)
def __call__(self, context): terms = [ SimpleTerm(title=u'Disabled', value=u'disabled', token='disabled') ] if ISyndicatableCollection.providedBy(context): terms.append( SimpleTerm(title=u'From Criteria', value=u'criteria', token='criteria')) if IRelatedItems.providedBy(context): terms.append( SimpleTerm(title=u'From Related Items', value=u'related', token='related')) return SimpleVocabulary(terms)
def getRelatedLink(obj, **kwargs): """Index to get the link for the slide. It will be the first related item. """ # Archetypes if base_hasattr(obj, 'getRawRelatedItems'): related_items = obj.getRefs('relatesTo') if related_items: # we're only concerned about the first item return checkPermissions(obj, related_items[0]) # Dexterity if HAS_RELATIONFIELD and IRelatedItems.providedBy(obj): related_items = obj.relatedItems if related_items: # we're only concerned about the first item return checkPermissions(obj, related_items[0]) raise AttributeError
def getRelatedLink(obj, **kwargs): """Index to get the link for the slide. It will be the first related item. """ # Archetypes if base_hasattr(obj, "getRawRelatedItems"): related_items = obj.getRefs("relatesTo") if related_items: # we're only concerned about the first item return checkPermissions(obj, related_items[0]) # Dexterity if HAS_RELATIONFIELD and IRelatedItems.providedBy(obj): related_items = obj.relatedItems if related_items: # we're only concerned about the first item return checkPermissions(obj, related_items[0]) raise AttributeError
def __call__(self, recursive=True): # look for a content with name file field into content fti = getUtility(IDexterityFTI, name=self.context.portal_type) schema = fti.lookupSchema() for name, field in getFieldsInOrder(schema): if INamedField.providedBy(field): return getattr(self.context, name) # else, look for a source file field into related items if recursive and IRelatedItems.providedBy(self.context): related_items = [r.to_object for r in self.context.relatedItems] for related_item in related_items: source_file = getMultiAdapter((related_item, self.request), IModelFileSource)() if source_file: return source_file else: continue return None
def __call__(self, recursive=True): # look for a content with name file field into content fti = getUtility(IDexterityFTI, name=self.context.portal_type) schema = fti.lookupSchema() for name, field in getFieldsInOrder(schema): if INamedField.providedBy(field): return getattr(self.context, name) # else, look for a source file field into related items if recursive and IRelatedItems.providedBy(self.context): related_items = [r.to_object for r in self.context.relatedItems] for related_item in related_items: source_file = getMultiAdapter((related_item, self.request), IModelFileSource )() if source_file: return source_file else: continue return None
def test_supports_object_relations(self): from plone.app.relationfield.behavior import IRelatedItems self.assertTrue(IRelatedItems.providedBy(self.blog))
def test_relateditems_behavior(self): from plone.app.relationfield.behavior import IRelatedItems self.assertTrue(IRelatedItems.providedBy(self.multimedia))
def _set_related_items(self, obj, items): assert IRelatedItems.providedBy(obj) setattr(obj, 'relatedItems', items) modified(obj)