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

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1828 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-05 21:12:42 +00:00
parent 9033ba7d36
commit 1885443c82
2 changed files with 14 additions and 11 deletions

View File

@ -36,7 +36,7 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
"Validates that the value is unique for this field."
lookup_type = f.get_validator_unique_lookup_type()
try:
old_obj = self.__class__._default_manager.get_object(**{lookup_type: field_data})
old_obj = self.manager.get_object(**{lookup_type: field_data})
except ObjectDoesNotExist:
return
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname):
@ -216,13 +216,13 @@ class Field(object):
params['choices'] = self.get_choices_default()
else:
field_objs = self.get_manipulator_field_objs()
return (field_objs,params)
return (field_objs, params)
def get_fields_and_manipulators(self, opts, manipulator, follow):
change = manipulator.change
rel = manipulator.name_prefix != ''
name_prefix = manipulator.name_prefix
return (self.get_manipulator_fields(opts, manipulator, change,name_prefix, rel, follow), None )
return (self.get_manipulator_fields(opts, manipulator, change, name_prefix, rel, follow), None)
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
"""

View File

@ -80,7 +80,7 @@ class AutomaticManipulator(Manipulator, Naming):
setattr(other_cls, name, ManipulatorDescriptor(name, cls))
contribute_to_class = classmethod(contribute_to_class)
def __init__(self, original_object=None, follow=None, name_parts=() ):
def __init__(self, original_object=None, follow=None, name_parts=()):
Naming.__init__(self, name_parts)
if name_parts == ():
self.follow = self.model._meta.get_follow(follow)
@ -100,7 +100,7 @@ class AutomaticManipulator(Manipulator, Naming):
self.ignore_errors = False
def get_fields(self):
if self.needs_deletion :
if self.needs_deletion:
return []
else:
return self.fields_
@ -130,7 +130,7 @@ class AutomaticManipulator(Manipulator, Naming):
child.do_html2python(new_data)
def get_original_value(self, field):
raise NotImplemented
raise NotImplementedError
def get_new_object(self, expanded_data, overrides=None):
params = {}
@ -200,11 +200,10 @@ class AutomaticManipulator(Manipulator, Naming):
child_manips = manips
break
if child_manips == None:
raise BadCommand, "'%s' : unknown manipulator collection name." % (part,)
raise BadCommand, "'%s': unknown manipulator collection name." % (part,)
else:
child_manips._do_command_expanded(command_parts)
def save(self, new_data):
self.update(new_data)
self.save_from_update()
@ -285,7 +284,7 @@ class ModelAddManipulator(AutomaticManipulator):
return field.get_default()
def __repr__(self):
return "<Automatic AddManipulator '%s' for %s>" % (self.name_prefix, self.model.__name__, )
return "<Automatic AddManipulator '%s' for %s>" % (self.name_prefix, self.model.__name__)
class ModelChangeManipulator(AutomaticManipulator):
change = True
@ -318,6 +317,10 @@ class ModelChangeManipulator(AutomaticManipulator):
original_object = opts.get_model_module().Klass(**params)
else:
raise
else:
# Save the obj_key even though we already have it, in case it's
# currently a string and needs to be an integer.
self.obj_key = getattr(original_object, self.model._meta.pk.attname)
super(ModelChangeManipulator, self).__init__(original_object=original_object, follow=follow, name_parts=name_parts)
#self.original_object = original_object
@ -347,7 +350,7 @@ class ManipulatorCollection(list, Naming):
man_class = self.model.ChangeManipulator
for i,obj in enumerate(self._get_list()):
self.append(man_class(obj,self.follow, self.name_parts + (str(i),) ))
self.append(man_class(obj, self.follow, self.name_parts + (str(i),)))
def _save_child(self, manip, parent_key):
manip.save_from_update()
@ -370,7 +373,7 @@ class ManipulatorCollection(list, Naming):
manip.needs_deletion = True
if expanded_data:
# There are new objects in the data
items = [ (int(k),v ) for k,v in expanded_data.items() ]
items = [(int(k), v) for k, v in expanded_data.items()]
items.sort(cmp = lambda x, y: cmp(x[0], y[0]))
for index, obj_data in items:
child_manip = self.add_child(index)