Ask Your Question
1

For Discussion: Updating Askbot for USE_TZ=True in Django>=1.4

asked 2014-08-14 11:35:13 -0500

geekofalltrades's avatar

I've been working on integrating Askbot with a commercial product developed in Django 1.5.8. A major sticking point I ran into was the use of timezone-aware datetime objects in the existing product, which cause the "Can't subtract offset-naive and offset-aware datetimes" exception. (I can't post links, but search for it on this forum, and you'll find at least one thread.)

I've created a fix. It was a basically a find-and-replace operation, replacing all instances of datetime.datetime.now() in the code with timezone.now(), and adding an import: from django.utils import timezone. timezone.now() is a Django utility function that returns a timezone-aware or timezone-naive datetime object according to the USE_TZ setting. I also had to update some datetime.datetime instances with a tzinfo attribute, and I had to replace import datetime in all migration scripts with from south.utils import datetime_utils as datetime, which is a South compatibility layer for USE_TZ.

I could contribute this fix back, but it would force dependency updates. Django's timezone module was introduced in Django 1.4, so versions of Django<1.4 would no longer be compatible with Askbot. Versions of South before datetime_utils was introduced would also no longer be compatible. It would be possible to write compatibility patches, eg:

try:
    from django.utils import timezone
except ImportError:
    from askbot.utils import timezone

...but I'm hesitant to do so, because a lot of the work I've had to do in getting Askbot to work in Django 1.5.8 has been undoing or working around prior patches. I would rather contribute work that moves Askbot forward.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-08-15 02:24:02 -0500

Evgeny's avatar

updated 2014-08-15 02:25:28 -0500

The issue is that USE_TZ = True makes local time rendered in the html templates, essentially "personalizing" the pages per timezone. This makes it harder to cache template fragments.

Local time can be rendered by Javascript based on the UTC timestamps as we have now or a reference time zone. If there is a way to make timestamp display in Askbot independent on the USE_TZ setting and allow the integrators make their own choice of that setting - it might be worth getting that done.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-08-14 11:35:13 -0500

Seen: 10,072 times

Last updated: Aug 15 '14