#15936: Syndication: Turning off autoescape (content:encoded) ------------------------------------------+-------------------------------- Reporter: Brant Steen <brant.steen@…> | Owner: nobody Type: New feature | Status: new Milestone: | Component: Version: 1.3 | contrib.syndication Keywords: syndication, content:encoded | Severity: Normal Has patch: 1 | Triage Stage: Unreviewed | Easy pickings: 0 ------------------------------------------+-------------------------------- A very common element to pull into an RSS feed is the content:encoded element. In a blog, for example, it allows you to put a full entry into your RSS feed, including the HTML in that entry (headings, paragraphs, lists, whatnot).
I couldn't find a way to get this element to work, given the current contrib.syndication module. I would do this: {{{ class ExtendedRSSFeed(feedgenerator.Rss201rev2Feed): """ Create a type of RSS feed that has content:encoded elements. """ def root_attributes(self): attrs = super(ExtendedRSSFeed, self).root_attributes() attrs['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/' return attrs def add_item_elements(self, handler, item): super(ExtendedRSSFeed, self).add_item_elements(handler, item) handler.addQuickElement(u'content:encoded', item['content_encoded']) ... class TheFeed(Feed): feed_type = ExtendedRSSFeed .... def item_extra_kwargs(self, item): return {'content_encoded': self.item_content_encoded(item)} def item_content_encoded(self, item): return "<![CDATA[%s]]>" % item.content }}} But that would generate a feed with all of the HTML bits autoescaped... even if I put an {% autoescape off %} block in the template where the content:encoded was being pulled from. So, instead of being able to stick html tags inside the CDATA, I would just end up with a lot of <h1> stuff. After drilling in and finding the SimplerXMLGenerator, it seemed like the ability to turn off autoescaping could be done at this point, without breaking anyone's current implementations (see patch). Thus, the only change to the above example becomes this: {{{ class ExtendedRSSFeed(feedgenerator.Rss201rev2Feed): """ Create a type of RSS feed that has content:encoded elements. """ def root_attributes(self): attrs = super(ExtendedRSSFeed, self).root_attributes() attrs['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/' return attrs def add_item_elements(self, handler, item): super(ExtendedRSSFeed, self).add_item_elements(handler, item) handler.addQuickElement(u'content:encoded', item['content_encoded'], escape=False) }}} And then content:encoded can be handled through the normal syndication process. -- Ticket URL: <http://code.djangoproject.com/ticket/15936> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.