<s> from django . conf import settings <EOL> from django . utils . encoding import smart_str <EOL> import pytz <EOL> default_tz = pytz . timezone ( getattr ( settings , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> def localdatetime ( field_name ) : <EOL> def get_datetime ( instance ) : <EOL> return getattr ( instance , field_name ) <EOL> def set_datetime ( instance , value ) : <EOL> return setattr ( instance , field_name , value ) <EOL> def make_local_property ( get_tz ) : <EOL> def get_local ( instance ) : <EOL> tz = get_tz ( instance ) <EOL> if not hasattr ( tz , "<STR_LIT>" ) : <EOL> tz = pytz . timezone ( smart_str ( tz ) ) <EOL> dt = get_datetime ( instance ) <EOL> if dt . tzinfo is None : <EOL> dt = default_tz . localize ( dt ) <EOL> return dt . astimezone ( tz ) <EOL> def set_local ( instance , dt ) : <EOL> if dt . tzinfo is None : <EOL> tz = get_tz ( instance ) <EOL> if not hasattr ( tz , "<STR_LIT>" ) : <EOL> tz = pytz . timezone ( smart_str ( tz ) ) <EOL> dt = tz . localize ( dt ) <EOL> dt = dt . astimezone ( default_tz ) <EOL> return set_datetime ( instance , dt ) <EOL> return property ( get_local , set_local ) <EOL> return make_local_property </s>
