1.3.txt 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. ============================================
  2. Django 1.3 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. This page documents release notes for the as-yet-unreleased Django
  5. 1.3. As such, it's tentative and subject to change. It provides
  6. up-to-date information for those who are following trunk.
  7. Django 1.3 includes a number of nifty `new features`_, lots of bug
  8. fixes, some minor `backwards incompatible changes`_ and an easy
  9. upgrade path from Django 1.2.
  10. .. _new features: `What's new in Django 1.3`_
  11. .. _backwards incompatible changes: backwards-incompatible-changes-1.3_
  12. What's new in Django 1.3
  13. ========================
  14. Class-based views
  15. ~~~~~~~~~~~~~~~~~
  16. Django 1.3 adds a framework that allows you to use a class as a view.
  17. This means you can compose a view out of a collection of methods that
  18. can be subclassed and overridden to provide common views of data without
  19. having to write too much code.
  20. Analogs of all the old function-based generic views have been
  21. provided, along with a completely generic view base class that can be
  22. used as the basis for reusable applications that can be easily
  23. extended.
  24. See :doc:`the documentation on Class-based Generic Views</topics/class-based-views>`
  25. for more details. There is also a document to help you :doc:`convert
  26. your function-based generic views to class-based
  27. views</topics/generic-views-migration>`.
  28. Logging
  29. ~~~~~~~
  30. Django 1.3 adds framework-level support for Python's logging module.
  31. This means you can now easily configure and control logging as part of
  32. your Django project. A number of logging handlers and logging calls
  33. have been added to Django's own code as well -- most notably, the
  34. error emails sent on a HTTP 500 server error are now handled as a
  35. logging activity. See :doc:`the documentation on Django's logging
  36. interface </topics/logging>` for more details.
  37. Extended static files handling
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. Django 1.3 ships with a new contrib app ``'django.contrib.staticfiles'``
  40. to help developers handle the static media files (images, CSS, Javascript,
  41. etc.) that are needed to render a complete web page.
  42. In previous versions of Django, it was common to place static assets in
  43. :setting:`MEDIA_ROOT` along with user-uploaded files, and serve them both at
  44. :setting:`MEDIA_URL`. Part of the purpose of introducing the ``staticfiles``
  45. app is to make it easier to keep static files separate from user-uploaded
  46. files. For this reason, you will probably want to make your
  47. :setting:`MEDIA_ROOT` and :setting:`MEDIA_URL` different from your
  48. :setting:`STATIC_ROOT` and :setting:`STATIC_URL`. You will need to
  49. arrange for serving of files in :setting:`MEDIA_ROOT` yourself;
  50. ``staticfiles`` does not deal with user-uploaded media at all.
  51. See the :doc:`reference documentation of the app </ref/contrib/staticfiles>`
  52. for more details or learn how to :doc:`manage static files
  53. </howto/static-files>`.
  54. ``unittest2`` support
  55. ~~~~~~~~~~~~~~~~~~~~~
  56. Python 2.7 introduced some major changes to the unittest library,
  57. adding some extremely useful features. To ensure that every Django
  58. project can benefit from these new features, Django ships with a
  59. copy of unittest2_, a copy of the Python 2.7 unittest library,
  60. backported for Python 2.4 compatibility.
  61. To access this library, Django provides the
  62. ``django.utils.unittest`` module alias. If you are using Python
  63. 2.7, or you have installed unittest2 locally, Django will map the
  64. alias to the installed version of the unittest library. Otherwise,
  65. Django will use it's own bundled version of unittest2.
  66. To use this alias, simply use::
  67. from django.utils import unittest
  68. wherever you would have historically used::
  69. import unittest
  70. If you want to continue to use the base unittest libary, you can --
  71. you just won't get any of the nice new unittest2 features.
  72. .. _unittest2: http://pypi.python.org/pypi/unittest2
  73. Transaction context managers
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. Users of Python 2.5 and above may now use :ref:`transaction management functions
  76. <transaction-management-functions>` as `context managers`_. For example::
  77. with transaction.autocommit():
  78. # ...
  79. .. _context managers: http://docs.python.org/glossary.html#term-context-manager
  80. For more information, see :ref:`transaction-management-functions`.
  81. Configurable delete-cascade
  82. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. :class:`~django.db.models.ForeignKey` and
  84. :class:`~django.db.models.OneToOneField` now accept an
  85. :attr:`~django.db.models.ForeignKey.on_delete` argument to customize behavior
  86. when the referenced object is deleted. Previously, deletes were always
  87. cascaded; available alternatives now include set null, set default, set to any
  88. value, protect, or do nothing.
  89. For more information, see the :attr:`~django.db.models.ForeignKey.on_delete`
  90. documentation.
  91. Contextual markers and comments for translatable strings
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. For translation strings with ambiguous meaning, you can now
  94. use the ``pgettext`` function to specify the context of the string.
  95. And if you just want to add some information for translators, you
  96. can also add special translator comments in the source.
  97. For more information, see :ref:`contextual-markers` and
  98. :ref:`translator-comments`.
  99. TemplateResponse
  100. ~~~~~~~~~~~~~~~~
  101. It can sometimes be beneficial to allow decorators or middleware to
  102. modify a response *after* it has been constructed by the view. For
  103. example, you may want to change the template that is used, or put
  104. additional data into the context.
  105. However, you can't (easily) modify the content of a basic
  106. :class:`~django.http.HttpResponse` after it has been constructed. To
  107. overcome this limitation, Django 1.3 adds a new
  108. :class:`~django.template.TemplateResponse` class. Unlike basic
  109. :class:`~django.http.HttpResponse` objects,
  110. :class:`~django.template.TemplateResponse` objects retain the details
  111. of the template and context that was provided by the view to compute
  112. the response. The final output of the response is not computed until
  113. it is needed, later in the response process.
  114. For more details, see the :doc:`documentation </ref/template-response>`
  115. on the :class:`~django.template.TemplateResponse` class.
  116. Caching changes
  117. ~~~~~~~~~~~~~~~
  118. Django 1.3 sees the introduction of several improvements to the
  119. Django's caching infrastructure.
  120. Firstly, Django now supports multiple named caches. In the same way
  121. that Django 1.2 introduced support for multiple database connections,
  122. Django 1.3 allows you to use the new :setting:`CACHES` setting to
  123. define multiple named cache connections.
  124. Secondly, :ref:`Versioning <cache_versioning>`, :ref:`site-wide
  125. prefixing <cache_key_prefixing>` and :ref:`transformation
  126. <cache_key_transformation>` has been added to the cache API.
  127. Lastly, support for pylibmc_ has been added to the memcached cache
  128. backend.
  129. For more details, see the :doc:`documentation on
  130. caching in Django</topics/cache>`.
  131. .. _pylibmc: http://sendapatch.se/projects/pylibmc/
  132. Permissions for inactive users
  133. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  134. If you provide a custom auth backend with ``supports_inactive_user`` set to
  135. ``True``, an inactive user model will check the backend for permissions.
  136. This is useful for further centralizing the permission handling. See the
  137. :doc:`authentication docs </topics/auth>` for more details.
  138. GeoDjango
  139. ~~~~~~~~~
  140. The GeoDjango test suite is now included when
  141. :ref:`running the Django test suite <running-unit-tests>` with ``runtests.py``
  142. when using :ref:`spatial database backends <spatial-backends>`.
  143. ``MEDIA_URL`` and ``STATIC_URL`` must end in a slash
  144. ----------------------------------------------------
  145. Previously, the ``MEDIA_URL`` setting only required a trailing slash if it
  146. contained a suffix beyond the domain name.
  147. A trailing slash is now *required* for ``MEDIA_URL`` and the new
  148. ``STATIC_URL`` setting as long as it is not blank. This ensures there is
  149. a consistent way to combine paths in templates.
  150. Project settings which provide either of both settings without a trailing
  151. slash will now raise a ``PendingDeprecation`` warning.
  152. In Django 1.4 this same condition will raise an ``ImproperlyConfigured``
  153. exception.
  154. Everything else
  155. ~~~~~~~~~~~~~~~
  156. Django :doc:`1.1 <1.1>` and :doc:`1.2 <1.2>` added
  157. lots of big ticket items to Django, like multiple-database support,
  158. model validation, and a session-based messages framework. However,
  159. this focus on big features came at the cost of lots of smaller
  160. features.
  161. To compensate for this, the focus of the Django 1.3 development
  162. process has been on adding lots of smaller, long standing feature
  163. requests. These include:
  164. * Improved tools for accessing and manipulating the current Site.
  165. * A :class:`~django.test.client.RequestFactory` for mocking
  166. requests in tests.
  167. * A new test assertion --
  168. :meth:`~django.test.client.Client.assertNumQueries` -- making it
  169. easier to test the database activity associated with a view.
  170. * Support for lookups spanning relations in admin's ``list_filter``.
  171. * Support for _HTTPOnly cookies.
  172. * :meth:`mail_admins()` and :meth:`mail_managers()` now support
  173. easily attaching HTML content to messages.
  174. * :class:`EmailMessage` now supports CC's.
  175. * Error emails now include more of the detail and formatting of
  176. the debug server error page.
  177. * :meth:`simple_tag` now accepts a :attr:`takes_context` argument,
  178. making it easier to write simple template tags that require
  179. access to template context.
  180. * A new :meth:`~django.shortcuts.render()` shortcut -- an
  181. alternative to :meth:`~django.shortcuts.render_to_response()`
  182. providing a :class:`~django.template.RequestContext` by
  183. default.
  184. * Support for combining :ref:`F() expressions <query-expressions>`
  185. with timedelta values when retrieving or updating database values.
  186. .. _HTTPOnly: http://www.owasp.org/index.php/HTTPOnly
  187. .. _backwards-incompatible-changes-1.3:
  188. Backwards-incompatible changes in 1.3
  189. =====================================
  190. CSRF exception for AJAX requests
  191. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  192. Django includes a CSRF-protection mechanism, which makes use of a
  193. token inserted into outgoing forms. Middleware then checks for the
  194. token's presence on form submission, and validates it.
  195. Prior to Django 1.2.5, our CSRF protection made an exception for AJAX
  196. requests, on the following basis:
  197. * Many AJAX toolkits add an X-Requested-With header when using
  198. XMLHttpRequest.
  199. * Browsers have strict same-origin policies regarding
  200. XMLHttpRequest.
  201. * In the context of a browser, the only way that a custom header
  202. of this nature can be added is with XMLHttpRequest.
  203. Therefore, for ease of use, we did not apply CSRF checks to requests
  204. that appeared to be AJAX on the basis of the X-Requested-With header.
  205. The Ruby on Rails web framework had a similar exemption.
  206. Recently, engineers at Google made members of the Ruby on Rails
  207. development team aware of a combination of browser plugins and
  208. redirects which can allow an attacker to provide custom HTTP headers
  209. on a request to any website. This can allow a forged request to appear
  210. to be an AJAX request, thereby defeating CSRF protection which trusts
  211. the same-origin nature of AJAX requests.
  212. Michael Koziarski of the Rails team brought this to our attention, and
  213. we were able to produce a proof-of-concept demonstrating the same
  214. vulnerability in Django's CSRF handling.
  215. To remedy this, Django will now apply full CSRF validation to all
  216. requests, regardless of apparent AJAX origin. This is technically
  217. backwards-incompatible, but the security risks have been judged to
  218. outweigh the compatibility concerns in this case.
  219. Additionally, Django will now accept the CSRF token in the custom HTTP
  220. header X-CSRFTOKEN, as well as in the form submission itself, for ease
  221. of use with popular JavaScript toolkits which allow insertion of
  222. custom headers into all AJAX requests.
  223. Please see the :ref:`CSRF docs for example jQuery code <csrf-ajax>`
  224. that demonstrates this technique, ensuring that you are looking at the
  225. documentation for your version of Django, as the exact code necessary
  226. is different for some older versions of Django.
  227. Restricted filters in admin interface
  228. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  229. The Django administrative interface, django.contrib.admin, supports
  230. filtering of displayed lists of objects by fields on the corresponding
  231. models, including across database-level relationships. This is
  232. implemented by passing lookup arguments in the querystring portion of
  233. the URL, and options on the ModelAdmin class allow developers to
  234. specify particular fields or relationships which will generate
  235. automatic links for filtering.
  236. One historically-undocumented and -unofficially-supported feature has
  237. been the ability for a user with sufficient knowledge of a model's
  238. structure and the format of these lookup arguments to invent useful
  239. new filters on the fly by manipulating the querystring.
  240. However, it has been demonstrated that this can be abused to gain
  241. access to information outside of an admin user's permissions; for
  242. example, an attacker with access to the admin and sufficient knowledge
  243. of model structure and relations could construct query strings which --
  244. with repeated use of regular-expression lookups supported by the
  245. Django database API -- expose sensitive information such as users'
  246. password hashes.
  247. To remedy this, django.contrib.admin will now validate that
  248. querystring lookup arguments either specify only fields on the model
  249. being viewed, or cross relations which have been explicitly
  250. whitelisted by the application developer using the pre-existing
  251. mechanism mentioned above. This is backwards-incompatible for any
  252. users relying on the prior ability to insert arbitrary lookups.
  253. FileField no longer deletes files
  254. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  255. In earlier Django versions, when a model instance containing a
  256. :class:`~django.db.models.FileField` was deleted,
  257. :class:`~django.db.models.FileField` took it upon itself to also delete the
  258. file from the backend storage. This opened the door to several data-loss
  259. scenarios, including rolled-back transactions and fields on different models
  260. referencing the same file. In Django 1.3, :class:`~django.db.models.FileField`
  261. will never delete files from the backend storage. If you need cleanup of
  262. orphaned files, you'll need to handle it yourself (for instance, with a custom
  263. management command that can be run manually or scheduled to run periodically
  264. via e.g. cron).
  265. PasswordInput default rendering behavior
  266. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  267. The :class:`~django.forms.PasswordInput` form widget, intended for use
  268. with form fields which represent passwords, accepts a boolean keyword
  269. argument ``render_value`` indicating whether to send its data back to
  270. the browser when displaying a submitted form with errors. Prior to
  271. Django 1.3, this argument defaulted to ``True``, meaning that the
  272. submitted password would be sent back to the browser as part of the
  273. form. Developers who wished to add a bit of additional security by
  274. excluding that value from the redisplayed form could instantiate a
  275. :class:`~django.forms.PasswordInput` passing ``render_value=False`` .
  276. Due to the sensitive nature of passwords, however, Django 1.3 takes
  277. this step automatically; the default value of ``render_value`` is now
  278. ``False``, and developers who want the password value returned to the
  279. browser on a submission with errors (the previous behavior) must now
  280. explicitly indicate this. For example::
  281. class LoginForm(forms.Form):
  282. username = forms.CharField(max_length=100)
  283. password = forms.CharField(widget=forms.PasswordInput(render_value=True))
  284. Clearable default widget for FileField
  285. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  286. Django 1.3 now includes a ``ClearableFileInput`` form widget in addition to
  287. ``FileInput``. ``ClearableFileInput`` renders with a checkbox to clear the
  288. field's value (if the field has a value and is not required); ``FileInput``
  289. provided no means for clearing an existing file from a ``FileField``.
  290. ``ClearableFileInput`` is now the default widget for a ``FileField``, so
  291. existing forms including ``FileField`` without assigning a custom widget will
  292. need to account for the possible extra checkbox in the rendered form output.
  293. To return to the previous rendering (without the ability to clear the
  294. ``FileField``), use the ``FileInput`` widget in place of
  295. ``ClearableFileInput``. For instance, in a ``ModelForm`` for a hypothetical
  296. ``Document`` model with a ``FileField`` named ``document``::
  297. from django import forms
  298. from myapp.models import Document
  299. class DocumentForm(forms.ModelForm):
  300. class Meta:
  301. model = Document
  302. widgets = {'document': forms.FileInput}
  303. New index on database session table
  304. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  305. Prior to Django 1.3, the database table used by the database backend
  306. for the :doc:`sessions </topics/http/sessions>` app had no index on
  307. the ``expire_date`` column. As a result, date-based queries on the
  308. session table -- such as the query that is needed to purge old
  309. sessions -- would be very slow if there were lots of sessions.
  310. If you have an existing project that is using the database session
  311. backend, you don't have to do anything to accommodate this change.
  312. However, you may get a significant performance boost if you manually
  313. add the new index to the session table. The SQL that will add the
  314. index can be found by running the :djadmin:`sqlindexes` admin
  315. command::
  316. python manage.py sqlindexes sessions
  317. No more naughty words
  318. ~~~~~~~~~~~~~~~~~~~~~
  319. Django has historically provided (and enforced) a list of profanities.
  320. The :doc:`comments app </ref/contrib/comments/index>` has enforced this
  321. list of profanities, preventing people from submitting comments that
  322. contained one of those profanities.
  323. Unfortunately, the technique used to implement this profanities list
  324. was woefully naive, and prone to the `Scunthorpe problem`_. Fixing the
  325. built in filter to fix this problem would require significant effort,
  326. and since natural language processing isn't the normal domain of a web
  327. framework, we have "fixed" the problem by making the list of
  328. prohibited words an empty list.
  329. If you want to restore the old behavior, simply put a
  330. ``PROFANITIES_LIST`` setting in your settings file that includes the
  331. words that you want to prohibit (see the `commit that implemented this
  332. change`_ if you want to see the list of words that was historically
  333. prohibited). However, if avoiding profanities is important to you, you
  334. would be well advised to seek out a better, less naive approach to the
  335. problem.
  336. .. _Scunthorpe problem: http://en.wikipedia.org/wiki/Scunthorpe_problem
  337. .. _commit that implemented this change: http://code.djangoproject.com/changeset/13996
  338. Localflavor changes
  339. ~~~~~~~~~~~~~~~~~~~
  340. Django 1.3 introduces the following backwards-incompatible changes to
  341. local flavors:
  342. * Indonesia (id) -- The province "Nanggroe Aceh Darussalam (NAD)"
  343. has been removed from the province list in favor of the new
  344. official designation "Aceh (ACE)".
  345. FormSet updates
  346. ~~~~~~~~~~~~~~~
  347. In Django 1.3 ``FormSet`` creation behavior is modified slightly. Historically
  348. the class didn't make a distinction between not being passed data and being
  349. passed empty dictionary. This was inconsistent with behavior in other parts of
  350. the framework. Starting with 1.3 if you pass in empty dictionary the
  351. ``FormSet`` will raise a ``ValidationError``.
  352. For example with a ``FormSet``::
  353. >>> class ArticleForm(Form):
  354. ... title = CharField()
  355. ... pub_date = DateField()
  356. >>> ArticleFormSet = formset_factory(ArticleForm)
  357. the following code will raise a ``ValidationError``::
  358. >>> ArticleFormSet({})
  359. Traceback (most recent call last):
  360. ...
  361. ValidationError: [u'ManagementForm data is missing or has been tampered with']
  362. if you need to instantiate an empty ``FormSet``, don't pass in the data or use
  363. ``None``::
  364. >>> formset = ArticleFormSet()
  365. >>> formset = ArticleFormSet(data=None)
  366. Callables in templates
  367. ~~~~~~~~~~~~~~~~~~~~~~
  368. Previously, a callable in a template would only be called automatically as part
  369. of the variable resolution process if it was retrieved via attribute
  370. lookup. This was an inconsistency that could result in confusing and unhelpful
  371. behaviour::
  372. >>> Template("{{ user.get_full_name }}").render(Context({'user': user}))
  373. u'Joe Bloggs'
  374. >>> Template("{{ full_name }}").render(Context({'full_name': user.get_full_name}))
  375. u'&lt;bound method User.get_full_name of &lt;...
  376. This has been resolved in Django 1.3 - the result in both cases will be ``u'Joe
  377. Bloggs'``. Although the previous behaviour was not useful for a template language
  378. designed for web designers, and was never deliberately supported, it is possible
  379. that some templates may be broken by this change.
  380. Use of custom SQL to load initial data in tests
  381. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  382. Django provides a custom SQL hooks as a way to inject hand-crafted SQL
  383. into the database synchronization process. One of the possible uses
  384. for this custom SQL is to insert data into your database. If your
  385. custom SQL contains ``INSERT`` statements, those insertions will be
  386. performed every time your database is synchronized. This includes the
  387. synchronization of any test databases that are created when you run a
  388. test suite.
  389. However, in the process of testing the Django 1.3, it was discovered
  390. that this feature has never completely worked as advertised. When
  391. using database backends that don't support transactions, or when using
  392. a TransactionTestCase, data that has been inserted using custom SQL
  393. will not be visible during the testing process.
  394. Unfortunately, there was no way to rectify this problem without
  395. introducing a backwards incompatibility. Rather than leave
  396. SQL-inserted initial data in an uncertain state, Django now enforces
  397. the policy that data inserted by custom SQL will *not* be visible
  398. during testing.
  399. This change only affects the testing process. You can still use custom
  400. SQL to load data into your production database as part of the syncdb
  401. process. If you require data to exist during test conditions, you
  402. should either insert it using :ref:`test fixtures
  403. <topics-testing-fixtures>`, or using the ``setUp()`` method of your
  404. test case.
  405. Changed priority of translation loading
  406. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  407. Work has been done to homogeneize, simplify, rationalize and properly document
  408. the algorithm used by Django at runtime to build translations from the
  409. differents translations found on disk, namely:
  410. For translatable literals found in Python code and templates (``'django'``
  411. gettext domain):
  412. * Priorities of translations included with applications listed in the
  413. :setting:`INSTALLED_APPS` setting were changed. To provide a behavior
  414. consistent with other parts of Django that also use such setting (templates,
  415. etc.) now, when building the translation that will be made available, the
  416. apps listed first have higher precedence than the ones listed later.
  417. * Now it is possible to override the translations shipped with applications by
  418. using the :setting:`LOCALE_PATHS` setting whose translations have now higher
  419. precedence than the translations of ``INSTALLED_APPS`` applications.
  420. The relative priority among the values listed in this setting has also been
  421. modified so the paths listed first have higher precedence than the
  422. ones listed later.
  423. * The ``locale`` subdirectory of the directory containing the settings, that
  424. usually coincides with and is know as the *project directory* is being
  425. deprecated in this release as a source of translations. (the precedence of
  426. these translations is intermediate between applications and ``LOCALE_PATHS``
  427. translations). See the `corresponding deprecated features section`_
  428. of this document.
  429. For translatable literals found in Javascript code (``'djangojs'`` gettext
  430. domain):
  431. * Similarly to the ``'django'`` domain translations: Overriding of
  432. translations shipped with applications by using the :setting:`LOCALE_PATHS`
  433. setting is now possible for this domain too. These translations have higher
  434. precedence than the translations of Python packages passed to the
  435. :ref:`javascript_catalog view <javascript_catalog-view>`. Paths listed first
  436. have higher precedence than the ones listed later.
  437. * Translations under the ``locale`` sbdirectory of the *project directory* have
  438. never been taken in account for JavaScript translations and remain in the
  439. same situation considering the deprecation of such location.
  440. .. _corresponding deprecated features section: loading_of_translations_from_the_project_directory_
  441. Transaction management
  442. ~~~~~~~~~~~~~~~~~~~~~~
  443. When using managed transactions -- that is, anything but the default
  444. autocommit mode -- it is important when a transaction is marked as
  445. "dirty". Dirty transactions are committed by the
  446. :func:`~django.db.transaction.commit_on_success` decorator or the
  447. :class:`~django.middleware.transaction.TransactionMiddleware`, and
  448. :func:`~django.db.transaction.commit_manually` forces them to be
  449. closed explicitly; clean transactions "get a pass", which means they
  450. are usually rolled back at the end of a request when the connection is
  451. closed.
  452. Until Django 1.3, transactions were only marked dirty when Django was
  453. aware of a modifying operation performed in them; that is, either some
  454. model was saved, some bulk update or delete was performed, or the user
  455. explicitly called ``transaction.set_dirty()``. In Django 1.3, a
  456. transaction is marked dirty when *any* database operation is
  457. performed.
  458. As a result of this change, you no longer need to set a transaction
  459. dirty explicitly when you execute raw SQL or use a data-modifying
  460. ``SELECT``. However, you *do* need to explicitly close any read-only
  461. transactions that are being managed using
  462. :func:`~django.db.transaction.commit_manually`. For example::
  463. @transaction.commit_manually
  464. def my_view(request, name):
  465. obj = get_object_or_404(MyObject, name__iexact=name)
  466. return render_to_response('template', {'object':obj})
  467. Prior to Django 1.3, this would work without error. However, under
  468. Django 1.3, this will raise a :class:`TransactionManagementError` because
  469. the read operation that retrieves the ``MyObject`` instance leaves the
  470. transaction in a dirty state.
  471. .. _deprecated-features-1.3:
  472. Features deprecated in 1.3
  473. ==========================
  474. Django 1.3 deprecates some features from earlier releases.
  475. These features are still supported, but will be gradually phased out
  476. over the next few release cycles.
  477. Code taking advantage of any of the features below will raise a
  478. ``PendingDeprecationWarning`` in Django 1.3. This warning will be
  479. silent by default, but may be turned on using Python's `warnings
  480. module`_, or by running Python with a ``-Wd`` or `-Wall` flag.
  481. .. _warnings module: http://docs.python.org/library/warnings.html
  482. In Django 1.4, these warnings will become a ``DeprecationWarning``,
  483. which is *not* silent. In Django 1.5 support for these features will
  484. be removed entirely.
  485. .. seealso::
  486. For more details, see the documentation :doc:`Django's release process
  487. </internals/release-process>` and our :doc:`deprecation timeline
  488. </internals/deprecation>`.
  489. ``mod_python`` support
  490. ~~~~~~~~~~~~~~~~~~~~~~
  491. The ``mod_python`` library has not had a release since 2007 or a commit since
  492. 2008. The Apache Foundation board voted to remove ``mod_python`` from the set
  493. of active projects in its version control repositories, and its lead developer
  494. has shifted all of his efforts toward the lighter, slimmer, more stable, and
  495. more flexible ``mod_wsgi`` backend.
  496. If you are currently using the ``mod_python`` request handler, you
  497. should redeploy your Django projects using another request handler.
  498. :doc:`mod_wsgi </howto/deployment/modwsgi>` is the request handler
  499. recommended by the Django project, but :doc:`FastCGI
  500. </howto/deployment/fastcgi>` is also supported. Support for
  501. ``mod_python`` deployment will be removed in Django 1.5.
  502. Function-based generic views
  503. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  504. As a result of the introduction of class-based generic views, the
  505. function-based generic views provided by Django have been deprecated.
  506. The following modules and the views they contain have been deprecated:
  507. * :mod:`django.views.generic.create_update`
  508. * :mod:`django.views.generic.date_based`
  509. * :mod:`django.views.generic.list_detail`
  510. * :mod:`django.views.generic.simple`
  511. Test client response ``template`` attribute
  512. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  513. Django's :ref:`test client <test-client>` returns
  514. :class:`~django.test.client.Response` objects annotated with extra testing
  515. information. In Django versions prior to 1.3, this included a
  516. :attr:`~django.test.client.Response.template` attribute containing information
  517. about templates rendered in generating the response: either None, a single
  518. :class:`~django.template.Template` object, or a list of
  519. :class:`~django.template.Template` objects. This inconsistency in return values
  520. (sometimes a list, sometimes not) made the attribute difficult to work with.
  521. In Django 1.3 the :attr:`~django.test.client.Response.template` attribute is
  522. deprecated in favor of a new :attr:`~django.test.client.Response.templates`
  523. attribute, which is always a list, even if it has only a single element or no
  524. elements.
  525. ``DjangoTestRunner``
  526. ~~~~~~~~~~~~~~~~~~~~
  527. As a result of the introduction of support for unittest2, the features
  528. of :class:`django.test.simple.DjangoTestRunner` (including fail-fast
  529. and Ctrl-C test termination) have been made redundant. In view of this
  530. redundancy, :class:`~django.test.simple.DjangoTestRunner` has been
  531. turned into an empty placeholder class, and will be removed entirely
  532. in Django 1.5.
  533. Changes to :ttag:`url` and :ttag:`ssi`
  534. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  535. Most template tags will allow you to pass in either constants or
  536. variables as arguments -- for example::
  537. {% extends "base.html" %}
  538. allows you to specify a base template as a constant, but if you have a
  539. context variable ``templ`` that contains the value ``base.html``::
  540. {% extends templ %}
  541. is also legal.
  542. However, due to an accident of history, the :ttag:`url` and
  543. :ttag:`ssi` are different. These tags use the second, quoteless
  544. syntax, but interpret the argument as a constant. This means it isn't
  545. possible to use a context variable as the target of a :ttag:`url` and
  546. :ttag:`ssi` tag.
  547. Django 1.3 marks the start of the process to correct this historical
  548. accident. Django 1.3 adds a new template library -- ``future`` -- that
  549. provides alternate implementations of the :ttag:`url` and :ttag:`ssi`
  550. template tags. This ``future`` library implement behavior that makes
  551. the handling of the first argument consistent with the handling of all
  552. other variables. So, an existing template that contains::
  553. {% url sample %}
  554. should be replaced with::
  555. {% load url from future %}
  556. {% url 'sample' %}
  557. The tags implementing the old behavior have been deprecated, and in
  558. Django 1.5, the old behavior will be replaced with the new behavior.
  559. To ensure compatibility with future versions of Django, existing
  560. templates should be modified to use the new ``future`` libraries and
  561. syntax.
  562. Changes to the login methods of the admin
  563. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  564. In previous version the admin app defined login methods in multiple locations
  565. and ignored the almost identical implementation in the already used auth app.
  566. A side effect of this duplication was the missing adoption of the changes made
  567. in r12634_ to support a broader set of characters for usernames.
  568. This release refactores the admin's login mechanism to use a subclass of the
  569. :class:`~django.contrib.auth.forms.AuthenticationForm` instead of a manual
  570. form validation. The previously undocumented method
  571. ``'django.contrib.admin.sites.AdminSite.display_login_form'`` has been removed
  572. in favor of a new :attr:`~django.contrib.admin.AdminSite.login_form`
  573. attribute.
  574. .. _r12634: http://code.djangoproject.com/changeset/12634
  575. ``reset`` and ``sqlreset`` management commands
  576. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  577. Those commands have been deprecated. The ``flush`` and ``sqlflush`` commands
  578. can be used to delete everything. You can also use ALTER TABLE or DROP TABLE
  579. statements manually.
  580. GeoDjango
  581. ~~~~~~~~~
  582. * The function-based :setting:`TEST_RUNNER` previously used to execute
  583. the GeoDjango test suite, :func:`django.contrib.gis.tests.run_gis_tests`,
  584. was deprecated for the class-bassed runner,
  585. :class:`django.contrib.gis.tests.GeoDjangoTestSuiteRunner`.
  586. * Previously, calling :meth:`~django.contrib.gis.geos.GEOSGeometry.transform`
  587. would silently do nothing when GDAL wasn't available. Now,
  588. a :class:`~django.contrib.gis.geos.GEOSException` is properly raised
  589. to indicate possible faulty application code. A warning is now raised
  590. if :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` is called when
  591. the SRID of the geometry is less than 0 or ``None``.
  592. ``CZBirthNumberField.clean``
  593. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  594. Previously this field's ``clean()`` method accepted a second, gender, argument
  595. which allowed stronger validation checks to be made, however since this
  596. argument could never actually be passed from the Django form machinery it is
  597. now pending deprecation.
  598. ``CompatCookie``
  599. ~~~~~~~~~~~~~~~~
  600. Previously, ``django.http`` exposed an undocumented ``CompatCookie`` class,
  601. which was a bug-fix wrapper around the standard library ``SimpleCookie``. As the
  602. fixes are moving upstream, this is now deprecated - you should use ``from
  603. django.http import SimpleCookie`` instead.
  604. .. _loading_of_translations_from_the_project_directory:
  605. Loading of translations from the project directory
  606. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  607. This release of Django starts the deprecation process for inclusion of
  608. translations located under the *project path* in the translation building
  609. process performed at runtime. The :setting:`LOCALE_PATHS` setting can be used
  610. for the same task by including in it the filesystem path to the ``locale``
  611. directory containing project-level translations.
  612. Rationale for this decision:
  613. * The *project path* has always been a loosely defined concept (actually, the
  614. directory used for locating project-level translations is the directory
  615. containing the settings module) and there has been a shift in other parts
  616. of the framework to stop using it as a reference for location of assets at
  617. runtime.
  618. * Detection of the ``locale`` subdirectory tends to fail when the deployment
  619. scenario is more complex than the basic one. e.g. it fails when the settings
  620. module is a directory (ticket #10765).
  621. * Potential for strange development- and deployment-time problems like the
  622. fact that the ``project_dir/locale/`` subdir can generate spurious error
  623. messages when the project directory is included in the Python path (default
  624. behavior of ``manage.py runserver``) and then it clashes with the equally
  625. named standard library module, this is a typical warming message::
  626. /usr/lib/python2.6/gettext.py:49: ImportWarning: Not importing directory '/path/to/project/dir/locale': missing __init__.py.
  627. import locale, copy, os, re, struct, sys
  628. * This location wasn't included in the translation building process for
  629. JavaScript literals.
  630. ``PermWrapper`` moved to ``django.contrib.auth.context_processors``
  631. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  632. In Django 1.2, we began the process of changing the location of the
  633. ``auth`` context processor from ``django.core.context_processors`` to
  634. ``django.contrib.auth.context_processors``. However, the
  635. ``PermWrapper`` support class was mistakenly omitted from that
  636. migration. In Django 1.3, the ``PermWrapper`` class has also been
  637. moved to ``django.contrib.auth.context_processors``, along with the
  638. ``PermLookupDict`` support class. The new classes are functionally
  639. identical to their old versions; only the module location has changed.