コード例 #1
0
    def test_apply_filters_checks_is_enabled(self):
        filter = DummyFilter()
        filter.is_enabled = lambda: False
        filters = [filter]

        apply_filters(filters, '')
        self.assertEqual([], DummyFilter.called)
コード例 #2
0
ファイル: test_apply_filters.py プロジェクト: CGTIC/Plone_SP
    def test_apply_filters_checks_is_enabled(self):
        filter = DummyFilter()
        filter.is_enabled = lambda: False
        filters = [filter]

        apply_filters(filters, '')
        self.assertEqual([], DummyFilter.called)
コード例 #3
0
    def test_apply_filters_ordering(self):
        filter1 = DummyFilter()
        filter2 = DummyFilter()
        filter2.order = 100
        filters = [filter1, filter2]

        apply_filters(filters, '')
        self.assertEqual([filters[1], filters[0]], DummyFilter.called)
コード例 #4
0
ファイル: test_apply_filters.py プロジェクト: CGTIC/Plone_SP
    def test_apply_filters_ordering(self):
        filter1 = DummyFilter()
        filter2 = DummyFilter()
        filter2.order = 100
        filters = [filter1, filter2]

        apply_filters(filters, '')
        self.assertEqual([filters[1], filters[0]], DummyFilter.called)
コード例 #5
0
    def handle_send2(self, action):
        data, errors = self.extractData()
        if not errors:
            utils = Utils(self.context, self.request)
            public_url = utils.get_public_url()
            html = data['body'].output

            filters = [
                f
                for _, f in getAdapters((self.context, self.request), IFilter)
            ]
            html = apply_filters(filters, html)
            html = html.replace(self.context.absolute_url(),
                                public_url.encode('utf8'))

            categories = set()
            if 'form.widgets.send_to_categories' in self.request.form:
                categories = set(data['send_to_categories'])

            sender = None
            if 'form.widgets.send_from' in self.request.form:
                sender = data['send_from']

            send_email_to_subscribers.delay(data['subject'],
                                            html=html,
                                            categories=categories,
                                            sender=sender)

            api.portal.show_message('Sending emails',
                                    request=self.request,
                                    type='info')
            self.request.response.redirect('%s/@@announcements-controlpanel' %
                                           (self.context.absolute_url()))
コード例 #6
0
    def handle_send(self, action):
        data, errors = self.extractData()
        if not errors:
            addresses = data['send_to_custom'] or []
            for group in data['send_to_groups'] or []:
                for user in api.user.get_users(groupname=group):
                    email = user.getProperty('email')
                    if email:
                        addresses.append(email)
            for username in data['send_to_users'] or []:
                user = api.user.get(username=username)
                if user:
                    email = user.getProperty('email')
                    if email:
                        addresses.append(email)

            try:
                sender = data['send_from']
            except Exception:
                sender = None

            utils = Utils(self.context, self.request)
            public_url = utils.get_public_url()
            html = data['body'].output

            filters = [f for _, f in getAdapters((self.context, self.request), IFilter)]
            html = apply_filters(filters, html)
            html = html.replace(self.context.absolute_url(), public_url.encode('utf8'))

            send_email.delay(list(set(addresses)), data['subject'], html=html, sender=sender)
            self.request.response.redirect('%s/@@announcements-controlpanel' % (
                self.context.absolute_url()))
コード例 #7
0
    def convert(self, orig, data, **kwargs):
        context = kwargs.get('context')
        request = getattr(getSite(), 'REQUEST', None)
        filters = [f for _, f in getAdapters((context, request), IFilter)]

        res = apply_filters(filters, orig)
        data.setData(res)
        return data
コード例 #8
0
    def convert(self, orig, data, **kwargs):
        context = kwargs.get('context')
        request = getattr(getSite(), 'REQUEST', None)
        filters = [f for _, f in getAdapters((context, request), IFilter)]

        res = apply_filters(filters, orig)
        data.setData(res)
        return data
コード例 #9
0
ファイル: test_apply_filters.py プロジェクト: CGTIC/Plone_SP
    def test_apply_filters_handles_return_none(self):
        class DummyFilterReturningNone(DummyFilter):
            def __call__(self, data):
                return None
        filter = DummyFilterReturningNone()

        res = apply_filters([filter], '')
        self.assertEqual('', res)
コード例 #10
0
    def test_apply_filters_handles_return_none(self):
        class DummyFilterReturningNone(DummyFilter):
            def __call__(self, data):
                return None

        filter = DummyFilterReturningNone()

        res = apply_filters([filter], '')
        self.assertEqual('', res)
コード例 #11
0
ファイル: html2captioned.py プロジェクト: nacho22martin/tesis
 def convert(self, orig, data, filename=None, **kwargs):
     """apply plone.outputfilters filters"""
     # XXX deprecate
     context = kwargs.get('context')
     request = getattr(getSite(), 'REQUEST', None)
     filters = [f for _, f in getAdapters((context, request), IFilter)]
     
     res = apply_filters(filters, orig)
     data.setData(res)
     return data
コード例 #12
0
 def __call__(self):
     content = self.data.get('content')
     if content:
         # Here we skip legacy portal_transforms and call
         # plone.outputfilters directly by purpose
         filters = [f for _, f
                    in getAdapters((self.context, self.request), IFilter)]
         content = apply_filters(filters, content)
     else:
         content = u'<p></p>'
     return u"<html><body>%s</body></html>" % content
コード例 #13
0
ファイル: layoutbehavior.py プロジェクト: CGTIC/Plone_SP
    def __call__(self):
        """Render the contents of the "content" field coming from
        the ILayoutAware behavior.

        This result is supposed to be transformed by plone.app.blocks.
        """
        layout = ILayoutAware(self.context).content
        # Here we skip legacy portal_transforms and call plone.outputfilters
        # directly by purpose
        filters = [f for _, f
                   in getAdapters((self.context, self.request), IFilter)]
        return apply_filters(filters, layout)
コード例 #14
0
    def __call__(self):
        """Render the contents of the "content" field coming from
        the ILayoutAware behavior.

        This result is supposed to be transformed by plone.app.blocks.
        """
        layout = ILayoutAware(self.context).content
        # Here we skip legacy portal_transforms and call plone.outputfilters
        # directly by purpose
        filters = [
            f for _, f in getAdapters((self.context, self.request), IFilter)
        ]
        return apply_filters(filters, layout)
コード例 #15
0
ファイル: syndication.py プロジェクト: espenmn/castle.cms
    def render_content_core(self):
        try:
            layout = getLayout(self.context)
        except TypeError:
            return super(LayoutAwareItem, self).render_content_core()
        req = getRequest()
        filters = [f for _, f in getAdapters((self.context, req), IFilter)]
        layout = apply_filters(filters, layout)
        dom = getHTMLSerializer(layout)
        tiles.renderTiles(req, dom.tree,
                          self.context.absolute_url() + '/layout_view')
        gridsystem.merge(req, dom.tree)

        content = contentpanel_xpath(dom.tree)
        if len(content) > 0:
            return tostring(content[0])
        return ''
コード例 #16
0
    def __call__(self):
        """Render the contents of the "content" field coming from
        the ILayoutAware behavior.

        This result is supposed to be transformed by plone.app.blocks.
        """
        behavior_data = ILayoutAware(self.context)
        if behavior_data.contentLayout:
            from plone.app.blocks.utils import resolveResource
            try:
                path = behavior_data.contentLayout
                resolved = resolveResource(path)
                layout = applyTilePersistent(path, resolved)
            except (NotFound, RuntimeError):
                layout = ''
        else:
            layout = behavior_data.content

        if not layout:
            from plone.app.blocks.utils import resolveResource
            registry = getUtility(IRegistry)
            try:
                path = registry['%s.%s' % (
                    DEFAULT_CONTENT_LAYOUT_REGISTRY_KEY,
                    self.context.portal_type.replace(' ', '-'))]
            except (KeyError, AttributeError):
                path = None
            try:
                path = path or registry[DEFAULT_CONTENT_LAYOUT_REGISTRY_KEY]
                resolved = resolveResource(path)
                layout = applyTilePersistent(path, resolved)
            except (KeyError, NotFound, RuntimeError):
                pass

        if not layout:
            layout = ERROR_LAYOUT

        # Here we skip legacy portal_transforms and call plone.outputfilters
        # directly by purpose
        filters = [f for _, f
                   in getAdapters((self.context, self.request), IFilter)]
        return apply_filters(filters, layout)
コード例 #17
0
ファイル: test_apply_filters.py プロジェクト: CGTIC/Plone_SP
    def test_apply_filters(self):
        filters = [DummyFilter()]

        apply_filters(filters, '')
        self.assertEqual([filters[0]], DummyFilter.called)
コード例 #18
0
    def test_apply_filters(self):
        filters = [DummyFilter()]

        apply_filters(filters, '')
        self.assertEqual([filters[0]], DummyFilter.called)