Opened 6 years ago

Last modified 5 years ago

#13896 assigned New feature

Change language to dynamic attribute in syndication feed generator

Reported by: jedie Owned by: Jason Kotenko
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 Jason Kotenko 6 years ago.
SVN Diff
django_13896_2.diff (3.7 KB) - added by Jason Kotenko 6 years ago.
SVN Diff
django_13896_20110506.diff (3.6 KB) - added by Jason Kotenko 6 years ago.
Latest SVN Diff

Download all attachments as: .zip

Change History (15)

comment:1 Changed 6 years ago by Matthias Kestenholz

Needs documentation: set
Triage Stage: UnreviewedAccepted

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 6 years ago by Jason Kotenko

Owner: changed from nobody to Jason Kotenko
Status: newassigned

comment:3 Changed 6 years ago by Jason Kotenko

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 6 years ago by Jason Kotenko

Attachment: django_13896.diff added

SVN Diff

comment:4 Changed 6 years ago by Jannis Leidel

Needs tests: set

Changed 6 years ago by Jason Kotenko

Attachment: django_13896_2.diff added

SVN Diff

comment:5 Changed 6 years ago by Jason Kotenko

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 6 years ago by Chris Morgan

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 6 years ago by Graham King

Severity: Normal
Type: New feature

comment:8 Changed 6 years ago by patchhammer

Easy pickings: unset
Patch needs improvement: set

django_13896_2.diff fails to apply cleanly on to trunk

Changed 6 years ago by Jason Kotenko

Attachment: django_13896_20110506.diff added

Latest SVN Diff

comment:9 Changed 6 years ago by Jason Kotenko

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

comment:10 Changed 6 years ago by Jason Kotenko

Patch needs improvement: unset

comment:11 Changed 5 years ago by Julien Phalip

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 5 years ago by Aymeric Augustin

#7039 was closed as a duplicate.

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