1
1
import copy
2
+ import sys
2
3
from django .core .exceptions import ImproperlyConfigured
3
4
from django .db .backends .signals import connection_created
4
5
from django .conf import settings
@@ -117,44 +118,31 @@ def pop(name, default=None):
117
118
password = pop ('PASSWORD' )
118
119
options = pop ('OPTIONS' , {})
119
120
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
-
127
121
self .operation_flags = options .pop ('OPERATIONS' , {})
128
122
if not any (k in ['save' , 'delete' , 'update' ] for k in self .operation_flags ):
129
123
# flags apply to all operations
130
124
flags = self .operation_flags
131
125
self .operation_flags = {'save' : flags , 'delete' : flags , 'update' : flags }
132
126
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
142
128
for key in options .iterkeys ():
143
129
options [key .lower ()] = options .pop (key )
144
130
145
131
try :
146
132
self .connection = Connection (host = host , port = port , ** options )
147
133
self .database = self .connection [db_name ]
148
134
except TypeError :
149
- import sys
150
135
exc_info = sys .exc_info ()
151
136
raise ImproperlyConfigured , exc_info [1 ], exc_info [2 ]
152
137
153
138
if user and password :
154
139
if not self .database .authenticate (user , password ):
155
140
raise ImproperlyConfigured ("Invalid username or password" )
156
141
157
- self ._add_serializer ()
142
+ if settings .get ('MONGODB_AUTOMATIC_REFERENCING' ):
143
+ from .serializer import TransformDjango
144
+ self .database .add_son_manipulator (TransformDjango ())
145
+
158
146
self .connected = True
159
147
connection_created .send (sender = self .__class__ , connection = self )
160
148
@@ -165,14 +153,6 @@ def _reconnect(self):
165
153
self .connected = False
166
154
self ._connect ()
167
155
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
-
176
156
def _commit (self ):
177
157
pass
178
158
0 commit comments