11import copy
2+ import sys
23from django .core .exceptions import ImproperlyConfigured
34from django .db .backends .signals import connection_created
45from django .conf import settings
@@ -117,44 +118,31 @@ def pop(name, default=None):
117118 password = pop ('PASSWORD' )
118119 options = pop ('OPTIONS' , {})
119120
120- if port :
121- try :
122- port = int (port )
123- except ValueError :
124- raise ImproperlyConfigured ("If set, PORT must be an integer "
125- "(got %r instead)" % port )
126-
127121 self .operation_flags = options .pop ('OPERATIONS' , {})
128122 if not any (k in ['save' , 'delete' , 'update' ] for k in self .operation_flags ):
129123 # flags apply to all operations
130124 flags = self .operation_flags
131125 self .operation_flags = {'save' : flags , 'delete' : flags , 'update' : flags }
132126
133- # Compatibility to version < 0.4
134- if 'SAFE_INSERTS' in settings :
135- _warn_deprecated ('SAFE_INSERTS' )
136- self .operation_flags ['save' ]['safe' ] = settings ['SAFE_INSERTS' ]
137- if 'WAIT_FOR_SLAVES' in settings :
138- _warn_deprecated ('WAIT_FOR_SLAVES' )
139- self .operation_flags ['save' ]['w' ] = settings ['WAIT_FOR_SLAVES' ]
140-
141- # lower-case all remaining OPTIONS
127+ # lower-case all OPTIONS keys
142128 for key in options .iterkeys ():
143129 options [key .lower ()] = options .pop (key )
144130
145131 try :
146132 self .connection = Connection (host = host , port = port , ** options )
147133 self .database = self .connection [db_name ]
148134 except TypeError :
149- import sys
150135 exc_info = sys .exc_info ()
151136 raise ImproperlyConfigured , exc_info [1 ], exc_info [2 ]
152137
153138 if user and password :
154139 if not self .database .authenticate (user , password ):
155140 raise ImproperlyConfigured ("Invalid username or password" )
156141
157- self ._add_serializer ()
142+ if settings .get ('MONGODB_AUTOMATIC_REFERENCING' ):
143+ from .serializer import TransformDjango
144+ self .database .add_son_manipulator (TransformDjango ())
145+
158146 self .connected = True
159147 connection_created .send (sender = self .__class__ , connection = self )
160148
@@ -165,14 +153,6 @@ def _reconnect(self):
165153 self .connected = False
166154 self ._connect ()
167155
168- def _add_serializer (self ):
169- for option in ['MONGODB_AUTOMATIC_REFERENCING' ,
170- 'MONGODB_ENGINE_ENABLE_MODEL_SERIALIZATION' ]:
171- if getattr (settings , option , False ):
172- from .serializer import TransformDjango
173- self .database .add_son_manipulator (TransformDjango ())
174- return
175-
176156 def _commit (self ):
177157 pass
178158
0 commit comments