Changeset 7918 for django/branches/gis/django/newforms
- Timestamp:
- 07/13/08 09:31:09 (6 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/newforms/fields.py (modified) (5 diffs)
- django/branches/gis/django/newforms/forms.py (modified) (1 diff)
- django/branches/gis/django/newforms/models.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7835 to /django/trunk:1-7917
django/branches/gis/django/newforms/fields.py
r7836 r7918 28 28 from util import ErrorList, ValidationError 29 29 from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, FileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateTimeInput 30 30 from django.core.files.uploadedfile import SimpleUploadedFile as UploadedFile 31 31 32 32 __all__ = ( … … 420 420 URL_VALIDATOR_USER_AGENT = 'Django (http://www.djangoproject.com/)' 421 421 422 class UploadedFile(StrAndUnicode):423 "A wrapper for files uploaded in a FileField"424 def __init__(self, filename, data):425 self.filename = filename426 self.data = data427 428 def __unicode__(self):429 """430 The unicode representation is the filename, so that the pre-database-insertion431 logic can use UploadedFile objects432 """433 return self.filename434 422 435 423 class FileField(Field): … … 461 449 stacklevel = 2 462 450 ) 451 data = UploadedFile(data['filename'], data['content']) 463 452 464 453 try: 465 file_name = data. file_name466 file_size = data. file_size454 file_name = data.name 455 file_size = data.size 467 456 except AttributeError: 468 try: 469 file_name = data.get('filename') 470 file_size = bool(data['content']) 471 except (AttributeError, KeyError): 472 raise ValidationError(self.error_messages['invalid']) 457 raise ValidationError(self.error_messages['invalid']) 473 458 474 459 if not file_name: … … 477 462 raise ValidationError(self.error_messages['empty']) 478 463 479 return UploadedFile(file_name, data)464 return data 480 465 481 466 class ImageField(FileField): … … 523 508 except Exception: # Python Imaging Library doesn't recognize it as an image 524 509 raise ValidationError(self.error_messages['invalid_image']) 510 if hasattr(f, 'seek') and callable(f.seek): 511 f.seek(0) 525 512 return f 526 513 django/branches/gis/django/newforms/forms.py
r7279 r7918 57 57 def __new__(cls, name, bases, attrs): 58 58 attrs['base_fields'] = get_declared_fields(bases, attrs) 59 return type.__new__(cls, name, bases, attrs) 59 return super(DeclarativeFieldsMetaclass, 60 cls).__new__(cls, name, bases, attrs) 60 61 61 62 class BaseForm(StrAndUnicode): django/branches/gis/django/newforms/models.py
r7768 r7918 214 214 215 215 class ModelFormMetaclass(type): 216 def __new__(cls, name, bases, attrs, 217 formfield_callback=lambda f: f.formfield()): 216 def __new__(cls, name, bases, attrs): 217 formfield_callback = attrs.pop('formfield_callback', 218 lambda f: f.formfield()) 218 219 try: 219 220 parents = [b for b in bases if issubclass(b, ModelForm)] … … 221 222 # We are defining ModelForm itself. 222 223 parents = None 224 new_class = super(ModelFormMetaclass, cls).__new__(cls, name, bases, 225 attrs) 223 226 if not parents: 224 return super(ModelFormMetaclass, cls).__new__(cls, name, bases, 225 attrs) 226 227 new_class = type.__new__(cls, name, bases, attrs) 227 return new_class 228 228 229 declared_fields = get_declared_fields(bases, attrs, False) 229 230 opts = new_class._meta = ModelFormOptions(getattr(new_class, 'Meta', None))
