Ticket #7830: deprecated.patch
File deprecated.patch, 24.5 KB (added by , 16 years ago) |
---|
-
django/db/models/fields/subclassing.py
5 5 to_python() and the other necessary methods and everything will work seamlessly. 6 6 """ 7 7 8 from django.utils.maxlength import LegacyMaxlength 9 10 class SubfieldBase(LegacyMaxlength): 8 class SubfieldBase(type): 11 9 """ 12 10 A metaclass for custom Field subclasses. This ensures the model's attribute 13 11 has the descriptor protocol attached to it. … … 50 48 setattr(cls, self.name, Creator(self)) 51 49 52 50 return contribute_to_class 53 -
django/db/models/fields/__init__.py
22 22 from django.utils.text import capfirst 23 23 from django.utils.translation import ugettext_lazy, ugettext as _ 24 24 from django.utils.encoding import smart_unicode, force_unicode, smart_str 25 from django.utils.maxlength import LegacyMaxlength26 25 from django.utils import datetime_safe 27 26 28 27 class NOT_PROVIDED: … … 62 61 # getattr(obj, opts.pk.attname) 63 62 64 63 class Field(object): 65 # Provide backwards compatibility for the maxlength attribute and66 # argument for this class and all subclasses.67 __metaclass__ = LegacyMaxlength68 69 64 # Designates whether empty strings fundamentally are allowed at the 70 65 # database level. 71 66 empty_strings_allowed = True -
django/db/models/fields/related.py
606 606 to_field = to_field or to._meta.pk.name 607 607 kwargs['verbose_name'] = kwargs.get('verbose_name', '') 608 608 609 if 'edit_inline_type' in kwargs:610 import warnings611 warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.", DeprecationWarning)612 kwargs['edit_inline'] = kwargs.pop('edit_inline_type')613 614 609 kwargs['rel'] = rel_class(to, to_field, 615 610 num_in_admin=kwargs.pop('num_in_admin', 3), 616 611 min_num_in_admin=kwargs.pop('min_num_in_admin', None), -
django/db/models/query.py
757 757 yield iter([]).next() 758 758 759 759 760 # QOperator, QNot, QAnd and QOr are temporarily retained for backwards761 # compatibility. All the old functionality is now part of the 'Q' class.762 class QOperator(Q):763 def __init__(self, *args, **kwargs):764 warnings.warn('Use Q instead of QOr, QAnd or QOperation.',765 DeprecationWarning, stacklevel=2)766 super(QOperator, self).__init__(*args, **kwargs)767 768 QOr = QAnd = QOperator769 770 771 def QNot(q):772 warnings.warn('Use ~q instead of QNot(q)', DeprecationWarning, stacklevel=2)773 return ~q774 775 776 760 def get_cached_row(klass, row, index_start, max_depth=0, cur_depth=0, 777 761 requested=None): 778 762 """ -
django/oldforms/__init__.py
5 5 from django.conf import settings 6 6 from django.utils.translation import ugettext, ungettext 7 7 from django.utils.encoding import smart_unicode, force_unicode 8 from django.utils.maxlength import LegacyMaxlength9 8 10 9 FORM_FIELD_ID_PREFIX = 'id_' 11 10 … … 304 303 Subclasses should also implement a render(data) method, which is responsible 305 304 for rending the form field in XHTML. 306 305 """ 307 # Provide backwards compatibility for the maxlength attribute and308 # argument for this class and all subclasses.309 __metaclass__ = LegacyMaxlength310 306 311 307 def __str__(self): 312 308 return unicode(self).encode('utf-8') -
django/core/cache/__init__.py
28 28 'dummy': 'dummy', 29 29 } 30 30 31 DEPRECATED_BACKENDS = {32 # deprecated backend --> replacement module33 'simple': 'locmem',34 }35 36 31 def get_cache(backend_uri): 37 32 if backend_uri.find(':') == -1: 38 33 raise InvalidCacheBackendError, "Backend URI must start with scheme://" 39 34 scheme, rest = backend_uri.split(':', 1) 40 35 if not rest.startswith('//'): 41 36 raise InvalidCacheBackendError, "Backend URI must start with scheme://" 42 if scheme in DEPRECATED_BACKENDS:43 import warnings44 warnings.warn("'%s' backend is deprecated. Use '%s' instead." %45 (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning)46 scheme = DEPRECATED_BACKENDS[scheme]47 37 if scheme not in BACKENDS: 48 38 raise InvalidCacheBackendError, "%r is not a valid cache backend" % scheme 49 39 -
django/core/paginator.py
112 112 if self.number == self.paginator.num_pages: 113 113 return self.paginator.count 114 114 return self.number * self.paginator.per_page 115 116 class ObjectPaginator(Paginator):117 """118 Legacy ObjectPaginator class, for backwards compatibility.119 120 Note that each method on this class that takes page_number expects a121 zero-based page number, whereas the new API (Paginator/Page) uses one-based122 page numbers.123 """124 def __init__(self, query_set, num_per_page, orphans=0):125 Paginator.__init__(self, query_set, num_per_page, orphans)126 import warnings127 warnings.warn("The ObjectPaginator is deprecated. Use django.core.paginator.Paginator instead.", DeprecationWarning)128 129 # Keep these attributes around for backwards compatibility.130 self.query_set = query_set131 self.num_per_page = num_per_page132 self._hits = self._pages = None133 134 def validate_page_number(self, page_number):135 try:136 page_number = int(page_number) + 1137 except ValueError:138 raise PageNotAnInteger139 return self.validate_number(page_number)140 141 def get_page(self, page_number):142 try:143 page_number = int(page_number) + 1144 except ValueError:145 raise PageNotAnInteger146 return self.page(page_number).object_list147 148 def has_next_page(self, page_number):149 return page_number < self.pages - 1150 151 def has_previous_page(self, page_number):152 return page_number > 0153 154 def first_on_page(self, page_number):155 """156 Returns the 1-based index of the first object on the given page,157 relative to total objects found (hits).158 """159 page_number = self.validate_page_number(page_number)160 return (self.num_per_page * (page_number - 1)) + 1161 162 def last_on_page(self, page_number):163 """164 Returns the 1-based index of the last object on the given page,165 relative to total objects found (hits).166 """167 page_number = self.validate_page_number(page_number)168 if page_number == self.num_pages:169 return self.count170 return page_number * self.num_per_page171 172 def _get_count(self):173 # The old API allowed for self.object_list to be either a QuerySet or a174 # list. Here, we handle both.175 if self._count is None:176 try:177 self._count = self.object_list.count()178 except (AttributeError, TypeError):179 # AttributeError if object_list has no count() method.180 # TypeError if object_list.count() requires arguments181 # (i.e. is of type list).182 self._count = len(self.object_list)183 return self._count184 count = property(_get_count)185 186 # The old API called it "hits" instead of "count".187 hits = count188 189 # The old API called it "pages" instead of "num_pages".190 pages = Paginator.num_pages -
django/utils/maxlength.py
1 """2 Utilities for providing backwards compatibility for the maxlength argument,3 which has been replaced by max_length. See ticket #2101.4 """5 6 from warnings import warn7 8 def get_maxlength(self):9 return self.max_length10 11 def set_maxlength(self, value):12 self.max_length = value13 14 def legacy_maxlength(max_length, maxlength):15 """16 Consolidates max_length and maxlength, providing backwards compatibilty17 for the legacy "maxlength" argument.18 19 If one of max_length or maxlength is given, then that value is returned.20 If both are given, a TypeError is raised. If maxlength is used at all, a21 deprecation warning is issued.22 """23 if maxlength is not None:24 warn("maxlength is deprecated. Use max_length instead.", DeprecationWarning, stacklevel=3)25 if max_length is not None:26 raise TypeError("Field cannot take both the max_length argument and the legacy maxlength argument.")27 max_length = maxlength28 return max_length29 30 def remove_maxlength(func):31 """32 A decorator to be used on a class's __init__ that provides backwards33 compatibilty for the legacy "maxlength" keyword argument, i.e.34 name = models.CharField(maxlength=20)35 36 It does this by changing the passed "maxlength" keyword argument37 (if it exists) into a "max_length" keyword argument.38 """39 def inner(self, *args, **kwargs):40 max_length = kwargs.get('max_length', None)41 # pop maxlength because we don't want this going to __init__.42 maxlength = kwargs.pop('maxlength', None)43 max_length = legacy_maxlength(max_length, maxlength)44 # Only set the max_length keyword argument if we got a value back.45 if max_length is not None:46 kwargs['max_length'] = max_length47 func(self, *args, **kwargs)48 return inner49 50 # This metaclass is used in two places, and should be removed when legacy51 # support for maxlength is dropped.52 # * oldforms.FormField53 # * db.models.fields.Field54 55 class LegacyMaxlength(type):56 """57 Metaclass for providing backwards compatibility support for the58 "maxlength" keyword argument.59 """60 def __init__(cls, name, bases, attrs):61 super(LegacyMaxlength, cls).__init__(name, bases, attrs)62 # Decorate the class's __init__ to remove any maxlength keyword.63 cls.__init__ = remove_maxlength(cls.__init__)64 # Support accessing and setting to the legacy maxlength attribute.65 cls.maxlength = property(get_maxlength, set_maxlength) -
tests/modeltests/pagination/models.py
4 4 Django provides a framework for paginating a list of objects in a few lines 5 5 of code. This is often useful for dividing search results or long lists of 6 6 objects into easily readable pages. 7 8 In Django 0.96 and earlier, a single ObjectPaginator class implemented this9 functionality. In the Django development version, the behavior is split across10 two classes -- Paginator and Page -- that are more easier to use. The legacy11 ObjectPaginator class is deprecated.12 7 """ 13 8 14 9 from django.db import models … … 27 22 ... a = Article(headline='Article %s' % x, pub_date=datetime(2005, 7, 29)) 28 23 ... a.save() 29 24 30 ################## ##################31 # New/current API (Paginator/Page)#32 ################## ##################25 ################## 26 # Paginator/Page # 27 ################## 33 28 34 29 >>> from django.core.paginator import Paginator 35 30 >>> paginator = Paginator(Article.objects.all(), 5) … … 140 135 >>> p.end_index() 141 136 5 142 137 143 ################################144 # Legacy API (ObjectPaginator) #145 ################################146 138 147 # Don't print out the deprecation warnings during testing.148 >>> from warnings import filterwarnings149 >>> filterwarnings("ignore")150 151 >>> from django.core.paginator import ObjectPaginator, EmptyPage152 >>> paginator = ObjectPaginator(Article.objects.all(), 5)153 >>> paginator.hits154 9155 >>> paginator.pages156 2157 >>> paginator.page_range158 [1, 2]159 160 # Get the first page.161 >>> paginator.get_page(0)162 [<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>, <Article: Article 5>]163 >>> paginator.has_next_page(0)164 True165 >>> paginator.has_previous_page(0)166 False167 >>> paginator.first_on_page(0)168 1169 >>> paginator.last_on_page(0)170 5171 172 # Get the second page.173 >>> paginator.get_page(1)174 [<Article: Article 6>, <Article: Article 7>, <Article: Article 8>, <Article: Article 9>]175 >>> paginator.has_next_page(1)176 False177 >>> paginator.has_previous_page(1)178 True179 >>> paginator.first_on_page(1)180 6181 >>> paginator.last_on_page(1)182 9183 184 # Invalid pages raise EmptyPage.185 >>> paginator.get_page(-1)186 Traceback (most recent call last):187 ...188 EmptyPage: ...189 >>> paginator.get_page(2)190 Traceback (most recent call last):191 ...192 EmptyPage: ...193 194 # Empty paginators with allow_empty_first_page=True.195 >>> paginator = ObjectPaginator(Article.objects.filter(id=0), 5)196 >>> paginator.count197 0198 >>> paginator.num_pages199 1200 >>> paginator.page_range201 [1]202 203 # ObjectPaginator can be passed lists too.204 >>> paginator = ObjectPaginator([1, 2, 3], 5)205 >>> paginator.hits206 3207 >>> paginator.pages208 1209 >>> paginator.page_range210 [1]211 212 213 # ObjectPaginator can be passed other objects with a count() method.214 >>> class Container:215 ... def __len__(self):216 ... return 42217 >>> paginator = ObjectPaginator(Container(), 10)218 >>> paginator.hits219 42220 >>> paginator.pages221 5222 >>> paginator.page_range223 [1, 2, 3, 4, 5]224 225 226 139 ################## 227 140 # Orphan support # 228 141 ################## … … 237 150 1 238 151 239 152 # With orphans only set to 1, we should get two pages. 240 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1)153 >>> paginator = Paginator(Article.objects.all(), 10, orphans=1) 241 154 >>> paginator.num_pages 242 155 2 243 244 # LEGACY: With orphans set to 3 and 10 items per page, we should get all 12 items on a single page.245 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=3)246 >>> paginator.pages247 1248 249 # LEGACY: With orphans only set to 1, we should get two pages.250 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1)251 >>> paginator.pages252 2253 156 """} -
tests/regressiontests/max_lengths/tests.py
13 13 self.verify_max_length(PersonWithDefaultMaxLengths, 'homepage', 200) 14 14 self.verify_max_length(PersonWithDefaultMaxLengths, 'avatar', 100) 15 15 16 def test_custom_max lengths(self):16 def test_custom_max_lengths(self): 17 17 self.verify_max_length(PersonWithCustomMaxLengths, 'email', 384) 18 18 self.verify_max_length(PersonWithCustomMaxLengths, 'vcard', 1024) 19 19 self.verify_max_length(PersonWithCustomMaxLengths, 'homepage', 256) -
tests/regressiontests/maxlength/tests.py
1 # Test access to max_length while still providing full backwards compatibility2 # with legacy maxlength attribute.3 """4 5 Don't print out the deprecation warnings during testing.6 >>> from warnings import filterwarnings7 >>> filterwarnings("ignore")8 9 # legacy_maxlength function10 11 >>> from django.utils.maxlength import legacy_maxlength12 13 >>> legacy_maxlength(None, None)14 15 16 >>> legacy_maxlength(10, None)17 1018 19 >>> legacy_maxlength(None, 10)20 1021 22 >>> legacy_maxlength(10, 12)23 Traceback (most recent call last):24 ...25 TypeError: Field cannot take both the max_length argument and the legacy maxlength argument.26 27 >>> legacy_maxlength(0, 10)28 Traceback (most recent call last):29 ...30 TypeError: Field cannot take both the max_length argument and the legacy maxlength argument.31 32 >>> legacy_maxlength(0, None)33 034 35 >>> legacy_maxlength(None, 0)36 037 38 #===============================================================================39 # Fields40 #===============================================================================41 42 # Set up fields43 >>> from django.db.models import fields44 >>> new = fields.Field(max_length=15)45 >>> old = fields.Field(maxlength=10)46 47 # Ensure both max_length and legacy maxlength are not able to both be specified48 >>> fields.Field(maxlength=10, max_length=15)49 Traceback (most recent call last):50 ...51 TypeError: Field cannot take both the max_length argument and the legacy maxlength argument.52 53 # Test max_length54 >>> new.max_length55 1556 >>> old.max_length57 1058 59 # Test accessing maxlength60 >>> new.maxlength61 1562 >>> old.maxlength63 1064 65 # Test setting maxlength66 >>> new.maxlength += 167 >>> old.maxlength += 168 >>> new.max_length69 1670 >>> old.max_length71 1172 73 # SlugField __init__ passes through max_length so test that too74 >>> fields.SlugField('new', max_length=15).max_length75 1576 >>> fields.SlugField('empty').max_length77 5078 >>> fields.SlugField('old', maxlength=10).max_length79 1080 81 #===============================================================================82 # (old)forms83 #===============================================================================84 85 >>> from django import oldforms86 87 # Test max_length attribute88 89 >>> oldforms.TextField('new', max_length=15).render('')90 u'<input type="text" id="id_new" class="vTextField" name="new" size="30" value="" maxlength="15" />'91 92 >>> oldforms.IntegerField('new', max_length=15).render('')93 u'<input type="text" id="id_new" class="vIntegerField" name="new" size="10" value="" maxlength="15" />'94 95 >>> oldforms.SmallIntegerField('new', max_length=15).render('')96 u'<input type="text" id="id_new" class="vSmallIntegerField" name="new" size="5" value="" maxlength="15" />'97 98 >>> oldforms.PositiveIntegerField('new', max_length=15).render('')99 u'<input type="text" id="id_new" class="vPositiveIntegerField" name="new" size="10" value="" maxlength="15" />'100 101 >>> oldforms.PositiveSmallIntegerField('new', max_length=15).render('')102 u'<input type="text" id="id_new" class="vPositiveSmallIntegerField" name="new" size="5" value="" maxlength="15" />'103 104 >>> oldforms.DatetimeField('new', max_length=15).render('')105 u'<input type="text" id="id_new" class="vDatetimeField" name="new" size="30" value="" maxlength="15" />'106 107 >>> oldforms.EmailField('new', max_length=15).render('')108 u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="15" />'109 >>> oldforms.EmailField('new').render('')110 u'<input type="text" id="id_new" class="vEmailField" name="new" size="50" value="" maxlength="75" />'111 112 >>> oldforms.URLField('new', max_length=15).render('')113 u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="15" />'114 >>> oldforms.URLField('new').render('')115 u'<input type="text" id="id_new" class="vURLField" name="new" size="50" value="" maxlength="200" />'116 117 >>> oldforms.IPAddressField('new', max_length=15).render('')118 u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />'119 >>> oldforms.IPAddressField('new').render('')120 u'<input type="text" id="id_new" class="vIPAddressField" name="new" size="15" value="" maxlength="15" />'121 122 >>> oldforms.CommaSeparatedIntegerField('new', max_length=15).render('')123 u'<input type="text" id="id_new" class="vCommaSeparatedIntegerField" name="new" size="20" value="" maxlength="15" />'124 125 126 # Test legacy maxlength attribute127 128 >>> oldforms.TextField('old', maxlength=10).render('')129 u'<input type="text" id="id_old" class="vTextField" name="old" size="30" value="" maxlength="10" />'130 131 >>> oldforms.IntegerField('old', maxlength=10).render('')132 u'<input type="text" id="id_old" class="vIntegerField" name="old" size="10" value="" maxlength="10" />'133 134 >>> oldforms.SmallIntegerField('old', maxlength=10).render('')135 u'<input type="text" id="id_old" class="vSmallIntegerField" name="old" size="5" value="" maxlength="10" />'136 137 >>> oldforms.PositiveIntegerField('old', maxlength=10).render('')138 u'<input type="text" id="id_old" class="vPositiveIntegerField" name="old" size="10" value="" maxlength="10" />'139 140 >>> oldforms.PositiveSmallIntegerField('old', maxlength=10).render('')141 u'<input type="text" id="id_old" class="vPositiveSmallIntegerField" name="old" size="5" value="" maxlength="10" />'142 143 >>> oldforms.DatetimeField('old', maxlength=10).render('')144 u'<input type="text" id="id_old" class="vDatetimeField" name="old" size="30" value="" maxlength="10" />'145 146 >>> oldforms.EmailField('old', maxlength=10).render('')147 u'<input type="text" id="id_old" class="vEmailField" name="old" size="50" value="" maxlength="10" />'148 149 >>> oldforms.URLField('old', maxlength=10).render('')150 u'<input type="text" id="id_old" class="vURLField" name="old" size="50" value="" maxlength="10" />'151 152 >>> oldforms.IPAddressField('old', maxlength=10).render('')153 u'<input type="text" id="id_old" class="vIPAddressField" name="old" size="15" value="" maxlength="10" />'154 155 >>> oldforms.CommaSeparatedIntegerField('old', maxlength=10).render('')156 u'<input type="text" id="id_old" class="vCommaSeparatedIntegerField" name="old" size="20" value="" maxlength="10" />'157 """158 if __name__ == "__main__":159 import doctest160 doctest.testmod() -
docs/model-api.txt
144 144 (in characters) of the field. The max_length is enforced at the database level 145 145 and in Django's validation. 146 146 147 Django veterans: Note that the argument is now called ``max_length`` to148 provide consistency throughout Django. There is full legacy support for149 the old ``maxlength`` argument, but ``max_length`` is preferred.150 151 147 ``CommaSeparatedIntegerField`` 152 148 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 153 149 -
docs/pagination.txt
135 135 ``number`` -- The 1-based page number for this page. 136 136 137 137 ``paginator`` -- The associated ``Paginator`` object. 138 139 The legacy ``ObjectPaginator`` class140 ====================================141 142 The ``Paginator`` and ``Page`` classes are new in the Django development143 version, as of revision 7306. In previous versions, Django provided an144 ``ObjectPaginator`` class that offered similar functionality but wasn't as145 convenient. This class still exists, for backwards compatibility, but Django146 now issues a ``DeprecationWarning`` if you try to use it. -
docs/cache.txt
159 159 160 160 CACHE_BACKEND = 'locmem:///' 161 161 162 Simple caching (for development)163 --------------------------------164 165 A simple, single-process memory cache is available as ``"simple:///"``. This166 merely saves cached data in-process, which means it should only be used in167 development or testing environments. For example::168 169 CACHE_BACKEND = 'simple:///'170 171 **New in Django development version:** This cache backend is deprecated and172 will be removed in a future release. New code should use the ``locmem`` backend173 instead.174 175 162 Dummy caching (for development) 176 163 ------------------------------- 177 164 -
docs/sessions.txt
65 65 .. note:: 66 66 67 67 You should probably only use cache-based sessions if you're using the 68 memcached cache backend. The local memory and simple cache backends69 don't retain data long enough to be good choices, and it'll be faster70 to use file or database sessions directly instead of sending everything71 through the fileor database cache backends.68 Memcached cache backend. The local-memory cache backend doesn't retain data 69 long enough to be a good choice, and it'll be faster to use file or 70 database sessions directly instead of sending everything through the file 71 or database cache backends. 72 72 73 73 Using sessions in views 74 74 =======================