Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:15:33 (4 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

Files:

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  
    88import re 
    99import time 
     10import urlparse 
    1011try: 
    1112    from cStringIO import StringIO 
     
    2425 
    2526from django.utils.translation import ugettext_lazy as _ 
    26 from django.utils.encoding import StrAndUnicode, smart_unicode, smart_str 
     27from django.utils.encoding import smart_unicode, smart_str 
    2728 
    2829from util import ErrorList, ValidationError 
     
    7475            label = smart_unicode(label) 
    7576        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) 
    7781        widget = widget or self.widget 
    7882        if isinstance(widget, type): 
     
    504508            trial_image = Image.open(file) 
    505509            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 
    506515        except Exception: # Python Imaging Library doesn't recognize it as an image 
    507516            raise ValidationError(self.error_messages['invalid_image']) 
     
    535544        if value and '://' not in value: 
    536545            value = u'http://%s' % value 
     546        # If no URL path given, assume / 
     547        if value and not urlparse.urlsplit(value)[2]: 
     548            value += '/' 
    537549        value = super(URLField, self).clean(value) 
    538550        if value == u'': 
  • django/branches/gis/django/forms/formsets.py

    r7979 r8215  
    33from django.utils.safestring import mark_safe 
    44from fields import IntegerField, BooleanField 
    5 from widgets import Media, HiddenInput, TextInput 
     5from widgets import Media, HiddenInput 
    66from util import ErrorList, ValidationError 
    77 
     
    1111TOTAL_FORM_COUNT = 'TOTAL_FORMS' 
    1212INITIAL_FORM_COUNT = 'INITIAL_FORMS' 
    13 MAX_FORM_COUNT = 'MAX_FORMS' 
    1413ORDERING_FIELD_NAME = 'ORDER' 
    1514DELETION_FIELD_NAME = 'DELETE' 
     
    2423        self.base_fields[TOTAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 
    2524        self.base_fields[INITIAL_FORM_COUNT] = IntegerField(widget=HiddenInput) 
    26         self.base_fields[MAX_FORM_COUNT] = IntegerField(widget=HiddenInput) 
    2725        super(ManagementForm, self).__init__(*args, **kwargs) 
    2826 
     
    4846                self._total_form_count = self.management_form.cleaned_data[TOTAL_FORM_COUNT] 
    4947                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] 
    5148            else: 
    5249                raise ValidationError('ManagementForm data is missing or has been tampered with') 
     
    5451            if initial: 
    5552                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_count 
     53                if self._initial_form_count > self.max_num and self.max_num > 0: 
     54                    self._initial_form_count = self.max_num 
    5855                self._total_form_count = self._initial_form_count + self.extra 
    5956            else: 
    6057                self._initial_form_count = 0 
    6158                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_count 
     59            if self._total_form_count > self.max_num and self.max_num > 0: 
     60                self._total_form_count = self.max_num 
    6461            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} 
    6763            self.management_form = ManagementForm(initial=initial, auto_id=self.auto_id, prefix=self.prefix) 
    6864         
     
    281277    attrs = {'form': form, 'extra': extra, 
    282278             'can_order': can_order, 'can_delete': can_delete, 
    283              '_max_form_count': max_num} 
     279             'max_num': max_num} 
    284280    return type(form.__name__ + 'FormSet', (formset,), attrs) 
    285281 
  • django/branches/gis/django/forms/models.py

    r7979 r8215  
    99from django.utils.encoding import smart_unicode 
    1010from django.utils.datastructures import SortedDict 
    11 from django.core.exceptions import ImproperlyConfigured 
    1211 
    1312from util import ValidationError, ErrorList 
     
    261260        if initial is not None: 
    262261            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) 
    265264 
    266265    def save(self, commit=True): 
     
    307306        self.queryset = queryset 
    308307        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
    311310        else: 
    312311            qs = self.get_queryset() 
     
    380379    def add_fields(self, form, index): 
    381380        """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) 
    384384        super(BaseModelFormSet, self).add_fields(form, index) 
    385385 
     
    403403class BaseInlineFormset(BaseModelFormSet): 
    404404    """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): 
    406407        from django.db.models.fields.related import RelatedObject 
    407408        self.instance = instance 
     
    409410        # is there a better way to get the object descriptor? 
    410411        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) 
    412413     
    413414    def _construct_forms(self): 
     
    442443        if len(fks_to_parent) == 1: 
    443444            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()): 
    445448                raise Exception("fk_name '%s' is not a ForeignKey to %s" % (fk_name, parent_model)) 
    446449        elif len(fks_to_parent) == 0: 
     
    448451    else: 
    449452        # 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        ] 
    451459        if len(fks_to_parent) == 1: 
    452460            fk = fks_to_parent[0] 
  • django/branches/gis/django/forms/util.py

    r7979 r8215  
    11from django.utils.html import escape 
    22from django.utils.encoding import smart_unicode, StrAndUnicode, force_unicode 
    3 from django.utils.functional import Promise 
    43from django.utils.safestring import mark_safe 
    54