Opened 8 years ago

Closed 4 years ago

Last modified 4 years ago

#4076 closed New feature (fixed)

Patch to Output Timezone in Date Fields for Atom Feeds

Reported by: Alastair Tse <alastair@…> Owned by: toke
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@…> 8 years ago.

Download all attachments as: .zip

Change History (11)

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

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

  • Cc alastair@… added

comment:2 Changed 8 years ago by toke

  • Needs documentation set
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 8 years ago by toke

  • Keywords sprintsept14 added
  • Needs documentation unset
  • Owner changed from nobody to toke
  • Status changed from new to assigned

Looks reasonable OK for me...

comment:4 Changed 8 years ago by toke

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed in [6233]

comment:5 Changed 6 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 follow-up: Changed 6 years ago by anonymous

  • Has patch unset
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Version changed from SVN to 1.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 5 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 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:9 Changed 4 years ago by aaugustin

  • Easy pickings unset
  • Resolution set to fixed
  • Status changed from reopened to closed
  • 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 4 years ago by aaugustin

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