def show(self): """ Removes all status messages (including HTML) and returns them for display. """ context = self.context annotations = IAnnotations(context) msgs = annotations.get(STATUSMESSAGEKEY, context.cookies.get(STATUSMESSAGEKEY)) msgs = msgs and adapter._decodeCookieValue(msgs) or [] html_msgs = annotations.get(HTMLMESSAGEKEY, context.cookies.get(HTMLMESSAGEKEY)) html_msgs = html_msgs and adapter._decodeCookieValue(html_msgs) or [] for msg in html_msgs: msg.message = literal(sanitize(msg.message, cleaner=msgcleaner, wrap=None)) value = msgs + html_msgs # clear the existing cookie entries, except on responses that don't # actually render in the browser (really, these shouldn't render # anything so we shouldn't get to this message, but some templates # are sloppy). if self.context.response.getStatus() not in (301, 302, 304): context.cookies[STATUSMESSAGEKEY] = None context.response.expireCookie(STATUSMESSAGEKEY, path='/') annotations[STATUSMESSAGEKEY] = None context.cookies[HTMLMESSAGEKEY] = None context.response.expireCookie(HTMLMESSAGEKEY, path='/') annotations[HTMLMESSAGEKEY] = None return value
def getNews(self, limit=0, strip_links=0): """Fetch campaign-related News and return the relevant parts""" subject = aq_inner(self.root).Subject() portal_path = self.ptool.getPortalPath() lang = self.context.portal_languages.getPreferredLanguage() now = DateTime() pc = getToolByName(self.context, 'portal_catalog') res = pc(portal_type='News Item', Language=['en', ''], effective={'query': now, 'range': 'max'}, sort_order='reverse', sort_on='effective', path=['%s/en' % portal_path, '%s/%s' % (portal_path, self.pref_lang), self.subsite_path], Subject=subject) if len(res) and limit > 0: res = res[:limit] for r in res: obj = r.getObject() # now get the correct translation, or use the EN one as fallback obj = obj.getTranslation(self.pref_lang) or obj link = "%s/@@hw.telescope?path=%s" % (self.getNewsfolderUrl(), '/'.join(obj.getPhysicalPath())) img_url = obj.getImage() and '/'.join(obj.getImage().getPhysicalPath()) or '' img_url = img_url.replace('/osha/portal', 'https://osha.europa.eu') description = obj.Description().strip() != '' and obj.Description() or obj.getText() if not isinstance(description, unicode): description = description.decode('utf-8') if strip_links: # Strip links from the news text description = laundryutils.sanitize(description, NewsCleaner) date = obj.effective() yield dict(link=link, img_url=img_url, description=description, title=obj.Title(), day=date.day(), month=date.pMonth(), year=date.year())
def show(self): """ Removes all status messages (including HTML) and returns them for display. """ context = self.context annotations = IAnnotations(context) msgs = annotations.get(STATUSMESSAGEKEY, context.cookies.get(STATUSMESSAGEKEY)) msgs = msgs and adapter._decodeCookieValue(msgs) or [] html_msgs = annotations.get(HTMLMESSAGEKEY, context.cookies.get(HTMLMESSAGEKEY)) html_msgs = html_msgs and adapter._decodeCookieValue(html_msgs) or [] for msg in html_msgs: msg.message = literal( sanitize(msg.message, cleaner=msgcleaner, wrap=None)) value = msgs + html_msgs # clear the existing cookie entries, except on responses that don't # actually render in the browser (really, these shouldn't render # anything so we shouldn't get to this message, but some templates # are sloppy). if self.context.response.getStatus() not in (301, 302, 304): context.cookies[STATUSMESSAGEKEY] = None context.response.expireCookie(STATUSMESSAGEKEY, path='/') annotations[STATUSMESSAGEKEY] = None context.cookies[HTMLMESSAGEKEY] = None context.response.expireCookie(HTMLMESSAGEKEY, path='/') annotations[HTMLMESSAGEKEY] = None return value
def html(self): htmlfile = open("%s/%s.html" % (self.tmpdir, self.__name__), 'r') html = htmlfile.read() htmlfile.close() html = safe_unicode(html) try: html = laundryutils.sanitize(html, HTMLCleaner) except Exception, err: html = ''
def sanitize(self, *a, **kw): from htmllaundry.utils import sanitize return sanitize(*a, **kw)
def toFieldValue(self, value): data = super(HtmlDataConverter, self).toFieldValue(value) if data: data = sanitize(data) return data