def test_apply_filters_checks_is_enabled(self): filter = DummyFilter() filter.is_enabled = lambda: False filters = [filter] apply_filters(filters, '') self.assertEqual([], DummyFilter.called)
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)
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()))
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()))
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
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)
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
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
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)
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)
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 ''
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)
def test_apply_filters(self): filters = [DummyFilter()] apply_filters(filters, '') self.assertEqual([filters[0]], DummyFilter.called)