Opened 17 years ago

Closed 13 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: dev
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: no

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

Download all attachments as: .zip

Change History (12)

comment:1 by Gary Wilson <gary.wilson@…>, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Rob Hudson <treborhudson@…>, 17 years ago

Cc: treborhudson@… added
Component: UncategorizedContrib apps
Owner: changed from Jacob to Adrian Holovaty
Version: 0.950.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.

by Rob Hudson <treborhudson@…>, 17 years ago

Attachment: feeds.diff added

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

by Rob Hudson <treborhudson@…>, 17 years ago

Attachment: feeds.2.diff added

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

comment:3 by Jacob, 16 years ago

Triage Stage: Design decision neededSomeday/Maybe

by sf, 16 years ago

Another approach to solve that problem.

comment:4 by sf, 16 years ago

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 by Seemant Kulleen, 15 years ago

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 by Seemant Kulleen, 15 years ago

Version: 0.961.0

comment:7 by Gabriel Hurley, 13 years ago

Component: Contrib appscontrib.syndication

comment:8 by Łukasz Rekucki, 13 years ago

Severity: Normal
Type: New feature

comment:9 by Stephen Burrows, 13 years ago

Easy pickings: unset
Resolution: fixed
Status: newclosed
Version: 1.0SVN

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