Author: russellm
Date: 2007-08-09 09:47:49 -0500 (Thu, 09 Aug 2007)
New Revision: 5833
Modified:
django/branches/newforms-admin/django/contrib/admin/options.py
django/branches/newforms-admin/django/contrib/admin/views/main.py
django/branches/newforms-admin/django/newforms/formsets.py
django/branches/newforms-admin/django/newforms/models.py
Log:
newforms-admin: Fixed handling of file uploads in inline formsets.
Modified: django/branches/newforms-admin/django/contrib/admin/options.py
===================================================================
--- django/branches/newforms-admin/django/contrib/admin/options.py
2007-08-09 03:07:02 UTC (rev 5832)
+++ django/branches/newforms-admin/django/contrib/admin/options.py
2007-08-09 14:47:49 UTC (rev 5833)
@@ -420,7 +420,7 @@
if request.method == 'POST':
form = ModelForm(request.POST, request.FILES)
for FormSet in self.get_inline_formsets():
- inline_formset = FormSet(data=request.POST)
+ inline_formset = FormSet(data=request.POST,
files=request.FILES)
inline_formsets.append(inline_formset)
if all_valid(inline_formsets) and form.is_valid():
return self.save_add(request, model, form, inline_formsets,
'../%s/')
@@ -470,7 +470,7 @@
if request.method == 'POST':
form = ModelForm(request.POST, request.FILES)
for FormSet in self.get_inline_formsets():
- inline_formset = FormSet(obj, request.POST)
+ inline_formset = FormSet(obj, request.POST, request.FILES)
inline_formsets.append(inline_formset)
if all_valid(inline_formsets) and form.is_valid():
Modified: django/branches/newforms-admin/django/contrib/admin/views/main.py
===================================================================
--- django/branches/newforms-admin/django/contrib/admin/views/main.py
2007-08-09 03:07:02 UTC (rev 5832)
+++ django/branches/newforms-admin/django/contrib/admin/views/main.py
2007-08-09 14:47:49 UTC (rev 5833)
@@ -124,7 +124,7 @@
'change': change,
'has_delete_permission':
context['perms'][app_label][opts.get_delete_permission()],
'has_change_permission':
context['perms'][app_label][opts.get_change_permission()],
- 'has_file_field': opts.has_field_type(models.FileField),
+ 'has_file_field': True, # FIXME - this should check if form or
formsets have a FileField,
'has_absolute_url': hasattr(model, 'get_absolute_url'),
'ordered_objects': ordered_objects,
'inline_related_objects': inline_related_objects,
Modified: django/branches/newforms-admin/django/newforms/formsets.py
===================================================================
--- django/branches/newforms-admin/django/newforms/formsets.py 2007-08-09
03:07:02 UTC (rev 5832)
+++ django/branches/newforms-admin/django/newforms/formsets.py 2007-08-09
14:47:49 UTC (rev 5833)
@@ -20,15 +20,16 @@
class BaseFormSet(object):
"""A collection of instances of the same Form class."""
- def __init__(self, data=None, auto_id='id_%s', prefix=None, initial=None):
- self.is_bound = data is not None
+ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
initial=None):
+ self.is_bound = data is not None and files is not None
self.prefix = prefix or 'form'
self.auto_id = auto_id
self.data = data
+ self.files = files
self.initial = initial
# initialization is different depending on whether we recieved data,
initial, or nothing
- if data:
- self.management_form = ManagementForm(data, auto_id=self.auto_id,
prefix=self.prefix)
+ if data or files:
+ self.management_form = ManagementForm(data, files,
auto_id=self.auto_id, prefix=self.prefix)
if self.management_form.is_valid():
self.total_forms =
self.management_form.cleaned_data[FORM_COUNT_FIELD_NAME]
self.required_forms = self.total_forms - self.num_extra
@@ -56,6 +57,8 @@
kwargs = {'auto_id': self.auto_id, 'prefix':
self.add_prefix(i)}
if self.data:
kwargs['data'] = self.data
+ if self.files:
+ kwargs['files'] = self.files
add_form = FormClass(**kwargs)
self.add_fields(add_form, i)
add_forms.append(add_form)
@@ -72,6 +75,8 @@
kwargs = {'auto_id': self.auto_id, 'prefix':
self.add_prefix(i)}
if self.data:
kwargs['data'] = self.data
+ if self.files:
+ kwargs['files'] = self.files
if self.initial:
kwargs['initial'] = self.initial[i]
change_form = FormClass(**kwargs)
Modified: django/branches/newforms-admin/django/newforms/models.py
===================================================================
--- django/branches/newforms-admin/django/newforms/models.py 2007-08-09
03:07:02 UTC (rev 5832)
+++ django/branches/newforms-admin/django/newforms/models.py 2007-08-09
14:47:49 UTC (rev 5833)
@@ -234,9 +234,9 @@
"""
model = None
- def __init__(self, data=None, auto_id='id_%s', prefix=None,
instances=None):
+ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
instances=None):
self.instances = instances
- kwargs = {'data': data, 'auto_id': auto_id, 'prefix': prefix}
+ kwargs = {'data': data, 'files': files, 'auto_id': auto_id, 'prefix':
prefix}
if instances:
kwargs['initial'] = [initial_data(instance) for instance in
instances]
super(BaseModelFormSet, self).__init__(**kwargs)
@@ -287,12 +287,12 @@
class InlineFormset(BaseModelFormSet):
"""A formset for child objects related to a parent."""
- def __init__(self, instance=None, data=None):
+ def __init__(self, instance=None, data=None, files=None):
from django.db.models.fields.related import RelatedObject
self.instance = instance
# is there a better way to get the object descriptor?
self.rel_name = RelatedObject(self.fk.rel.to, self.model,
self.fk).get_accessor_name()
- super(InlineFormset, self).__init__(data,
instances=self.get_inline_objects(), prefix=self.rel_name)
+ super(InlineFormset, self).__init__(data, files,
instances=self.get_inline_objects(), prefix=self.rel_name)
def get_inline_objects(self):
if self.instance is None:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---