def get(self, request): """Generates the RSS feed.""" page = request.pages.current # Write the feed headers. feed = DefaultFeed( title=page.title, link=page.get_absolute_url(), description=page.meta_description, ) # Write the feed items. for article in self.get_queryset()[:30]: feed.add_item( title=article.title, link=article.get_absolute_url(), description=process_html(article.summary or article.content), pubdate=article.date, ) # Write the response. content = feed.writeString("utf-8") response = HttpResponse(content) response["Content-Type"] = feed.mime_type response["Content-Length"] = len(content) return response
def get(self, request): """Generates the RSS feed.""" page = request.pages.current # Write the feed headers. feed = DefaultFeed( title=page.title, link=page.get_absolute_url(), description=page.meta_description, ) # Write the feed items. for article in self.get_queryset()[:30]: feed.add_item( title=article.title, link=article.get_absolute_url(), description=process_html( article.summary or article.content), pubdate=article.date, ) # Write the response. content = feed.writeString("utf-8") response = HttpResponse(content) response["Content-Type"] = feed.mime_type response["Content-Length"] = len(content) return response
def html(text): # Return empty string if no text if not text: return "" # Process HTML through cms parser text = process_html(text) # Load text into BS4 soup = BeautifulSoup(text, 'html.parser') # Unwrap all image tags for img in soup.find_all('img'): img.parent.unwrap() def wrap(to_wrap, wrap_in): contents = to_wrap.replace_with(wrap_in) wrap_in.append(contents) # Wrap all table tags for table in soup.find_all('table'): div = soup.new_tag('div') div['class'] = 'wys-TableWrap' wrap(table, div) # Wrap all iframes in intrinsic containers for iframe in soup.find_all('iframe'): for attr in ['width', 'height']: if iframe.get(attr, None): del iframe[attr] wrapper = soup.new_tag('div', **{'class': 'wys-Intrinsic'}) iframe.wrap(wrapper) # Force return string version of BS4 obj return mark_safe(str(soup))
def html(text): ''' Processes HTML text. The text is checked for permalinks embedded in <a> tags, expanding the permalinks to their referenced URL. Images containing a permalink source are checked for size and thumbnailed as appropriate. ''' if not text: return '' text = process_html(text) return mark_safe(text)
def html(text): """ Processes HTML text. The text is checked for permalinks embedded in <a> tags, expanding the permalinks to their referenced URL. Images containing a permalink source are checked for size and thumbnailed as appropriate. """ if not text: return "" text = process_html(text) return mark_safe(text)