Changeset 8191
- Timestamp:
- 08/01/08 23:56:11 (4 months ago)
- Files:
-
- django/trunk/django/core/cache/__init__.py (modified) (2 diffs)
- django/trunk/django/core/paginator.py (modified) (1 diff)
- django/trunk/django/db/models/fields/__init__.py (modified) (2 diffs)
- django/trunk/django/db/models/fields/related.py (modified) (1 diff)
- django/trunk/django/db/models/fields/subclassing.py (modified) (2 diffs)
- django/trunk/django/db/models/query.py (modified) (1 diff)
- django/trunk/django/oldforms/__init__.py (modified) (2 diffs)
- django/trunk/django/utils/maxlength.py (deleted)
- django/trunk/docs/cache.txt (modified) (1 diff)
- django/trunk/docs/model-api.txt (modified) (1 diff)
- django/trunk/docs/pagination.txt (modified) (1 diff)
- django/trunk/docs/sessions.txt (modified) (1 diff)
- django/trunk/tests/modeltests/pagination/models.py (modified) (4 diffs)
- django/trunk/tests/regressiontests/maxlength (deleted)
- django/trunk/tests/regressiontests/max_lengths/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/core/cache/__init__.py
r8075 r8191 31 31 } 32 32 33 DEPRECATED_BACKENDS = {34 # deprecated backend --> replacement module35 'simple': 'locmem',36 }37 38 33 def get_cache(backend_uri): 39 34 if backend_uri.find(':') == -1: … … 42 37 if not rest.startswith('//'): 43 38 raise InvalidCacheBackendError, "Backend URI must start with scheme://" 44 if scheme in DEPRECATED_BACKENDS:45 import warnings46 warnings.warn("'%s' backend is deprecated. Use '%s' instead." %47 (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning)48 scheme = DEPRECATED_BACKENDS[scheme]49 39 50 40 host = rest[2:] django/trunk/django/core/paginator.py
r8129 r8191 119 119 return self.paginator.count 120 120 return self.number * self.paginator.per_page 121 122 class ObjectPaginator(Paginator):123 """124 Legacy ObjectPaginator class, for backwards compatibility.125 126 Note that each method on this class that takes page_number expects a127 zero-based page number, whereas the new API (Paginator/Page) uses one-based128 page numbers.129 """130 def __init__(self, query_set, num_per_page, orphans=0):131 Paginator.__init__(self, query_set, num_per_page, orphans)132 import warnings133 warnings.warn("The ObjectPaginator is deprecated. Use django.core.paginator.Paginator instead.", DeprecationWarning)134 135 # Keep these attributes around for backwards compatibility.136 self.query_set = query_set137 self.num_per_page = num_per_page138 self._hits = self._pages = None139 140 def validate_page_number(self, page_number):141 try:142 page_number = int(page_number) + 1143 except ValueError:144 raise PageNotAnInteger145 return self.validate_number(page_number)146 147 def get_page(self, page_number):148 try:149 page_number = int(page_number) + 1150 except ValueError:151 raise PageNotAnInteger152 return self.page(page_number).object_list153 154 def has_next_page(self, page_number):155 return page_number < self.pages - 1156 157 def has_previous_page(self, page_number):158 return page_number > 0159 160 def first_on_page(self, page_number):161 """162 Returns the 1-based index of the first object on the given page,163 relative to total objects found (hits).164 """165 page_number = self.validate_page_number(page_number)166 return (self.num_per_page * (page_number - 1)) + 1167 168 def last_on_page(self, page_number):169 """170 Returns the 1-based index of the last object on the given page,171 relative to total objects found (hits).172 """173 page_number = self.validate_page_number(page_number)174 if page_number == self.num_pages:175 return self.count176 return page_number * self.num_per_page177 178 # The old API called it "hits" instead of "count".179 hits = Paginator.count180 181 # The old API called it "pages" instead of "num_pages".182 pages = Paginator.num_pagesdjango/trunk/django/db/models/fields/__init__.py
r8143 r8191 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 … … 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. django/trunk/django/db/models/fields/related.py
r8138 r8191 626 626 to_field = to_field or to._meta.pk.name 627 627 kwargs['verbose_name'] = kwargs.get('verbose_name', None) 628 629 if 'edit_inline_type' in kwargs:630 import warnings631 warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.", DeprecationWarning)632 kwargs['edit_inline'] = kwargs.pop('edit_inline_type')633 628 634 629 kwargs['rel'] = rel_class(to, to_field, django/trunk/django/db/models/fields/subclassing.py
r7294 r8191 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 … … 51 49 52 50 return contribute_to_class 53 django/trunk/django/db/models/query.py
r8128 r8191 756 756 # (it raises StopIteration immediately). 757 757 yield iter([]).next() 758 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 758 775 759 django/trunk/django/oldforms/__init__.py
r7859 r8191 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_' … … 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): django/trunk/docs/cache.txt
r8075 r8191 159 159 160 160 CACHE_BACKEND = 'locmem:///' 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 161 175 162 Dummy caching (for development) django/trunk/docs/model-api.txt
r8167 r8191 144 144 (in characters) of the field. The max_length is enforced at the database level 145 145 and in Django's validation. 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 146 151 147 ``CommaSeparatedIntegerField`` django/trunk/docs/pagination.txt
r8121 r8191 138 138 139 139 ``paginator`` -- The associated ``Paginator`` object. 140 141 The legacy ``ObjectPaginator`` class142 ====================================143 144 The ``Paginator`` and ``Page`` classes are new in the Django development145 version, as of revision 7306. In previous versions, Django provided an146 ``ObjectPaginator`` class that offered similar functionality but wasn't as147 convenient. This class still exists, for backwards compatibility, but Django148 now issues a ``DeprecationWarning`` if you try to use it.django/trunk/docs/sessions.txt
r7844 r8191 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 django/trunk/tests/modeltests/pagination/models.py
r8121 r8191 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 … … 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 … … 166 161 167 162 168 ################################169 # Legacy API (ObjectPaginator) #170 ################################171 172 # Don't print out the deprecation warnings during testing.173 >>> from warnings import filterwarnings174 >>> filterwarnings("ignore")175 176 >>> from django.core.paginator import ObjectPaginator, EmptyPage177 >>> paginator = ObjectPaginator(Article.objects.all(), 5)178 >>> paginator.hits179 9180 >>> paginator.pages181 2182 >>> paginator.page_range183 [1, 2]184 185 # Get the first page.186 >>> paginator.get_page(0)187 [<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>, <Article: Article 5>]188 >>> paginator.has_next_page(0)189 True190 >>> paginator.has_previous_page(0)191 False192 >>> paginator.first_on_page(0)193 1194 >>> paginator.last_on_page(0)195 5196 197 # Get the second page.198 >>> paginator.get_page(1)199 [<Article: Article 6>, <Article: Article 7>, <Article: Article 8>, <Article: Article 9>]200 >>> paginator.has_next_page(1)201 False202 >>> paginator.has_previous_page(1)203 True204 >>> paginator.first_on_page(1)205 6206 >>> paginator.last_on_page(1)207 9208 209 # Invalid pages raise EmptyPage.210 >>> paginator.get_page(-1)211 Traceback (most recent call last):212 ...213 EmptyPage: ...214 >>> paginator.get_page(2)215 Traceback (most recent call last):216 ...217 EmptyPage: ...218 219 # Empty paginators with allow_empty_first_page=True.220 >>> paginator = ObjectPaginator(Article.objects.filter(id=0), 5)221 >>> paginator.count222 0223 >>> paginator.num_pages224 1225 >>> paginator.page_range226 [1]227 228 # ObjectPaginator can be passed lists too.229 >>> paginator = ObjectPaginator([1, 2, 3], 5)230 >>> paginator.hits231 3232 >>> paginator.pages233 1234 >>> paginator.page_range235 [1]236 237 238 # ObjectPaginator can be passed other objects without a count() method.239 >>> class Container:240 ... def __len__(self):241 ... return 42242 >>> paginator = ObjectPaginator(Container(), 10)243 >>> paginator.hits244 42245 >>> paginator.pages246 5247 >>> paginator.page_range248 [1, 2, 3, 4, 5]249 250 251 163 ################## 252 164 # Orphan support # … … 263 175 264 176 # With orphans only set to 1, we should get two pages. 265 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1)177 >>> paginator = Paginator(Article.objects.all(), 10, orphans=1) 266 178 >>> paginator.num_pages 267 179 2 268 269 # LEGACY: With orphans set to 3 and 10 items per page, we should get all 12 items on a single page.270 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=3)271 >>> paginator.pages272 1273 274 # LEGACY: With orphans only set to 1, we should get two pages.275 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1)276 >>> paginator.pages277 2278 180 """} django/trunk/tests/regressiontests/max_lengths/tests.py
r7294 r8191 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)
