class TestOpengeverContentListingWithEnabledBumblebee(FunctionalTestCase):
    """Test we do not trip up in the presence of a bumblebee installation."""

    layer = OPENGEVER_FUNCTIONAL_BUMBLEBEE_LAYER

    def setUp(self):
        super(TestOpengeverContentListingWithEnabledBumblebee, self).setUp()

        document = create(Builder('document').with_dummy_content())
        self.obj = IContentListingObject(obj2brain(document))

    def test_documents_are_bumblebeeable(self):
        self.assertTrue(self.obj.is_bumblebeeable())

    def test_dossiers_are_not_bumblebeeable(self):
        dossier = create(Builder('dossier'))
        listing = IContentListingObject(obj2brain(dossier))

        self.assertFalse(listing.is_bumblebeeable())

    def test_get_preview_image_url(self):
        self.assertIsNotNone(self.obj.get_preview_image_url())

    def test_get_overlay_title(self):
        self.assertEqual(u'Testdokum\xe4nt', self.obj.get_overlay_title())

    def test_get_overlay_url(self):
        self.assertEqual(
            'http://nohost/plone/document-1/@@bumblebee-overlay-listing',
            self.obj.get_overlay_url(),
        )
    def test_klass(self):
        article = self.create_content('collective.cart.core.Article')
        instance = IContentListingObject(article)
        self.assertEqual(instance.klass(), 'normal')

        instance.discount_available = mock.Mock()
        self.assertEqual(instance.klass(), 'discount')
class TestOpengeverContentListingWithEnabledBumblebee(IntegrationTestCase):
    """Test we do not trip up in the presence of a bumblebee installation."""

    features = ('bumblebee', )

    def setUp(self):
        super(TestOpengeverContentListingWithEnabledBumblebee, self).setUp()
        self.login(self.regular_user)
        self.obj = IContentListingObject(obj2brain(self.document))

    def test_documents_are_bumblebeeable(self):
        self.assertTrue(self.obj.is_bumblebeeable())

    def test_dossiers_are_not_bumblebeeable(self):
        listing = IContentListingObject(obj2brain(self.dossier))
        self.assertFalse(listing.is_bumblebeeable())

    def test_get_preview_image_url(self):
        self.assertIsNotNone(self.obj.get_preview_image_url())

    def test_get_overlay_title(self):
        self.assertEqual(u'Vertr\xe4gsentwurf', self.obj.get_overlay_title())

    def test_get_overlay_url(self):
        expected_url = ('{}/@@bumblebee-overlay-listing'.format(
            self.document.absolute_url()))

        self.assertEqual(expected_url, self.obj.get_overlay_url())
Example #4
0
class TestOpengeverContentListingWithEnabledBumblebee(FunctionalTestCase):

    layer = OPENGEVER_FUNCTIONAL_BUMBLEBEE_LAYER

    def setUp(self):
        super(TestOpengeverContentListingWithEnabledBumblebee, self).setUp()

        document = create(Builder('document')
                          .with_dummy_content())
        self.obj = IContentListingObject(obj2brain(document))

    def test_documents_are_bumblebeeable(self):
        self.assertTrue(self.obj.is_bumblebeeable())

    def test_dossiers_are_not_bumblebeeable(self):
        dossier = create(Builder('dossier'))
        listing = IContentListingObject(obj2brain(dossier))

        self.assertFalse(listing.is_bumblebeeable())

    def test_get_preview_image_url(self):
        self.assertIsNotNone(self.obj.get_preview_image_url())

    def test_get_overlay_title(self):
        self.assertEqual(u'Testdokum\xe4nt', self.obj.get_overlay_title())

    def test_get_overlay_url(self):
        self.assertEqual('http://nohost/plone/document-1/@@bumblebee-overlay-listing',
                         self.obj.get_overlay_url())
    def test_feed_order(self):
        article = self.create_content('collective.cart.core.Article')
        instance = IContentListingObject(article)
        self.assertEqual(instance.feed_order(), u'Edit')

        instance._realobject.feed_order = 3
        self.assertEqual(instance.feed_order(), 3)
Example #6
0
    def __call__(self):
        field_list = self.request.form.get('items.fl', '').strip()
        if field_list:
            field_list = field_list.split(',')
        else:
            field_list = ['@type', 'title', 'description', 'review_state']

        obj = IContentListingObject(self.context)
        summary = json_compatible({
            '@id': obj.getURL(),
        })

        for field in field_list:
            accessor = FIELD_ACCESSORS.get(field)
            if accessor is None:
                continue
            if isinstance(accessor, str):
                value = getattr(obj, accessor, None)
                if callable(value):
                    value = value()
            else:
                value = accessor(obj)
            summary[field] = json_compatible(value)

        if ('title' in summary
                and ITranslatedTitleSupport.providedBy(self.context)):
            # Update title to contain translated title in negotiated language
            attr = 'title_{}'.format(get_preferred_language_code())
            summary['title'] = getattr(self.context, attr)

        return summary
Example #7
0
    def __call__(self):
        field_list = self.request.form.get('items.fl', '').strip()
        if field_list:
            field_list = field_list.split(',')
        else:
            field_list = ['@type', 'title', 'description', 'review_state']

        obj = IContentListingObject(self.context)
        summary = json_compatible({
            '@id': obj.getURL(),
        })

        for field in field_list:
            accessor = FIELD_ACCESSORS.get(field)
            if accessor is None:
                continue
            if isinstance(accessor, str):
                value = getattr(obj, accessor, None)
                if callable(value):
                    value = value()
            else:
                value = accessor(obj)
            summary[field] = json_compatible(value)

        if ('title' in summary and
                ITranslatedTitleSupport.providedBy(self.context)):
            # Update title to contain translated title in negotiated language
            attr = 'title_{}'.format(get_preferred_language_code())
            summary['title'] = getattr(self.context, attr)

        return summary
Example #8
0
    def test_is_trashed(self):
        self.grant('Administrator')

        document_a = create(Builder('document'))
        document_b = create(Builder('document').trashed())

        self.assertFalse(IContentListingObject(document_a).is_trashed)
        self.assertTrue(IContentListingObject(document_b).is_trashed)
Example #9
0
 def test_product_listing_object(self):
     from example.trajectory.product.api import add_product
     from example.trajectory.product.trajectory import product_factory
     from plone.app.contentlisting.interfaces import IContentListingObject
     product = add_product(name='Widget Wash', price=9.75)
     wrapper = product_factory(product.id)
     listing = IContentListingObject(wrapper)
     self.assertEqual(listing.Title(), u'Widget Wash')
 def setUp(self):
     super(TestIndividualRealContentItems, self).setUp()
     self.folder.invokeFactory('Document',
                               'mypage',
                               title='My Page',
                               description='blah')
     self.item = IContentListingObject(self.folder.mypage)
     self.realitem = self.folder.mypage
Example #11
0
    def test_getIcon_returns_none_for_every_contenttype(self):
        self.login(self.regular_user)

        self.assertIsNone(
            IContentListingObject(obj2brain(self.dossier)).getIcon(), )

        self.assertIsNone(
            IContentListingObject(obj2brain(self.document)).getIcon(), )
    def test_is_document(self):
        document = create(Builder('document'))
        mail = create(Builder('mail'))
        dossier = create(Builder('dossier'))

        self.assertTrue(IContentListingObject(obj2brain(document)).is_document)
        self.assertFalse(IContentListingObject(obj2brain(mail)).is_document)
        self.assertFalse(IContentListingObject(obj2brain(dossier)).is_document)
    def test_discount_available(self):
        article = self.create_content('collective.cart.core.Article')
        instance = IContentListingObject(article)
        self.assertFalse(instance.discount_available())

        instance.adapter = mock.Mock()
        instance.adapter.discount_available.ruturn_value = True
        self.assertTrue(instance.discount_available())
Example #14
0
 def __call__(self):
     obj = IContentListingObject(self.context)
     summary = json_compatible({
         '@id': obj.getURL(),
         '@type': obj.PortalType(),
         'title': obj.Title(),
         'description': obj.Description()
     })
     return summary
    def test_getIcon_returns_none_for_every_contenttype(self):
        dossier = create(Builder('dossier'))
        document = create(Builder('document'))

        self.assertEquals(None,
                          IContentListingObject(obj2brain(dossier)).getIcon())

        self.assertEquals(None,
                          IContentListingObject(obj2brain(document)).getIcon())
    def test_is_removed(self):
        document_a = create(Builder('document'))
        document_b = create(Builder('document').removed())
        dossier = create(Builder('dossier'))

        self.assertFalse(
            IContentListingObject(obj2brain(document_a)).is_removed)
        self.assertTrue(
            IContentListingObject(obj2brain(document_b,
                                            unrestricted=True)).is_removed)
        self.assertFalse(IContentListingObject(obj2brain(dossier)).is_removed)
Example #17
0
    def test_is_document(self):
        self.login(self.regular_user)

        self.assertTrue(
            IContentListingObject(obj2brain(self.document)).is_document, )

        self.assertFalse(
            IContentListingObject(obj2brain(self.mail_eml)).is_document, )

        self.assertFalse(
            IContentListingObject(obj2brain(self.dossier)).is_document, )
Example #18
0
    def test_ContentTypeClass_returns_the_contenttype_icon_css_class(self):
        dossier = create(Builder('dossier'))
        document = create(Builder('document'))

        self.assertEquals(
            'contenttype-opengever-dossier-businesscasedossier',
            IContentListingObject(obj2brain(dossier)).ContentTypeClass())

        self.assertEquals(
            'contenttype-opengever-document-document',
            IContentListingObject(obj2brain(document)).ContentTypeClass())
Example #19
0
    def test_ContentTypeClass_returns_the_contenttype_icon_css_class(self):
        self.login(self.regular_user)

        self.assertEquals(
            'contenttype-opengever-dossier-businesscasedossier',
            IContentListingObject(obj2brain(self.dossier)).ContentTypeClass(),
        )

        self.assertEquals(
            'icon-docx',
            IContentListingObject(obj2brain(self.document)).ContentTypeClass(),
        )
    def test_is_trashed(self):
        self.grant('Administrator')
        document_a = create(Builder('document'))
        document_b = create(Builder('document').trashed())

        dossier = create(Builder('dossier'))

        self.assertFalse(
            IContentListingObject(obj2brain(document_a)).is_trashed)
        self.assertTrue(
            IContentListingObject(obj2brain(document_b,
                                            unrestricted=True)).is_trashed)
        self.assertFalse(IContentListingObject(obj2brain(dossier)).is_trashed)
Example #21
0
    def test_is_trashed(self):
        self.login(self.regular_user)

        self.assertFalse(
            IContentListingObject(obj2brain(self.document)).is_trashed, )

        Trasher(self.document).trash()

        self.assertTrue(
            IContentListingObject(obj2brain(self.document,
                                            unrestricted=True), ).is_trashed, )

        self.assertFalse(
            IContentListingObject(obj2brain(self.dossier)).is_trashed, )
Example #22
0
def create_list_item(item, fields):
    obj = IContentListingObject(item)
    data = {'@id': obj.getURL()}
    for field in fields:
        if field not in FIELDS:
            continue
        accessor = FIELDS[field][1]
        if isinstance(accessor, str):
            value = getattr(obj, accessor, None)
            if callable(value):
                value = value()
        else:
            value = accessor(obj)
        data[field] = json_compatible(value)
    return data
Example #23
0
    def test_is_removed(self):
        self.login(self.regular_user)

        self.assertFalse(
            IContentListingObject(obj2brain(self.dossier)).is_removed, )

        self.assertFalse(
            IContentListingObject(obj2brain(self.document)).is_removed, )

        self.login(self.manager)
        self.set_workflow_state('document-state-removed', self.document)

        self.assertTrue(
            IContentListingObject(obj2brain(self.document,
                                            unrestricted=True)).is_removed, )
Example #24
0
def create_list_item(item, fields):
    obj = IContentListingObject(item)
    data = {'@id': obj.getURL()}
    for field in fields:
        if field not in FIELDS:
            continue
        accessor = FIELDS[field][1]
        if isinstance(accessor, str):
            value = getattr(obj, accessor, None)
            if callable(value):
                value = value()
        else:
            value = accessor(obj)
        data[field] = json_compatible(value)
    return data
    def test_containing_dossier_returns_empty_string_for_object_not_in_a_dossier(
            self):  # noqa
        repository = create(Builder('repository'))

        self.assertEquals(
            '',
            IContentListingObject(obj2brain(repository)).containing_dossier())
    def test_get_breadcrumbs_returns_a_tuple_of_dicts_with_title_and_url(self):
        root = create(Builder('repository_root').titled(u'Ordnungssystem'))
        repo = create(Builder('repository').within(root).titled(u'Ablage 1'))
        dossier = create(
            Builder('dossier').within(repo).titled(
                'hans m\xc3\xbcller'.decode('utf-8')))
        document = create(
            Builder('document').titled('Anfrage Meier').within(
                dossier).with_dummy_content())

        self.assertEquals(
            (
                {
                    'absolute_url': 'http://nohost/plone/ordnungssystem',
                    'Title': 'Ordnungssystem'
                },
                {
                    'absolute_url':
                    'http://nohost/plone/ordnungssystem/ablage-1',
                    'Title': '1. Ablage 1'
                },
                {
                    'absolute_url':
                    'http://nohost/plone/ordnungssystem/ablage-1/dossier-1',  # noqa
                    'Title': 'hans m\xc3\xbcller'
                },
                {
                    'absolute_url':
                    'http://nohost/plone/ordnungssystem/ablage-1/dossier-1/document-1',  # noqa
                    'Title': 'Anfrage Meier'
                }),
            IContentListingObject(obj2brain(document)).get_breadcrumbs())
Example #27
0
    def test_brain_summary(self):
        brain = self.catalog(UID=self.doc1.UID())[0]
        summary = getMultiAdapter((brain, self.request),
                                  ISerializeToJsonSummary)()

        self.assertDictEqual(
            {
                '@id': 'http://nohost/plone/doc1',
                '@type': 'DXTestDocument',
                'title': 'Lorem Ipsum',
                'description': 'Description'
            }, summary)

        # Must also work if we're dealing with a CatalogContentListingObject
        # (because the brain has already been adapted to IContentListingObject,
        # as is the case for collection results)
        listing_obj = IContentListingObject(brain)
        summary = getMultiAdapter((listing_obj, self.request),
                                  ISerializeToJsonSummary)()

        self.assertDictEqual(
            {
                '@id': 'http://nohost/plone/doc1',
                '@type': 'DXTestDocument',
                'title': 'Lorem Ipsum',
                'description': 'Description'
            }, summary)
 def setUp(self):
     super(TestIndividualRealContentItems, self).setUp()
     self.portal = self.layer["portal"]
     self.folder = self.portal["test-folder"]
     self.folder.invokeFactory("Document", "mypage", title="My Page", description="blah")
     self.item = IContentListingObject(self.folder.mypage)
     self.realitem = self.folder.mypage
Example #29
0
 def test_cropped_description_returns_empty_string_for_objs_without_description(
         self):
     self.login(self.regular_user)
     self.assertEqual(
         '',
         IContentListingObject(obj2brain(
             self.empty_document)).CroppedDescription())
Example #30
0
 def _get_scaled_img(self, item, size):
     request = getRequest()
     if (
                 ICatalogBrain.providedBy(item) or
                 IContentListingObject.providedBy(item)
     ):
         obj = item.getObject()
     else:
         obj = item
     info = {}
     if hasattr(obj, 'image'):
         scales = getMultiAdapter((obj, request), name='images')
         if size == 'small':
             scale = scales.scale('image', width=300, height=300)
         if size == 'medium':
             scale = scales.scale('image', width=600, height=600)
         if size == 'large':
             scale = scales.scale('image', width=900, height=900)
         else:
             scale = scales.scale('image', width=1200, height=1200)
         if scale is not None:
             info['url'] = scale.url
             info['width'] = scale.width
             info['height'] = scale.height
         else:
             info['url'] = IMG
             info['width'] = '1px'
             info['height'] = '1px'
     else:
         info['url'] = IMG
         info['width'] = '1px'
         info['height'] = '1px'
     return info
Example #31
0
    def test_containing_dossier_title_is_cropped_to_near_200_chars(self):
        dossier = create(Builder('dossier')
                         .titled(25 * u'lorem ipsum '))
        document = create(Builder('document').within(dossier))

        self.assertCropping(
            201, IContentListingObject(obj2brain(document)).containing_dossier())
Example #32
0
    def test_uses_documentlinkrenderer_for_documents(self):
        self.login(self.regular_user)

        self.assertEquals(
            u'PATCHED LINK Vertr\xe4gsentwurf'.encode('utf-8'),
            IContentListingObject(obj2brain(self.document)).render_link(),
        )
Example #33
0
    def _serialize_submitted_excerpt(self, item):
        if not item.has_proposal:
            return None

        excerpt = item.proposal.resolve_submitted_excerpt_document()
        if excerpt:
            return IContentListingObject(excerpt).render_link()
Example #34
0
    def test_containing_dossier_returns_the_title_of_the_containing_dossier(self):
        dossier = create(Builder('dossier').titled(u'Testdossier'))
        document = create(Builder('document').within(dossier))

        self.assertEquals(
            'Testdossier',
            IContentListingObject(obj2brain(document)).containing_dossier())
Example #35
0
        def walk(items, result, parent):
            for item in items:
                collection = []
                if COLLECTION and IContentListingObject.providedBy(item):
                    item = item.getObject()
                elif IATTopic.providedBy(item):
                    collection = item.queryCatalog(b_size=100, full_objects=True)
                elif COLLECTION and ICollection.providedBy(item):
                    collection = item.getQuery()

                if collection:
                    result[item.title_or_id()] = []
                    walk(collection, result, item.title_or_id())
                else:
                    # add only published items
                    if wft.getInfoFor(item, "review_state") != "published":
                        IStatusMessage(self.request).\
                        add(_(u'Some of the items in your list are private. '
                               'They were not included in the wizard - '
                               'MailChimp supports only published content.'),
                            type='error')
                        continue

                    result[parent].append({'uid': IUUID(item),
                                           'title': item.title_or_id()})
            return result
 def __getitem__(self, index):
     """`x.__getitem__(index)` <==> `x[index]`
     """
     if isinstance(index, slice):
         return IContentListing(
             self._basesequence[index.start:index.stop:index.step])
     return IContentListingObject(self._basesequence[index])
Example #37
0
 def _get_scaled_img(self, item, size):
     request = getRequest()
     if ICatalogBrain.providedBy(item) or IContentListingObject.providedBy(item):
         obj = item.getObject()
     else:
         obj = item
     info = {}
     if hasattr(obj, "image"):
         scales = getMultiAdapter((obj, request), name="images")
         if size == "small":
             scale = scales.scale("image", width=300, height=300)
         if size == "medium":
             scale = scales.scale("image", width=600, height=600)
         if size == "large":
             scale = scales.scale("image", width=900, height=900)
         else:
             scale = scales.scale("image", width=1200, height=1200)
         if scale is not None:
             info["url"] = scale.url
             info["width"] = scale.width
             info["height"] = scale.height
         else:
             info["url"] = IMG
             info["width"] = "1px"
             info["height"] = "1px"
     else:
         info["url"] = IMG
         info["width"] = "1px"
         info["height"] = "1px"
     return info
Example #38
0
    def test_uses_documentlinkrenderer_for_mails(self):
        self.login(self.regular_user)

        self.assertEquals(
            u'PATCHED LINK Die B\xfcrgschaft'.encode('utf-8'),
            IContentListingObject(obj2brain(self.mail_eml)).render_link(),
        )
Example #39
0
        def walk(items, result, parent):
            for item in items:
                collection = []
                if COLLECTION and IContentListingObject.providedBy(item):
                    item = item.getObject()
                elif IATTopic.providedBy(item):
                    collection = item.queryCatalog(b_size=100,
                                                   full_objects=True)
                elif COLLECTION and ICollection.providedBy(item):
                    collection = item.getQuery()

                if collection:
                    result[item.title_or_id()] = []
                    walk(collection, result, item.title_or_id())
                else:
                    # add only published items
                    if wft.getInfoFor(item, "review_state") != "published":
                        IStatusMessage(self.request).\
                        add(_(u'Some of the items in your list are private. '
                               'They were not included in the wizard - '
                               'MailChimp supports only published content.'),
                            type='error')
                        continue

                    result[parent].append({
                        'uid': IUUID(item),
                        'title': item.title_or_id()
                    })
            return result
Example #40
0
    def test_brain_summary(self):
        brain = self.catalog(UID=self.doc1.UID())[0]
        summary = getMultiAdapter((brain, self.request),
                                  ISerializeToJsonSummary)()

        self.assertDictEqual(
            {
                "@id": "http://nohost/plone/doc1",
                "@type": "DXTestDocument",
                "title": "Lorem Ipsum",
                "description": "Description",
                "review_state": "private",
            },
            summary,
        )

        # Must also work if we're dealing with a CatalogContentListingObject
        # (because the brain has already been adapted to IContentListingObject,
        # as is the case for collection results)
        listing_obj = IContentListingObject(brain)
        summary = getMultiAdapter((listing_obj, self.request),
                                  ISerializeToJsonSummary)()

        self.assertDictEqual(
            {
                "@id": "http://nohost/plone/doc1",
                "@type": "DXTestDocument",
                "title": "Lorem Ipsum",
                "description": "Description",
                "review_state": "private",
            },
            summary,
        )
Example #41
0
def construct_icalendar(context, events):
    """Returns an icalendar.Calendar object.

    :param context: A content object, which is used for calendar details like
                    Title and Description. Usually a container, collection or
                    the event itself.

    :param events: The list of event objects, which are included in this
                   calendar.
    """
    cal = icalendar.Calendar()
    cal.add('prodid', PRODID)
    cal.add('version', VERSION)

    cal_tz = default_timezone(context)
    if cal_tz:
        cal.add('x-wr-timezone', cal_tz)

    tzmap = {}
    if not hasattr(events, '__getslice__'):  # LazyMap doesn't have __iter__
        events = [events]
    for event in events:
        if ICatalogBrain.providedBy(event) or\
                IContentListingObject.providedBy(event):
            event = event.getObject()
        acc = IEventAccessor(event)
        tz = acc.timezone
        # TODO: the standard wants each recurrence to have a valid timezone
        # definition. sounds decent, but not realizable.
        if not acc.whole_day:  # whole day events are exported as dates without
                               # timezone information
            tzmap = add_to_zones_map(tzmap, tz, acc.start)
            tzmap = add_to_zones_map(tzmap, tz, acc.end)
        cal.add_component(IICalendarEventComponent(event).to_ical())

    for (tzid, transitions) in tzmap.items():
        cal_tz = icalendar.Timezone()
        cal_tz.add('tzid', tzid)
        cal_tz.add('x-lic-location', tzid)

        for (transition, tzinfo) in transitions.items():

            if tzinfo['dst']:
                cal_tz_sub = icalendar.TimezoneDaylight()
            else:
                cal_tz_sub = icalendar.TimezoneStandard()

            cal_tz_sub.add('tzname', tzinfo['name'])
            cal_tz_sub.add('dtstart', transition)
            cal_tz_sub.add('tzoffsetfrom', tzinfo['tzoffsetfrom'])
            cal_tz_sub.add('tzoffsetto', tzinfo['tzoffsetto'])
            # TODO: add rrule
            # tzi.add('rrule',
            #         {'freq': 'yearly', 'bymonth': 10, 'byday': '-1su'})
            cal_tz.add_component(cal_tz_sub)
        cal.add_component(cal_tz)

    return cal
 def setUp(self):
     super(TestIndividualRealContentItems, self).setUp()
     self.portal = self.layer['portal']
     self.folder = self.portal['test-folder']
     self.folder.invokeFactory(
         'Document',
         'mypage',
         title='My Page',
         description='blah',
     )
     self.item = IContentListingObject(self.folder.mypage)
     self.realitem = self.folder.mypage
Example #43
0
class TestOpengeverContentListingWithDisabledBumblebee(FunctionalTestCase):

    def setUp(self):
        super(TestOpengeverContentListingWithDisabledBumblebee, self).setUp()

        document = create(Builder('document'))
        self.obj = IContentListingObject(obj2brain(document))

    def test_documents_are_not_bumblebeeable(self):
        self.assertFalse(self.obj.is_bumblebeeable())

    def test_get_css_classes(self):
        self.assertEqual('state-document-state-draft',
                         self.obj.get_css_classes())

    def test_get_preview_image_url(self):
        self.assertIsNone(self.obj.get_preview_image_url())

    def test_get_overlay_title(self):
        self.assertIsNone(self.obj.get_overlay_title())

    def test_get_overlay_url(self):
        self.assertIsNone(self.obj.get_overlay_url())
Example #44
0
    def get_type(self, item):
        """differ the object typ and return the type as string"""

        if isinstance(item, dict):
            return 'dict'
        elif ICatalogBrain.providedBy(item):
            return 'brain'
        elif IContentListingObject.providedBy(item):
            return 'contentlistingobject'
        elif IFieldWidget.providedBy(item):
            return 'widget'
        elif isinstance(item, Task):
            return 'globalindex_task'
        else:
            raise ValueError("Unknown item type: {!r}".format(item))
Example #45
0
 def get_state_css(self, itemob=None):
     itemob = itemob or self.context
     if ICatalogBrain.providedBy(itemob) or IContentListingObject.providedBy(itemob):
         itemob = itemob.getObject()
     css_map = {
         None: 'success',
         'QUEUED': 'warning',
         'RUNNING': 'warning',
         'COMPLETED': 'success',
         'FAILED': 'error',
         'REMOVED': 'removed',
         'FINISHED': 'info'
     }
     # check job_state and return either success, error or block
     job_state = IExperimentJobTracker(itemob).state
     return css_map.get(job_state, 'info')
Example #46
0
 def _get_scaled_img(self, item, image_field, size):
     request = getRequest()
     if (
         ICatalogBrain.providedBy(item) or
         IContentListingObject.providedBy(item)
     ):
         obj = item.getObject()
     else:
         obj = item
     info = {}
     if hasattr(obj, image_field):
         scales = getMultiAdapter((obj, request), name='images')
         if size == 'lgip':
             stored_image = getattr(obj, image_field)
             scale = image_scale.scaleImage(
                 stored_image.data,
                 width=stored_image.getImageSize()[0],
                 height=stored_image.getImageSize()[1],
                 direction='keep',
                 quality=10
             )
         if size == 'small':
             scale = scales.scale(image_field, width=300, height=300)
         if size == 'medium':
             scale = scales.scale(image_field, width=600, height=600)
         if size == 'large':
             scale = scales.scale(image_field, width=900, height=900)
         else:
             scale = scales.scale(image_field, width=1200, height=1200)
         if scale is not None:
             info['url'] = scale.url
             info['width'] = scale.width
             info['height'] = scale.height
         else:
             info['url'] = IMG
             info['width'] = '1px'
             info['height'] = '1px'
     else:
         info['url'] = IMG
         info['width'] = '1px'
         info['height'] = '1px'
     return info
Example #47
0
class DocumentLinkWidget(object):

    template = ViewPageTemplateFile('document_link.pt')

    def __init__(self, document):
        self.document = IContentListingObject(document)
        self.context = self.document
        self.request = getRequest()

    def get_url(self):
        return self.document.getURL()

    def portal_url(self):
        return api.portal.get().absolute_url()

    def get_css_class(self):
        classes = ['document_link']
        if self.show_icon:
            classes.append(self.document.ContentTypeClass())
        if self.context.is_removed:
            classes.append('removed_document')

        return ' '.join(classes)

    def get_title(self):
        if self.title is not None:
            return self.title
        return self.document.Title().decode('utf-8')

    def render(self, title=None, show_icon=True):
        self.title = title
        self.show_icon = show_icon
        return self.template(self, self.request)

    def is_view_allowed(self):
        return api.user.has_permission('View', obj=self.context.getObject())
Example #48
0
class DocumentLinkWidget(object):

    template = ViewPageTemplateFile('document_link.pt')

    def __init__(self, document):
        self.document = IContentListingObject(document)
        self.context = self.document
        self.request = getRequest()

    def get_url(self):
        return self.document.getURL()

    def portal_url(self):
        return api.portal.get().absolute_url()

    def get_css_class(self):
        classes = ['document_link', self.document.ContentTypeClass()]
        return ' '.join(classes)

    def get_title(self):
        return self.document.Title().decode('utf-8')

    def render(self):
        return self.template(self, self.request)
Example #49
0
    def setUp(self):
        super(TestOpengeverContentListingWithEnabledBumblebee, self).setUp()

        document = create(Builder('document')
                          .with_dummy_content())
        self.obj = IContentListingObject(obj2brain(document))
class TestIndividualRealContentItems(unittest.TestCase):
    layer = CONTENTLISTING_FUNCTIONAL_TESTING

    def setUp(self):
        super(TestIndividualRealContentItems, self).setUp()
        self.portal = self.layer['portal']
        self.folder = self.portal['test-folder']
        self.folder.invokeFactory(
            'Document',
            'mypage',
            title='My Page',
            description='blah',
        )
        self.item = IContentListingObject(self.folder.mypage)
        self.realitem = self.folder.mypage

    def test_printing_item(self):
        self.assertEqual(
            repr(self.item),
            '<plone.app.contentlisting.realobject.RealContentListingObject '
            'instance at /plone/test-folder/mypage>',
        )
        self.assertEqual(
            str(self.item),
            '<plone.app.contentlisting.realobject.RealContentListingObject '
            'instance at /plone/test-folder/mypage>',
        )

    def test_special_getattr_with_underscore(self):
        # looking up attributes starting with _ should always raise
        # AttributeError
        self.assertRaises(AttributeError, self.item.__getattr__, 'foo')

    def test_special_getattr_from_object(self):
        # Asking for an attribute not in the contentlistingobject, should
        # defer lookup to the brain
        self.assertEqual(self.item.absolute_url(), '')
        self.assertEqual(
            repr(self.item.getDataOrigin()),
            '<Document at /plone/test-folder/mypage>',
        )

    def test_item_Title(self):
        self.assertEqual(self.item.Title(), 'My Page')
        self.assertEqual(self.item.Title(), self.realitem.Title())

    def test_item_Description(self):
        self.assertEqual(self.item.Description(), 'blah')
        self.assertEqual(self.item.Description(), self.realitem.Description())

    def test_item_Creator(self):
        self.assertEqual(self.item.Creator(), 'test_user_1_')

    def test_item_getURL(self):
        self.assertEqual(
            self.item.getURL(),
            'http://nohost/plone/test-folder/mypage',
        )
        self.assertEqual(self.item.getURL(), self.realitem.absolute_url())

    def test_item_getSize(self):
        self.assertEqual(self.item.getSize().upper(), '0 KB')

    def test_item_reviewState(self):
        wftool = getToolByName(self.realitem, 'portal_workflow')
        wf = wftool.getInfoFor(self.realitem, 'review_state')
        self.assertEqual(self.item.review_state(), wf)

    def test_item_Type(self):
        self.assertEqual(self.item.Type(), u'Page')
        self.assertEqual(self.item.Type().domain, u'plone')

    def test_item_ContentTypeClass(self):
        # checking the that we print nice strings for css class identifiers
        self.assertEqual(self.item.ContentTypeClass(), 'contenttype-document')

    def test_item_uuid(self):
        uuid = self.item.uuid()
        assert uuid
        assert uuid != self.item.getPath()
Example #51
0
 def test_contentlisting_iteration(self):
     self.assertTrue(IContentListingObject.providedBy(
         [item for item in self.contentlisting][0]))
Example #52
0
 def test_contentlisting_getitem(self):
     self.assertTrue(
         IContentListingObject.providedBy(self.contentlisting[0]))
 def test_money(self):
     article = self.create_content('collective.cart.core.Article')
     instance = IContentListingObject(article)
     instance.shopping_site = mock.Mock()
     instance._realobject.money = self.money('12.40')
     self.assertEqual(instance.money(), instance.shopping_site.format_money())
 def test_gross(self):
     article = self.create_content('collective.cart.core.Article')
     instance = IContentListingObject(article)
     instance.shopping_site = mock.Mock()
     instance.adapter = mock.Mock()
     self.assertEqual(instance.gross(), instance.shopping_site.format_money())
 def test_getSize(self):
     article = self.create_content('collective.cart.core.Article')
     instance = IContentListingObject(article)
     with self.assertRaises(NotImplementedError):
         instance.getSize()
Example #56
0
    def test_dossiers_are_not_bumblebeeable(self):
        dossier = create(Builder('dossier'))
        listing = IContentListingObject(obj2brain(dossier))

        self.assertFalse(listing.is_bumblebeeable())
Example #57
0
 def __eq__(self, other):
     """For comparing two contentlistingobject"""
     other = IContentListingObject(other)
     return self.uuid() == other.uuid()
 def test__repr_(self):
     article = self.create_content('collective.cart.core.Article')
     instance = IContentListingObject(article)
     self.assertEqual(instance.__repr__(), '<slt.content.adapter.content_listing_object.ArticleContentListingObject instance at /plone/collective-cart-core-article>')
Example #59
0
 def __init__(self, document):
     self.document = IContentListingObject(document)
     self.context = self.document
     self.request = getRequest()