<s> import pytz <EOL> from django . db import models <EOL> from django . conf import settings <EOL> from django . core . exceptions import AppRegistryNotReady <EOL> try : <EOL> from django . contrib . auth import get_user_model <EOL> User = get_user_model ( ) <EOL> except ImportError : <EOL> from django . contrib . auth . models import User <EOL> except AppRegistryNotReady : <EOL> from django . contrib . auth . models import User <EOL> def get_default_timezone ( ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( settings , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TimezoneStore ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> user = models . OneToOneField ( User , related_name = '<STR_LIT>' ) <EOL> timezone = models . CharField ( max_length = <NUM_LIT> , default = get_default_timezone ) <EOL> def __unicode__ ( self ) : <EOL> return self . timezone <EOL> def get_timezone_for_user ( self ) : <EOL> """<STR_LIT>""" <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> return self . _timezone <EOL> try : <EOL> tz = self . timezone <EOL> except TimezoneStore . DoesNotExist : <EOL> tz , created = TimezoneStore . objects . get_or_create ( user = self ) <EOL> self . _timezone = tz . timezone <EOL> return tz . timezone <EOL> def get_timezone_info_for_user ( self ) : <EOL> """<STR_LIT>""" <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> return self . _timezone_info <EOL> self . _timezone_info = pytz . timezone ( self . tz ) <EOL> return self . _timezone_info <EOL> User . add_to_class ( '<STR_LIT>' , property ( get_timezone_for_user ) ) <EOL> User . add_to_class ( '<STR_LIT>' , property ( get_timezone_info_for_user ) ) </s>
