Localized timezone support (Review Board)

Review Request #2725 — Created Dec. 1, 2011 and submitted

Information

Review Board

Reviewers

Adds per-user timezone support, relying on the USE_TZ feature from the Django dev branch.

Using this method, datetime's are stored in the database in UTC and are timezone-aware. Datetime objects are stored with tzinfo=utc, so that they can be easily converted into any other timezone when retrieved from the database.
Middleware was created in the accounts app which activates the user's timezone in each session. A timezone field is added to the user model to store their local time, which they can change in "My account". The user profile and admin forms use TimeZoneField, which is pre-populated with all the available timezone choices. Templates which show dates and/or times are changed to display the user's local time with the {% load tz %}{% localtime on %} tags.

 
Description From Last Updated

"timezone"

chipx86chipx86

One per line, ending with commas.

chipx86chipx86

Should be after the siteconfig stuff. Alphabetical order.

chipx86chipx86

Group these together. pytz is a third-party module.

chipx86chipx86

Mind adding a docstring on this?

chipx86chipx86

It's possible that there isn't a Profile yet. For example, if the user just logged in for the very first …

chipx86chipx86

Why did these move?

chipx86chipx86

Get the profile first, in a separate call. Should be self.request.user.get_profile().

chipx86chipx86

Move semicolon out of the trans block.

ME medanat

"Time Zone:" if we're going to be consistent with other places.

chipx86chipx86

These should be single-space indented.

mike_conleymike_conley

Just to check, will the result we get back from the API for comparison be in the expected timezone?

chipx86chipx86

Given that this e-mail goes out to admins, I don't think we want to apply the user's timezone to it. …

chipx86chipx86
ME
  1. 
      
  2. Show all issues
    Move semicolon out of the trans block.
    1. And by semicolon I mean colon.
    2. Actually, it should stay where it is. That may localize differently.
  3. 
      
chipx86
  1. 
      
  2. reviewboard/accounts/backends.py (Diff revision 1)
     
     
    Show all issues
    "timezone"
  3. Show all issues
    One per line, ending with commas.
  4. reviewboard/accounts/forms.py (Diff revision 1)
     
     
    Show all issues
    Should be after the siteconfig stuff. Alphabetical order.
  5. reviewboard/accounts/middleware.py (Diff revision 1)
     
     
     
     
    Show all issues
    Group these together. pytz is a third-party module.
  6. reviewboard/accounts/middleware.py (Diff revision 1)
     
     
    Show all issues
    Mind adding a docstring on this?
  7. reviewboard/accounts/middleware.py (Diff revision 1)
     
     
    Show all issues
    It's possible that there isn't a Profile yet. For example, if the user just logged in for the very first time, and is using something like LDAP auth, the User will exist but the Profile won't have been created just yet.
  8. reviewboard/reviews/datagrids.py (Diff revision 1)
     
     
     
     
     
    Show all issues
    Why did these move?
    1. I saw that they weren't in alphabetical order. Why are they in the order they are?
  9. reviewboard/reviews/datagrids.py (Diff revision 1)
     
     
     
    Show all issues
    Get the profile first, in a separate call.
    
    Should be self.request.user.get_profile().
  10. reviewboard/reviews/models.py (Diff revision 1)
     
     
    I feel like we do this so often that we should really have a util function that does it.
  11. Show all issues
    "Time Zone:" if we're going to be consistent with other places.
  12. Show all issues
    Just to check, will the result we get back from the API for comparison be in the expected timezone?
    1. I'll check on that.
    2. Was this issue ever resolved or investigated?
    3. It should have NO localtime tags, anything that isn't shown to the viewer is in UTC.
  13. Show all issues
    Given that this e-mail goes out to admins, I don't think we want to apply the user's timezone to it. We should, however, make sure to list the timezone in the format. That's using "T"
  14. 
      
mike_conley
  1. Dave:
    
    This looks pretty good!  Just found one further nit below.
    
    -Mike
  2. reviewboard/reviews/models.py (Diff revision 1)
     
     
    Seconded.
  3. reviewboard/templates/accounts/prefs.html (Diff revision 1)
     
     
     
    Show all issues
    These should be single-space indented.
  4. 
      
DD
DD
mike_conley
  1. This looks good to me.  Great work, Dave!
    
    -Mike
  2. 
      
david
  1. Ship It!
  2. 
      
DD
DD
DD
Review request changed
Status:
Completed