def __call__(self): self.request.response.setHeader('Content-type', 'application/json') cutils = Utils(self.context, self.request) data = { 'title': self.context.title, 'id': self.context.id, 'has_image': utils.has_image(self.context), 'youtube_url': None } rendered = None if self.context.portal_type in ('Image',): pass elif self.context.portal_type == 'Video': fi = getattr(self.context, 'file', None) data.update({ 'youtube_url': cutils.get_youtube_url(self.context), 'content_type': getattr( fi, 'original_content_type', getattr(fi, 'contentType', None)) }) else: feed = SearchFeed(api.portal.get()) adapter = queryMultiAdapter((self.context, feed), IFeedItem) if adapter is not None: rendered = adapter.render_content_core().strip() return json.dumps({ 'portal_type': self.context.portal_type, 'url': self.context.absolute_url(), 'data': data, 'rendered': rendered })
def getContent(self, version): alsoProvides(self.request, IVersionViewLayer) feed = SearchFeed(api.portal.get()) adapter = queryMultiAdapter((version, feed), IFeedItem) content = adapter.render_content_core().strip() noLongerProvides(self.request, IVersionViewLayer) if not content: # try old fashioned way... bah! content = version.restrictedTraverse(version.defaultView())() dom = fromstring(content) return ''.join([tostring(el) for el in dom.cssselect('#content-core > *')]) else: dom = fromstring(content) return ''.join([tostring(el) for el in dom.cssselect('[data-panel] > *')])
def __call__(self): valid = True for link in getOutgoingLinks(self.context): state = api.content.get_state(obj=link.to_object, default='published') if state != 'published': valid = False break headers_ordered = True try: feed = SearchFeed(api.portal.get()) adapter = queryMultiAdapter((self.context, feed), IFeedItem) html = adapter.render_content_core().strip() except Exception: html = '' if html: dom = fromstring(html) last = 1 for el in dom.cssselect('h1,h2,h3,h4,h5,h6'): idx = int(el.tag[-1]) if idx - last > 1: # means they skipped from say h1 -> h5 # h1 -> h2 is allowed headers_ordered = False break last = idx is_template = False if ITemplate.providedBy(self.context): is_template = True self.request.response.setHeader('Content-type', 'application/json') return json.dumps({ 'title': self.context.Title(), 'id': self.context.getId(), 'description': self.context.Description(), 'linksValid': valid, 'headersOrdered': headers_ordered, 'html': html_parser.unescape(html), 'template': is_template })