def test_relation_list_gets_cleared(self):
        a_ca = api.translate(self.a_en, 'ca')

        adapted = IRelatedItems(self.a_en)
        dm = getMultiAdapter((adapted, IRelatedItems['relatedItems']),
                             IDataManager)
        dm.set([])

        notify(ObjectModifiedEvent(self.a_en))

        adapted = IRelatedItems(a_ca)
        dm = getMultiAdapter((adapted, IRelatedItems['relatedItems']),
                             IDataManager)
        self.assertEqual(dm.get(), [])
Beispiel #2
0
    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
Beispiel #3
0
    def related(self):
        context = aq_inner(self.context)
        res = ()
        if base_hasattr(context, 'relatedItems'):
            related = context.relatedItems
        else:
            try:
                behavior = IRelatedItems(context)
                related = behavior.relatedItems
            except TypeError:
                return res
        tools = context.restrictedTraverse('@@plone_tools')
        catalog = tools.catalog()
        if related:
            related = [item.to_path for item in related if item.to_path]
            brains = catalog(path=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)
        return res
Beispiel #4
0
    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 __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 test_has_relation_list(self):
        adapted = IRelatedItems(self.a_en)

        bound = IRelatedItems['relatedItems'].bind(adapted)
        self.assertEqual(len(bound.get(adapted)), 1)

        value = bound.get(adapted)
        self.assertEqual(type(value[0]), RelationValue)

        dm = getMultiAdapter((adapted, IRelatedItems['relatedItems']),
                             IDataManager)
        self.assertEqual(dm.get(), [self.b_en])
    def test_relation_list_gets_copied(self):
        a_ca = api.translate(self.a_en, 'ca')

        adapted = IRelatedItems(a_ca)

        bound = IRelatedItems['relatedItems'].bind(adapted)
        self.assertEqual(len(bound.get(adapted)), 1)

        value = bound.get(adapted)
        self.assertEqual(type(value[0]), RelationValue)

        dm = getMultiAdapter((adapted, IRelatedItems['relatedItems']),
                             IDataManager)
        self.assertEqual(dm.get(), [self.b_en])
Beispiel #8
0
 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 test_copied_relation_list_gets_translated(self):
        a_ca = api.translate(self.a_en, 'ca')
        b_ca = api.translate(self.b_en, 'ca')

        # But only after self.a_en is modified (this is a feature, not a bug):
        notify(ObjectModifiedEvent(self.a_en))

        adapted = IRelatedItems(a_ca)

        bound = IRelatedItems['relatedItems'].bind(adapted)
        self.assertEqual(len(bound.get(adapted)), 1)

        value = bound.get(adapted)
        self.assertEqual(type(value[0]), RelationValue)

        dm = getMultiAdapter((adapted, IRelatedItems['relatedItems']),
                             IDataManager)
        self.assertEqual(dm.get(), [b_ca])
Beispiel #10
0
    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        alsoProvides(self.request, IDefaultBrowserLayer)
        alsoProvides(self.request, IPloneAppMultilingualInstalled)

        self.a_en = createContentInContainer(
            self.portal['en'], 'Document', title=u'Test Document')

        self.b_en = createContentInContainer(
            self.portal['en'], 'Document', title=u'Another Document')

        adapted = IRelatedItems(self.a_en)
        dm = getMultiAdapter(
            (adapted, IRelatedItems['relatedItems']),
            IDataManager
        )
        dm.set([self.b_en])
Beispiel #11
0
    def test_migrate_relations(self):
        self.grant('Manager')

        foo = create(Builder('folder').titled(u'Foo'))
        bar = create(
            Builder('folder').titled(u'Bar').having(relatedItems=[foo]))

        self.assertEquals([foo], bar.getRelatedItems())
        self.assertEquals([bar], foo.getBackReferences())

        self.install_profile('plone.app.contenttypes:default')
        map(InplaceMigrator('Folder').migrate_object, (foo, bar))

        foo = self.portal.get('foo')
        bar = self.portal.get('bar')

        self.assertEquals([foo],
                          map(attrgetter('to_object'),
                              IRelatedItems(bar).relatedItems))
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
Beispiel #16
0
# -*- coding: utf-8 -*-

from zope.i18nmessageid import MessageFactory

from plone.autoform.interfaces import WIDGETS_KEY
from zope import schema as _schema
from plone.app.relationfield.behavior import IRelatedItems

_ = MessageFactory('collective.nitf')


widget = 'collective.z3cform.widgets.multicontent_search_widget.MultiContentSearchFieldWidget'
_widget_values = IRelatedItems.queryTaggedValue(WIDGETS_KEY, {})
_widget_values['relatedItems'] = widget
IRelatedItems.setTaggedValue(WIDGETS_KEY, _widget_values)

_schema.getFields(IRelatedItems)['relatedItems'].index_name = 'Related Items'
Beispiel #17
0
 def test_supports_object_relations(self):
     from plone.app.relationfield.behavior import IRelatedItems
     self.assertTrue(IRelatedItems.providedBy(self.blog))
Beispiel #18
0
def related_items_widget():
    IRelatedItems.setTaggedValue(
        WIDGETS_KEY, {'relatedItems': MultiContentSearchFieldWidget})
    logger.info('Patched Related Items widget')
 def test_relateditems_behavior(self):
     from plone.app.relationfield.behavior import IRelatedItems
     self.assertTrue(IRelatedItems.providedBy(self.multimedia))
Beispiel #20
0
 def _set_related_items(self, obj, items):
     assert IRelatedItems.providedBy(obj)
     setattr(obj, 'relatedItems', items)
     modified(obj)
Beispiel #21
0
def related_items_widget():
    IRelatedItems.setTaggedValue(
        WIDGETS_KEY,
        {'relatedItems': MultiContentSearchFieldWidget}
    )
    logger.info('Patched Related Items widget')
 def test_relateditems_behavior(self):
     from plone.app.relationfield.behavior import IRelatedItems
     self.assertTrue(IRelatedItems.providedBy(self.multimedia))