Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magic-removal: Fixed #1159 -- Fixed error in 'unique' manipulator val…

…idator

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1828 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1885443c8239e09b06330096e15704c0d2779a87 1 parent 9033ba7
Adrian Holovaty authored January 05, 2006
6  django/db/models/fields/__init__.py
@@ -36,7 +36,7 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
36 36
     "Validates that the value is unique for this field."
37 37
     lookup_type = f.get_validator_unique_lookup_type()
38 38
     try:
39  
-        old_obj = self.__class__._default_manager.get_object(**{lookup_type: field_data})
  39
+        old_obj = self.manager.get_object(**{lookup_type: field_data})
40 40
     except ObjectDoesNotExist:
41 41
         return
42 42
     if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname):
@@ -216,13 +216,13 @@ def prepare_field_objs_and_params(self, manipulator, name_prefix):
216 216
             params['choices'] = self.get_choices_default()
217 217
         else:
218 218
             field_objs = self.get_manipulator_field_objs()
219  
-        return (field_objs,params)
  219
+        return (field_objs, params)
220 220
 
221 221
     def get_fields_and_manipulators(self, opts, manipulator, follow):
222 222
         change = manipulator.change
223 223
         rel = manipulator.name_prefix != ''
224 224
         name_prefix = manipulator.name_prefix
225  
-        return (self.get_manipulator_fields(opts, manipulator, change,name_prefix, rel, follow), None )
  225
+        return (self.get_manipulator_fields(opts, manipulator, change, name_prefix, rel, follow), None)
226 226
 
227 227
     def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
228 228
         """
19  django/db/models/manipulators.py
@@ -80,7 +80,7 @@ def contribute_to_class(cls, other_cls, name):
80 80
         setattr(other_cls, name, ManipulatorDescriptor(name, cls))
81 81
     contribute_to_class = classmethod(contribute_to_class)
82 82
 
83  
-    def __init__(self, original_object=None, follow=None, name_parts=() ):
  83
+    def __init__(self, original_object=None, follow=None, name_parts=()):
84 84
         Naming.__init__(self, name_parts)
85 85
         if name_parts == ():
86 86
             self.follow = self.model._meta.get_follow(follow)
@@ -100,7 +100,7 @@ def __init__(self, original_object=None, follow=None, name_parts=() ):
100 100
         self.ignore_errors = False
101 101
 
102 102
     def get_fields(self):
103  
-        if self.needs_deletion :
  103
+        if self.needs_deletion:
104 104
             return []
105 105
         else:
106 106
             return self.fields_
@@ -130,7 +130,7 @@ def do_html2python(self, new_data):
130 130
             child.do_html2python(new_data)
131 131
 
132 132
     def get_original_value(self, field):
133  
-        raise NotImplemented
  133
+        raise NotImplementedError
134 134
 
135 135
     def get_new_object(self, expanded_data, overrides=None):
136 136
         params = {}
@@ -200,11 +200,10 @@ def _do_command_expanded(self, command_parts):
200 200
                     child_manips = manips
201 201
                     break
202 202
             if child_manips == None:
203  
-                raise BadCommand, "'%s' : unknown manipulator collection name." % (part,)
  203
+                raise BadCommand, "'%s': unknown manipulator collection name." % (part,)
204 204
             else:
205 205
                 child_manips._do_command_expanded(command_parts)
206 206
 
207  
-
208 207
     def save(self, new_data):
209 208
         self.update(new_data)
210 209
         self.save_from_update()
@@ -285,7 +284,7 @@ def get_original_value(self, field):
285 284
         return field.get_default()
286 285
 
287 286
     def __repr__(self):
288  
-        return "<Automatic AddManipulator '%s' for %s>" % (self.name_prefix, self.model.__name__, )
  287
+        return "<Automatic AddManipulator '%s' for %s>" % (self.name_prefix, self.model.__name__)
289 288
 
290 289
 class ModelChangeManipulator(AutomaticManipulator):
291 290
     change = True
@@ -318,6 +317,10 @@ def __init__(self, obj_key=None, follow=None, name_parts=()):
318 317
                     original_object = opts.get_model_module().Klass(**params)
319 318
                 else:
320 319
                     raise
  320
+            else:
  321
+                # Save the obj_key even though we already have it, in case it's
  322
+                # currently a string and needs to be an integer.
  323
+                self.obj_key = getattr(original_object, self.model._meta.pk.attname)
321 324
 
322 325
         super(ModelChangeManipulator, self).__init__(original_object=original_object, follow=follow, name_parts=name_parts)
323 326
         #self.original_object = original_object
@@ -347,7 +350,7 @@ def _load(self):
347 350
         man_class = self.model.ChangeManipulator
348 351
 
349 352
         for i,obj in enumerate(self._get_list()):
350  
-            self.append(man_class(obj,self.follow, self.name_parts + (str(i),)  ))
  353
+            self.append(man_class(obj, self.follow, self.name_parts + (str(i),)))
351 354
 
352 355
     def _save_child(self, manip, parent_key):
353 356
         manip.save_from_update()
@@ -370,7 +373,7 @@ def _fill_data(self, expanded_data):
370 373
                     manip.needs_deletion = True
371 374
         if expanded_data:
372 375
             # There are new objects in the data
373  
-            items = [ (int(k),v ) for k,v in expanded_data.items() ]
  376
+            items = [(int(k), v) for k, v in expanded_data.items()]
374 377
             items.sort(cmp = lambda x, y: cmp(x[0], y[0]))
375 378
             for index, obj_data in items:
376 379
                 child_manip = self.add_child(index)

0 notes on commit 1885443

Please sign in to comment.
Something went wrong with that request. Please try again.