Opened 9 years ago

Closed 4 years ago

#3624 closed New feature (fixed)

Syndication could be friendlier to non Django templating languages

Reported by: andy@… Owned by: nobody
Component: contrib.syndication Version: master
Severity: Normal Keywords:
Cc: treborhudson@… Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:

Description

To specify the title or description for a feed, the syndication module will accept a path to a template:

"You can also change the names of these two templates by specifying title_template and description_template as attributes of your Feed class."
http://www.djangoproject.com/documentation/syndication/

This makes it a little unfriendly to non Django templating languages since it will use the loader defined in Django. It would be nice if it took a template object and rendered that, as opposed to using a string, using the default Django loader and rendering the template. This would allow me to easily use my templating language in my feed module, without interfering with the underlying module.

Django-0.95.1

contrib/syndication/feeds.py:

try:

description_tmp = loader.get_template(self.description_template_name)

except TemplateDoesNotExist:

description_tmp = Template('{{ obj }}')

Attachments (3)

feeds.diff (1.1 KB) - added by Rob Hudson <treborhudson@…> 8 years ago.
Patch against trunk. I can add docs if this looks good.
feeds.2.diff (4.7 KB) - added by Rob Hudson <treborhudson@…> 8 years ago.
Cleaned up, tested override and default, and added docs.
item_title_and_description_methods.patch (2.6 KB) - added by sf 7 years ago.
Another approach to solve that problem.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 9 years ago by Gary Wilson <gary.wilson@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 8 years ago by Rob Hudson <treborhudson@…>

  • Cc treborhudson@… added
  • Component changed from Uncategorized to Contrib apps
  • Owner changed from jacob to adrian
  • Version changed from 0.95 to 0.96

Or similar to the feed title and description, have the ability for the subclass to create methods of "item_title" or "item_description". I created a patch that will allow the user to add these methods that return a Template object.

Changed 8 years ago by Rob Hudson <treborhudson@…>

Patch against trunk. I can add docs if this looks good.

Changed 8 years ago by Rob Hudson <treborhudson@…>

Cleaned up, tested override and default, and added docs.

comment:3 Changed 8 years ago by jacob

  • Triage Stage changed from Design decision needed to Someday/Maybe

Changed 7 years ago by sf

Another approach to solve that problem.

comment:4 Changed 7 years ago by sf

The previous patch takes a slightly different approach than the two patches already submitted. In fact, it takes the same approach as the other syndication fields: item_title() and item_description() methods are responsible for fetching the content of both fields, and by default it will fetch a template or use {{ obj }}. Thus, one is free to override those to use its own templating or to just provide the value without having to use a template.

I think this is fine since often, those method would just be:

   def item_title(self, item):
      return item.title
   def item_description(self, item):
      return item.contents

Note that the current patch doesn't include docs, and that the "current_site" argument for the template has been lost in the process. It can be reintroduced though.

comment:5 Changed 7 years ago by seemant

This would help me, personally, in the case of syndication feeds on the new comment model. The unicode() function in comments makes the title of each comment into the first 50 words of the comment itself. I'd prefer to override that in the feed (akin to the old 0.96 behaviour of "By <author> on <date>" instead.

comment:6 Changed 7 years ago by seemant

  • Version changed from 0.96 to 1.0

comment:7 Changed 4 years ago by gabrielhurley

  • Component changed from Contrib apps to contrib.syndication

comment:8 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:9 Changed 4 years ago by melinath

  • Easy pickings unset
  • Resolution set to fixed
  • Status changed from new to closed
  • Version changed from 1.0 to SVN

The methods described above were added with changeset r12338, which moved syndication to class-based views. This means that anyone who wants to use an alternate template language can just override the method and do whatever they want.

Note: See TracTickets for help on using tickets.
Back to Top