def template_localtime(value, use_tz=None):
 should_convert = (isinstance(value, datetime) and (settings.USE_TZ if (use_tz is None) else use_tz) and (not is_naive(value)) and getattr(value, 'convert_to_local_time', True))
 return (localtime(value) if should_convert else value)

def template_localtime ( value , use_tz = None ) : should_convert = ( isinstance ( value , datetime ) and ( settings . USE_TZ if ( use_tz is None ) else use_tz ) and ( not is_naive ( value ) ) and getattr ( value , 'convert_to_local_time' , True ) ) return ( localtime ( value ) if should_convert else value )
checks if value is a datetime and converts it to local time if necessary .