summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2006-03-08 17:53:55 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2006-03-08 17:53:55 +0000
commit738d9af1e8e38b0289b7dfa7c8a5413f5d0e20d1 (patch)
tree658584dfb036deb8ea0f6070e314015b28170e84 /django/forms
parent4e292dabc0969ce36ffaa5ebf39fb1b041cd676b (diff)
magic-removal: fixed #1330: edit-inline works again on magic-removal. Note that the API will change *substantailly* before we're done (for example, this reintroduces core fields, which suck) but this at least gives us a place to start with.
Many many thanks for Christopher Lenz, my new hero. git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2502 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/__init__.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/django/forms/__init__.py b/django/forms/__init__.py
index 4d3c24c373..ba42706c9e 100644
--- a/django/forms/__init__.py
+++ b/django/forms/__init__.py
@@ -131,10 +131,10 @@ class FormWrapper:
def fill_inline_collections(self):
if not self._inline_collections:
ic = []
- children = self.manipulator.children.items()
- for rel_obj, child_manips in children:
+ related_objects = self.manipulator.get_related_objects()
+ for rel_obj in related_objects:
data = rel_obj.extract_data(self.data)
- inline_collection = InlineObjectCollection(self.manipulator, rel_obj, child_manips, data, self.error_dict)
+ inline_collection = InlineObjectCollection(self.manipulator, rel_obj, data, self.error_dict)
ic.append(inline_collection)
self._inline_collections = ic
@@ -213,12 +213,11 @@ class FormFieldCollection(FormFieldWrapper):
class InlineObjectCollection:
"An object that acts like a sparse list of form field collections."
- def __init__(self, parent_manipulator, rel_obj,child_manips, data, errors):
+ def __init__(self, parent_manipulator, rel_obj, data, errors):
self.parent_manipulator = parent_manipulator
self.rel_obj = rel_obj
self.data = data
self.errors = errors
- self.child_manips = child_manips
self._collections = None
self.name = rel_obj.name
@@ -240,7 +239,7 @@ class InlineObjectCollection:
def __iter__(self):
self.fill()
- return self._collections.values().__iter__()
+ return iter(self._collections.values())
def items(self):
self.fill()
@@ -250,22 +249,25 @@ class InlineObjectCollection:
if self._collections:
return
else:
- #var_name = self.rel_obj.opts.object_name.lower()
- cols = {}
- #orig = hasattr(self.parent_manipulator, 'original_object') and self.parent_manipulator.original_object or None
- #orig_list = self.rel_obj.get_list(orig)
+ var_name = self.rel_obj.opts.object_name.lower()
+ collections = {}
+ orig = None
+ if hasattr(self.parent_manipulator, 'original_object'):
+ orig = self.parent_manipulator.original_object
+ orig_list = self.rel_obj.get_list(orig)
- for i, manip in enumerate(self.child_manips) :
- if manip and not manip.needs_deletion:
- collection = {'original': manip.original_object}
- for field in manip.fields:
- errors = self.errors.get(field.field_name, [])
+ for i, instance in enumerate(orig_list):
+ collection = {'original': instance}
+ for f in self.rel_obj.editable_fields():
+ for field_name in f.get_manipulator_field_names(''):
+ full_field_name = '%s.%d.%s' % (var_name, i, field_name)
+ field = self.parent_manipulator[full_field_name]
data = field.extract_data(self.data)
- last_part = field.field_name[field.field_name.rindex('.') + 1:]
- collection[last_part] = FormFieldWrapper(field, data, errors)
+ errors = self.errors.get(full_field_name, [])
+ collection[field_name] = FormFieldWrapper(field, data, errors)
+ collections[i] = FormFieldCollection(collection)
+ self._collections = collections
- cols[i] = FormFieldCollection(collection)
- self._collections = cols
class FormField:
"""Abstract class representing a form field.