Django

Code

Changeset 8191

Show
Ignore:
Timestamp:
08/01/08 23:56:11 (4 months ago)
Author:
gwilson
Message:

Removed several deprecated features for 1.0 (refs #7830):

  • "simple" cache backend
  • ObjectPaginator
  • edit_inline_type argument for ForeignKey fields
  • QOperator, QNot, QAnd and QOr
  • maxlength argument
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/cache/__init__.py

    r8075 r8191  
    3131} 
    3232 
    33 DEPRECATED_BACKENDS = { 
    34     # deprecated backend --> replacement module 
    35     'simple': 'locmem', 
    36 } 
    37  
    3833def get_cache(backend_uri): 
    3934    if backend_uri.find(':') == -1: 
     
    4237    if not rest.startswith('//'): 
    4338        raise InvalidCacheBackendError, "Backend URI must start with scheme://" 
    44     if scheme in DEPRECATED_BACKENDS: 
    45         import warnings 
    46         warnings.warn("'%s' backend is deprecated. Use '%s' instead." %  
    47             (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning) 
    48         scheme = DEPRECATED_BACKENDS[scheme] 
    4939 
    5040    host = rest[2:] 
  • django/trunk/django/core/paginator.py

    r8129 r8191  
    119119            return self.paginator.count 
    120120        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 a 
    127     zero-based page number, whereas the new API (Paginator/Page) uses one-based 
    128     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 warnings 
    133         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_set 
    137         self.num_per_page = num_per_page 
    138         self._hits = self._pages = None 
    139  
    140     def validate_page_number(self, page_number): 
    141         try: 
    142             page_number = int(page_number) + 1 
    143         except ValueError: 
    144             raise PageNotAnInteger 
    145         return self.validate_number(page_number) 
    146  
    147     def get_page(self, page_number): 
    148         try: 
    149             page_number = int(page_number) + 1 
    150         except ValueError: 
    151             raise PageNotAnInteger 
    152         return self.page(page_number).object_list 
    153  
    154     def has_next_page(self, page_number): 
    155         return page_number < self.pages - 1 
    156  
    157     def has_previous_page(self, page_number): 
    158         return page_number > 0 
    159  
    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)) + 1 
    167  
    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.count 
    176         return page_number * self.num_per_page 
    177  
    178     # The old API called it "hits" instead of "count". 
    179     hits = Paginator.count 
    180  
    181     # The old API called it "pages" instead of "num_pages". 
    182     pages = Paginator.num_pages 
  • django/trunk/django/db/models/fields/__init__.py

    r8143 r8191  
    2323from django.utils.translation import ugettext_lazy, ugettext as _ 
    2424from django.utils.encoding import smart_unicode, force_unicode, smart_str 
    25 from django.utils.maxlength import LegacyMaxlength 
    2625from django.utils import datetime_safe 
    2726 
     
    6362 
    6463class Field(object): 
    65     # Provide backwards compatibility for the maxlength attribute and 
    66     # argument for this class and all subclasses. 
    67     __metaclass__ = LegacyMaxlength 
    68  
    6964    # Designates whether empty strings fundamentally are allowed at the 
    7065    # database level. 
  • django/trunk/django/db/models/fields/related.py

    r8138 r8191  
    626626            to_field = to_field or to._meta.pk.name 
    627627        kwargs['verbose_name'] = kwargs.get('verbose_name', None) 
    628  
    629         if 'edit_inline_type' in kwargs: 
    630             import warnings 
    631             warnings.warn("edit_inline_type is deprecated. Use edit_inline instead.", DeprecationWarning) 
    632             kwargs['edit_inline'] = kwargs.pop('edit_inline_type') 
    633628 
    634629        kwargs['rel'] = rel_class(to, to_field, 
  • django/trunk/django/db/models/fields/subclassing.py

    r7294 r8191  
    66""" 
    77 
    8 from django.utils.maxlength import LegacyMaxlength 
    9  
    10 class SubfieldBase(LegacyMaxlength): 
     8class SubfieldBase(type): 
    119    """ 
    1210    A metaclass for custom Field subclasses. This ensures the model's attribute 
     
    5149 
    5250    return contribute_to_class 
    53  
  • django/trunk/django/db/models/query.py

    r8128 r8191  
    756756        # (it raises StopIteration immediately). 
    757757        yield iter([]).next() 
    758  
    759  
    760 # QOperator, QNot, QAnd and QOr are temporarily retained for backwards 
    761 # 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 = QOperator 
    769  
    770  
    771 def QNot(q): 
    772     warnings.warn('Use ~q instead of QNot(q)', DeprecationWarning, stacklevel=2) 
    773     return ~q 
    774758 
    775759 
  • django/trunk/django/oldforms/__init__.py

    r7859 r8191  
    66from django.utils.translation import ugettext, ungettext 
    77from django.utils.encoding import smart_unicode, force_unicode 
    8 from django.utils.maxlength import LegacyMaxlength 
    98 
    109FORM_FIELD_ID_PREFIX = 'id_' 
     
    305304    for rending the form field in XHTML. 
    306305    """ 
    307     # Provide backwards compatibility for the maxlength attribute and 
    308     # argument for this class and all subclasses. 
    309     __metaclass__ = LegacyMaxlength 
    310306 
    311307    def __str__(self): 
  • django/trunk/docs/cache.txt

    r8075 r8191  
    159159 
    160160    CACHE_BACKEND = 'locmem:///' 
    161  
    162 Simple caching (for development) 
    163 -------------------------------- 
    164  
    165 A simple, single-process memory cache is available as ``"simple:///"``. This 
    166 merely saves cached data in-process, which means it should only be used in 
    167 development or testing environments. For example:: 
    168  
    169     CACHE_BACKEND = 'simple:///' 
    170  
    171 **New in Django development version:** This cache backend is deprecated and 
    172 will be removed in a future release. New code should use the ``locmem`` backend 
    173 instead. 
    174161 
    175162Dummy caching (for development) 
  • django/trunk/docs/model-api.txt

    r8167 r8191  
    144144(in characters) of the field. The max_length is enforced at the database level 
    145145and in Django's validation. 
    146  
    147 Django veterans: Note that the argument is now called ``max_length`` to 
    148 provide consistency throughout Django. There is full legacy support for 
    149 the old ``maxlength`` argument, but ``max_length`` is preferred. 
    150146 
    151147``CommaSeparatedIntegerField`` 
  • django/trunk/docs/pagination.txt

    r8121 r8191  
    138138 
    139139``paginator`` -- The associated ``Paginator`` object. 
    140  
    141 The legacy ``ObjectPaginator`` class 
    142 ==================================== 
    143  
    144 The ``Paginator`` and ``Page`` classes are new in the Django development 
    145 version, as of revision 7306. In previous versions, Django provided an 
    146 ``ObjectPaginator`` class that offered similar functionality but wasn't as 
    147 convenient. This class still exists, for backwards compatibility, but Django 
    148 now issues a ``DeprecationWarning`` if you try to use it. 
  • django/trunk/docs/sessions.txt

    r7844 r8191  
    6666 
    6767    You should probably only use cache-based sessions if you're using the 
    68     memcached cache backend. The local memory and simple cache backends 
    69     don't retain data long enough to be good choices, and it'll be faste
    70     to use file or database sessions directly instead of sending everything 
    71     through the file or 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 o
     70    database sessions directly instead of sending everything through the file 
     71    or database cache backends. 
    7272 
    7373Using sessions in views 
  • django/trunk/tests/modeltests/pagination/models.py

    r8121 r8191  
    55of code. This is often useful for dividing search results or long lists of 
    66objects into easily readable pages. 
    7  
    8 In Django 0.96 and earlier, a single ObjectPaginator class implemented this 
    9 functionality. In the Django development version, the behavior is split across 
    10 two classes -- Paginator and Page -- that are more easier to use. The legacy 
    11 ObjectPaginator class is deprecated. 
    127""" 
    138 
     
    2823...     a.save() 
    2924 
    30 #################################### 
    31 # New/current API (Paginator/Page)
    32 #################################### 
     25################## 
     26# Paginator/Page
     27################## 
    3328 
    3429>>> from django.core.paginator import Paginator 
     
    166161 
    167162 
    168 ################################ 
    169 # Legacy API (ObjectPaginator) # 
    170 ################################ 
    171  
    172 # Don't print out the deprecation warnings during testing. 
    173 >>> from warnings import filterwarnings 
    174 >>> filterwarnings("ignore") 
    175  
    176 >>> from django.core.paginator import ObjectPaginator, EmptyPage 
    177 >>> paginator = ObjectPaginator(Article.objects.all(), 5) 
    178 >>> paginator.hits 
    179 9 
    180 >>> paginator.pages 
    181 2 
    182 >>> paginator.page_range 
    183 [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 True 
    190 >>> paginator.has_previous_page(0) 
    191 False 
    192 >>> paginator.first_on_page(0) 
    193 1 
    194 >>> paginator.last_on_page(0) 
    195 5 
    196  
    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 False 
    202 >>> paginator.has_previous_page(1) 
    203 True 
    204 >>> paginator.first_on_page(1) 
    205 6 
    206 >>> paginator.last_on_page(1) 
    207 9 
    208  
    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.count 
    222 0 
    223 >>> paginator.num_pages 
    224 1 
    225 >>> paginator.page_range 
    226 [1] 
    227  
    228 # ObjectPaginator can be passed lists too. 
    229 >>> paginator = ObjectPaginator([1, 2, 3], 5) 
    230 >>> paginator.hits 
    231 3 
    232 >>> paginator.pages 
    233 1 
    234 >>> paginator.page_range 
    235 [1] 
    236  
    237  
    238 # ObjectPaginator can be passed other objects without a count() method. 
    239 >>> class Container: 
    240 ...     def __len__(self): 
    241 ...         return 42 
    242 >>> paginator = ObjectPaginator(Container(), 10) 
    243 >>> paginator.hits 
    244 42 
    245 >>> paginator.pages 
    246 5 
    247 >>> paginator.page_range 
    248 [1, 2, 3, 4, 5] 
    249  
    250  
    251163################## 
    252164# Orphan support # 
     
    263175 
    264176# 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) 
    266178>>> paginator.num_pages 
    2671792 
    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.pages 
    272 1 
    273  
    274 # LEGACY: With orphans only set to 1, we should get two pages. 
    275 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1) 
    276 >>> paginator.pages 
    277 2 
    278180"""} 
  • django/trunk/tests/regressiontests/max_lengths/tests.py

    r7294 r8191  
    1414        self.verify_max_length(PersonWithDefaultMaxLengths, 'avatar', 100) 
    1515 
    16     def test_custom_maxlengths(self): 
     16    def test_custom_max_lengths(self): 
    1717        self.verify_max_length(PersonWithCustomMaxLengths, 'email', 384) 
    1818        self.verify_max_length(PersonWithCustomMaxLengths, 'vcard', 1024)