Opened 5 years ago

Last modified 4 years ago

#13896 assigned New feature

Change language to dynamic attribute in syndication feed generator

Reported by: jedie Owned by: jasonkotenko
Component: contrib.syndication Version: master
Severity: Normal Keywords:
Cc: kotenko@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

In my project, the language is dynamic and not hardcoded in settings. IMHO there is no way to change the language in syndication feed generator without a hack.

Change language to dynamic attribute in syndication feed generator:

  • django/contrib/syndication/views.py

     
    104104            subtitle = self.__get_dynamic_attr('subtitle', obj),
    105105            link = link,
    106106            description = self.__get_dynamic_attr('description', obj),
    107             language = settings.LANGUAGE_CODE.decode(),
     107            language=self.__get_dynamic_attr('language', obj, settings.LANGUAGE_CODE.decode()),
    108108            feed_url = add_domain(current_site.domain,
    109109                    self.__get_dynamic_attr('feed_url', obj) or request.path),
    110110            author_name = self.__get_dynamic_attr('author_name', obj),

Attachments (3)

django_13896.diff (1.5 KB) - added by jasonkotenko 4 years ago.
SVN Diff
django_13896_2.diff (3.7 KB) - added by jasonkotenko 4 years ago.
SVN Diff
django_13896_20110506.diff (3.6 KB) - added by jasonkotenko 4 years ago.
Latest SVN Diff

Download all attachments as: .zip

Change History (15)

comment:1 Changed 5 years ago by mk

  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I think this makes sense. The language of the feed might be encoded inside the URL too and isn't fixed to LANGUAGE_CODE from the site settings.

This change has to be documented.

comment:2 Changed 4 years ago by jasonkotenko

  • Owner changed from nobody to jasonkotenko
  • Status changed from new to assigned

comment:3 Changed 4 years ago by jasonkotenko

  • Cc kotenko@… added
  • Needs documentation unset

Adding SVN diff that includes the patch included above and a patch for the docs, mentioning that now the language attribute can be set, and otherwise defaults to the project-wide setting for LANGUAGE_CODE.

Changed 4 years ago by jasonkotenko

SVN Diff

comment:4 Changed 4 years ago by jezdez

  • Needs tests set

Changed 4 years ago by jasonkotenko

SVN Diff

comment:5 Changed 4 years ago by jasonkotenko

  • Needs tests unset

New diff entered, includes Fix, Docs, and Regression Test. Use the second patch, as the first is wrong. Thanks.

comment:6 Changed 4 years ago by ChrisMorgan

It would be very nice if this could get put into Django 1.3. I've had to hack this into shape myself to get it working for the new Inkscape website which can make news feeds for any supported language, using request.LANGUAGE_CODE rather than settings.LANGUAGE_CODE (seems to me that that is going to be a common request; I think it would be good if Feed stored the Request - but that's another ticket).

See http://bazaar.launchpad.net/~inkscape-webadmin/inkscape-web/inkscape-web/revision/62 for how I ended up wedging it in (1.2.5): and I know it won't work even back in 1.2.3 due to a couple of changes in the Django code, without providing another couple of methods. Not very maintainable :-(

comment:7 Changed 4 years ago by graham_king

  • Severity set to Normal
  • Type set to New feature

comment:8 Changed 4 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

django_13896_2.diff fails to apply cleanly on to trunk

Changed 4 years ago by jasonkotenko

Latest SVN Diff

comment:9 Changed 4 years ago by jasonkotenko

Looks like bitrot got the best of the last one. New diff uploaded, new test passes under "settings=test_sqlite".

comment:10 Changed 4 years ago by jasonkotenko

  • Patch needs improvement unset

comment:11 Changed 4 years ago by julien

  • Patch needs improvement set
  • UI/UX unset

The patch looks pretty good but there is one slight inconsistency. The doc says:

You  can set the language for a feed by specifying an attribute :attr:`language`,  using the ***same format*** as the project-wide setting :setting:`LANGUAGE_CODE`.

... yet the code is:

language = self.__get_dynamic_attr('language', obj, settings.LANGUAGE_CODE.decode()),

So the LANGUAGE_CODE setting is decoded whereas the language API attribute isn't. Ideally the behaviour should be normalised and made consistent.

comment:12 Changed 4 years ago by aaugustin

#7039 was closed as a duplicate.

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