Opened 10 years ago

Closed 5 years ago

Last modified 5 years ago

#4076 closed New feature (fixed)

Patch to Output Timezone in Date Fields for Atom Feeds

Reported by: Alastair Tse <alastair@…> Owned by: Thomas Kerpe
Component: contrib.syndication Version: 1.1
Severity: Normal Keywords: sprintsept14
Cc: alastair@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently, django.utils.feedgenerator outputs date strings for Atom 1.0 feeds without timezone information. For datetime objects that have tzinfo infor set, we should output the UTC offset if present. The patch attach will simply check whether tzinfo is set to something other than None, and thus have a valid timezone UTF offset that can be shown via strftime().

Attachments (1)

django-svn-feedgenerator-timezone.patch (619 bytes) - added by Alastair Tse <alastair@…> 10 years ago.

Download all attachments as: .zip

Change History (11)

Changed 10 years ago by Alastair Tse <alastair@…>

comment:1 Changed 10 years ago by Alastair Tse <alastair@…>

Cc: alastair@… added

comment:2 Changed 9 years ago by Thomas Kerpe

Needs documentation: set
Triage Stage: UnreviewedAccepted

comment:3 Changed 9 years ago by Thomas Kerpe

Keywords: sprintsept14 added
Needs documentation: unset
Owner: changed from nobody to Thomas Kerpe
Status: newassigned

Looks reasonable OK for me...

comment:4 Changed 9 years ago by Thomas Kerpe

Resolution: fixed
Status: assignedclosed

Fixed in [6233]

comment:5 Changed 8 years ago by max klymyshyn

I don't understand what is wrong, but i had some trouble with django/utils/feedgenerator.py.
Error output is:

Exception Value:  	'datetime.date' object has no attribute 'tzinfo'
Exception Location: /Users/gabonsky/Bin/dist/django/django/utils/feedgenerator.py in rfc2822_date, line 29
Python Executable:  /System/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
Python Version: 	2.5.1

Here is patch for django/django/utils/feedgenerator.py:

29c29
<     if date.tzinfo:
---
>     if hasattr(date, 'tzinfo') and date.tzinfo:

comment:6 Changed 7 years ago by anonymous

Has patch: unset
Resolution: fixed
Status: closedreopened
Version: SVN1.1

Same problem here:

Code:

def items(self):
    return Entry.objects.filter(is_published=True, pub_date__lte=datetime.date.today()).order_by('-pub_date')[:5]

Error:

Exception Type: AttributeError
Exception Value: 'datetime.date' object has no attribute 'tzinfo'
Exception Location: /Library/Python/2.6/site-packages/django/contrib/syndication/feeds.py in get_feed, line 148
Python Executable: /usr/bin/python
Python Version: 2.6.1

comment:7 in reply to:  6 Changed 7 years ago by wiboshu

Replying to anonymous:

Same problem here:

Code:

def items(self):
    return Entry.objects.filter(is_published=True, pub_date__lte=datetime.date.today()).order_by('-pub_date')[:5]

Error:

Exception Type: AttributeError
Exception Value: 'datetime.date' object has no attribute 'tzinfo'
Exception Location: /Library/Python/2.6/site-packages/django/contrib/syndication/feeds.py in get_feed, line 148
Python Executable: /usr/bin/python
Python Version: 2.6.1

You may have used DateField in the model incorrectly.Use DateTimeField instead.

comment:8 Changed 6 years ago by Łukasz Rekucki

Severity: Normal
Type: New feature

comment:9 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset
Resolution: fixed
Status: reopenedclosed
UI/UX: unset

As mentioned by wiboshu, you're using a DateField for pub_date, rather than a DateTimeField.

There's no reason to reject dates here. Indeed, it was a regression introduced in r6233. However, it was fixed as a side effect of #15503.

I'm going to add tests.

Please reopen if you still encounter the issue, with enough information to reproduce it.

comment:10 Changed 5 years ago by Aymeric Augustin

In [16989]:

Ensured that the feeds framework supports both datetimes and dates. Refs #4076.

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