Changeset 8215 for django/branches/gis/django/forms
- Timestamp:
- 08/05/08 12:15:33 (4 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/forms/fields.py (modified) (5 diffs)
- django/branches/gis/django/forms/formsets.py (modified) (6 diffs)
- django/branches/gis/django/forms/models.py (modified) (8 diffs)
- django/branches/gis/django/forms/util.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
django/branches/gis/django/forms/fields.py
r7979 r8215 8 8 import re 9 9 import time 10 import urlparse 10 11 try: 11 12 from cStringIO import StringIO … … 24 25 25 26 from django.utils.translation import ugettext_lazy as _ 26 from django.utils.encoding import StrAndUnicode,smart_unicode, smart_str27 from django.utils.encoding import smart_unicode, smart_str 27 28 28 29 from util import ErrorList, ValidationError … … 74 75 label = smart_unicode(label) 75 76 self.required, self.label, self.initial = required, label, initial 76 self.help_text = smart_unicode(help_text or '') 77 if help_text is None: 78 self.help_text = u'' 79 else: 80 self.help_text = smart_unicode(help_text) 77 81 widget = widget or self.widget 78 82 if isinstance(widget, type): … … 504 508 trial_image = Image.open(file) 505 509 trial_image.verify() 510 except ImportError: 511 # Under PyPy, it is possible to import PIL. However, the underlying 512 # _imaging C module isn't available, so an ImportError will be 513 # raised. Catch and re-raise. 514 raise 506 515 except Exception: # Python Imaging Library doesn't recognize it as an image 507 516 raise ValidationError(self.error_messages['invalid_image']) … … 535 544 if value and '://' not in value: 536 545 value = u'http://%s' % value 546 # If no URL path given, assume / 547 if value and not urlparse.urlsplit(value)[2]: 548 value += '/' 537 549 value = super(URLField, self).clean(value) 538 550 if value == u'': django/branches/gis/django/forms/formsets.py
r7979 r8215 3 3 from django.utils.safestring import mark_safe 4 4 from fields import IntegerField, BooleanField 5 from widgets import Media, HiddenInput , TextInput5 from widgets import Media, HiddenInput 6 6 from util import ErrorList, ValidationError 7 7 … … 11 11 TOTAL_FORM_COUNT = 'TOTAL_FORMS' 12 12 INITIAL_FORM_COUNT = 'INITIAL_FORMS' 13 MAX_FORM_COUNT = 'MAX_FORMS'14 13 ORDERING_FIELD_NAME = 'ORDER' 15 14 DELETION_FIELD_NAME = 'DELETE' … … 24 23 self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 25 24 self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 26 self.base_fields[MAX_FORM_COUNT] = IntegerField(widget=HiddenInput)27 25 super(ManagementForm, self).__init__(*args, **kwargs) 28 26 … … 48 46 self._total_form_count = self.management_form.cleaned_data[TOTAL_FORM_COUNT] 49 47 self._initial_form_count = self.management_form.cleaned_data[INITIAL_FORM_COUNT] 50 self._max_form_count = self.management_form.cleaned_data[MAX_FORM_COUNT]51 48 else: 52 49 raise ValidationError('ManagementForm data is missing or has been tampered with') … … 54 51 if initial: 55 52 self._initial_form_count = len(initial) 56 if self._initial_form_count > self. _max_form_count and self._max_form_count> 0:57 self._initial_form_count = self. _max_form_count53 if self._initial_form_count > self.max_num and self.max_num > 0: 54 self._initial_form_count = self.max_num 58 55 self._total_form_count = self._initial_form_count + self.extra 59 56 else: 60 57 self._initial_form_count = 0 61 58 self._total_form_count = self.extra 62 if self._total_form_count > self. _max_form_count and self._max_form_count> 0:63 self._total_form_count = self. _max_form_count59 if self._total_form_count > self.max_num and self.max_num > 0: 60 self._total_form_count = self.max_num 64 61 initial = {TOTAL_FORM_COUNT: self._total_form_count, 65 INITIAL_FORM_COUNT: self._initial_form_count, 66 MAX_FORM_COUNT: self._max_form_count} 62 INITIAL_FORM_COUNT: self._initial_form_count} 67 63 self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) 68 64 … … 281 277 attrs = {'form': form, 'extra': extra, 282 278 'can_order': can_order, 'can_delete': can_delete, 283 ' _max_form_count': max_num}279 'max_num': max_num} 284 280 return type(form.__name__ + 'FormSet', (formset,), attrs) 285 281 django/branches/gis/django/forms/models.py
r7979 r8215 9 9 from django.utils.encoding import smart_unicode 10 10 from django.utils.datastructures import SortedDict 11 from django.core.exceptions import ImproperlyConfigured12 11 13 12 from util import ValidationError, ErrorList … … 261 260 if initial is not None: 262 261 object_data.update(initial) 263 BaseForm.__init__(self,data, files, auto_id, prefix, object_data,264 error_class, label_suffix, empty_permitted)262 super(BaseModelForm, self).__init__(data, files, auto_id, prefix, object_data, 263 error_class, label_suffix, empty_permitted) 265 264 266 265 def save(self, commit=True): … … 307 306 self.queryset = queryset 308 307 defaults = {'data': data, 'files': files, 'auto_id': auto_id, 'prefix': prefix} 309 if self. _max_form_count> 0:310 qs = self.get_queryset()[:self. _max_form_count]308 if self.max_num > 0: 309 qs = self.get_queryset()[:self.max_num] 311 310 else: 312 311 qs = self.get_queryset() … … 380 379 def add_fields(self, form, index): 381 380 """Add a hidden field for the object's primary key.""" 382 self._pk_field_name = self.model._meta.pk.attname 383 form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput) 381 if self.model._meta.has_auto_field: 382 self._pk_field_name = self.model._meta.pk.attname 383 form.fields[self._pk_field_name] = IntegerField(required=False, widget=HiddenInput) 384 384 super(BaseModelFormSet, self).add_fields(form, index) 385 385 … … 403 403 class BaseInlineFormset(BaseModelFormSet): 404 404 """A formset for child objects related to a parent.""" 405 def __init__(self, data=None, files=None, instance=None, save_as_new=False): 405 def __init__(self, data=None, files=None, instance=None, 406 save_as_new=False, prefix=None): 406 407 from django.db.models.fields.related import RelatedObject 407 408 self.instance = instance … … 409 410 # is there a better way to get the object descriptor? 410 411 self.rel_name = RelatedObject(self.fk.rel.to, self.model, self.fk).get_accessor_name() 411 super(BaseInlineFormset, self).__init__(data, files, prefix= self.rel_name)412 super(BaseInlineFormset, self).__init__(data, files, prefix=prefix or self.rel_name) 412 413 413 414 def _construct_forms(self): … … 442 443 if len(fks_to_parent) == 1: 443 444 fk = fks_to_parent[0] 444 if not isinstance(fk, ForeignKey) or fk.rel.to != parent_model: 445 if not isinstance(fk, ForeignKey) or \ 446 (fk.rel.to != parent_model and 447 fk.rel.to not in parent_model._meta.parents.keys()): 445 448 raise Exception("fk_name '%s' is not a ForeignKey to %s" % (fk_name, parent_model)) 446 449 elif len(fks_to_parent) == 0: … … 448 451 else: 449 452 # Try to discover what the ForeignKey from model to parent_model is 450 fks_to_parent = [f for f in opts.fields if isinstance(f, ForeignKey) and f.rel.to == parent_model] 453 fks_to_parent = [ 454 f for f in opts.fields 455 if isinstance(f, ForeignKey) 456 and (f.rel.to == parent_model 457 or f.rel.to in parent_model._meta.parents.keys()) 458 ] 451 459 if len(fks_to_parent) == 1: 452 460 fk = fks_to_parent[0] django/branches/gis/django/forms/util.py
r7979 r8215 1 1 from django.utils.html import escape 2 2 from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode 3 from django.utils.functional import Promise4 3 from django.utils.safestring import mark_safe 5 4
