Ticket #14039: 14039_r13760.diff

File 14039_r13760.diff, 3.5 KB (added by Carl Meyer, 14 years ago)
  • django/db/models/fields/__init__.py

    diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
    index 3c58873..c2e5695 100644
    a b class Field(object):  
    6565        'blank': _(u'This field cannot be blank.'),
    6666    }
    6767
     68    defer_save = False # If true, defer saving until after other fields.
     69   
    6870    # Generic field type description, usually overriden by subclasses
    6971    def _description(self):
    7072        return _(u'Field of type: %(field_type)s') % {
  • django/db/models/fields/files.py

    diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
    index 6dfeddb..c592993 100644
    a b class FileField(Field):  
    217217    # The descriptor to use for accessing the attribute off of the class.
    218218    descriptor_class = FileDescriptor
    219219
     220    defer_save = True
     221
    220222    description = ugettext_lazy("File path")
    221223
    222224    def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs):
  • django/forms/fields.py

    diff --git a/django/forms/fields.py b/django/forms/fields.py
    index de14a5c..7a1e55e 100644
    a b class Field(object):  
    6565        'required': _(u'This field is required.'),
    6666        'invalid': _(u'Enter a valid value.'),
    6767    }
     68    clean_takes_initial = False # If true, clean() takes initial value as well as data.
    6869
    6970    # Tracks each time a Field instance is created. Used to retain order.
    7071    creation_counter = 0
    class FileField(Field):  
    442443        'max_length': _(u'Ensure this filename has at most %(max)d characters (it has %(length)d).'),
    443444    }
    444445
     446    clean_takes_initial = True
     447
    445448    def __init__(self, *args, **kwargs):
    446449        self.max_length = kwargs.pop('max_length', None)
    447450        super(FileField, self).__init__(*args, **kwargs)
  • django/forms/forms.py

    diff --git a/django/forms/forms.py b/django/forms/forms.py
    index 7b2bc66..bcbe305 100644
    a b class BaseForm(StrAndUnicode):  
    277277            # widgets split data over several HTML fields.
    278278            value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
    279279            try:
    280                 if isinstance(field, FileField):
     280                if field.clean_takes_initial:
    281281                    initial = self.initial.get(name, field.initial)
    282282                    value = field.clean(value, initial)
    283283                else:
  • django/forms/models.py

    diff --git a/django/forms/models.py b/django/forms/models.py
    index cf465ad..c749cc4 100644
    a b def construct_instance(form, instance, fields=None, exclude=None):  
    3535    opts = instance._meta
    3636
    3737    cleaned_data = form.cleaned_data
    38     file_field_list = []
     38    deferred_list = []
    3939    for f in opts.fields:
    4040        if not f.editable or isinstance(f, models.AutoField) \
    4141                or not f.name in cleaned_data:
    def construct_instance(form, instance, fields=None, exclude=None):  
    4646            continue
    4747        # Defer saving file-type fields until after the other fields, so a
    4848        # callable upload_to can use the values from other fields.
    49         if isinstance(f, models.FileField):
    50             file_field_list.append(f)
     49        if f.defer_save:
     50            deferred_list.append(f)
    5151        else:
    5252            f.save_form_data(instance, cleaned_data[f.name])
    5353
    54     for f in file_field_list:
     54    for f in deferred_list:
    5555        f.save_form_data(instance, cleaned_data[f.name])
    5656
    5757    return instance
Back to Top