1
0
mirror of https://github.com/django/django.git synced 2025-06-12 15:09:12 +00:00

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." "Validates that the value is unique for this field."
lookup_type = f.get_validator_unique_lookup_type() lookup_type = f.get_validator_unique_lookup_type()
try: 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: except ObjectDoesNotExist:
return return
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname): 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() params['choices'] = self.get_choices_default()
else: else:
field_objs = self.get_manipulator_field_objs() field_objs = self.get_manipulator_field_objs()
return (field_objs,params) return (field_objs, params)
def get_fields_and_manipulators(self, opts, manipulator, follow): def get_fields_and_manipulators(self, opts, manipulator, follow):
change = manipulator.change change = manipulator.change
rel = manipulator.name_prefix != '' rel = manipulator.name_prefix != ''
name_prefix = 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): 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)) setattr(other_cls, name, ManipulatorDescriptor(name, cls))
contribute_to_class = classmethod(contribute_to_class) 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) Naming.__init__(self, name_parts)
if name_parts == (): if name_parts == ():
self.follow = self.model._meta.get_follow(follow) self.follow = self.model._meta.get_follow(follow)
@ -100,7 +100,7 @@ class AutomaticManipulator(Manipulator, Naming):
self.ignore_errors = False self.ignore_errors = False
def get_fields(self): def get_fields(self):
if self.needs_deletion : if self.needs_deletion:
return [] return []
else: else:
return self.fields_ return self.fields_
@ -130,7 +130,7 @@ class AutomaticManipulator(Manipulator, Naming):
child.do_html2python(new_data) child.do_html2python(new_data)
def get_original_value(self, field): def get_original_value(self, field):
raise NotImplemented raise NotImplementedError
def get_new_object(self, expanded_data, overrides=None): def get_new_object(self, expanded_data, overrides=None):
params = {} params = {}
@ -200,11 +200,10 @@ class AutomaticManipulator(Manipulator, Naming):
child_manips = manips child_manips = manips
break break
if child_manips == None: if child_manips == None:
raise BadCommand, "'%s' : unknown manipulator collection name." % (part,) raise BadCommand, "'%s': unknown manipulator collection name." % (part,)
else: else:
child_manips._do_command_expanded(command_parts) child_manips._do_command_expanded(command_parts)
def save(self, new_data): def save(self, new_data):
self.update(new_data) self.update(new_data)
self.save_from_update() self.save_from_update()
@ -285,7 +284,7 @@ class ModelAddManipulator(AutomaticManipulator):
return field.get_default() return field.get_default()
def __repr__(self): 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): class ModelChangeManipulator(AutomaticManipulator):
change = True change = True
@ -318,6 +317,10 @@ class ModelChangeManipulator(AutomaticManipulator):
original_object = opts.get_model_module().Klass(**params) original_object = opts.get_model_module().Klass(**params)
else: else:
raise 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) super(ModelChangeManipulator, self).__init__(original_object=original_object, follow=follow, name_parts=name_parts)
#self.original_object = original_object #self.original_object = original_object
@ -347,7 +350,7 @@ class ManipulatorCollection(list, Naming):
man_class = self.model.ChangeManipulator man_class = self.model.ChangeManipulator
for i,obj in enumerate(self._get_list()): 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): def _save_child(self, manip, parent_key):
manip.save_from_update() manip.save_from_update()
@ -370,7 +373,7 @@ class ManipulatorCollection(list, Naming):
manip.needs_deletion = True manip.needs_deletion = True
if expanded_data: if expanded_data:
# There are new objects in the 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])) items.sort(cmp = lambda x, y: cmp(x[0], y[0]))
for index, obj_data in items: for index, obj_data in items:
child_manip = self.add_child(index) child_manip = self.add_child(index)