1.3.txt 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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. The following example using the jQuery JavaScript toolkit demonstrates
  224. this; the call to jQuery's ajaxSetup will cause all AJAX requests to
  225. send back the CSRF token in the custom X-CSRFTOKEN header::
  226. $.ajaxSetup({
  227. beforeSend: function(xhr, settings) {
  228. function getCookie(name) {
  229. var cookieValue = null;
  230. if (document.cookie && document.cookie != '') {
  231. var cookies = document.cookie.split(';');
  232. for (var i = 0; i < cookies.length; i++) {
  233. var cookie = jQuery.trim(cookies[i]);
  234. // Does this cookie string begin with the name we want?
  235. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  236. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  237. break;
  238. }
  239. }
  240. }
  241. return cookieValue;
  242. }
  243. if (!(/^http:.*/.test(settings.url) || /^https:.*/.test(settings.url))) {
  244. // Only send the token to relative URLs i.e. locally.
  245. xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
  246. }
  247. }
  248. });
  249. Restricted filters in admin interface
  250. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. The Django administrative interface, django.contrib.admin, supports
  252. filtering of displayed lists of objects by fields on the corresponding
  253. models, including across database-level relationships. This is
  254. implemented by passing lookup arguments in the querystring portion of
  255. the URL, and options on the ModelAdmin class allow developers to
  256. specify particular fields or relationships which will generate
  257. automatic links for filtering.
  258. One historically-undocumented and -unofficially-supported feature has
  259. been the ability for a user with sufficient knowledge of a model's
  260. structure and the format of these lookup arguments to invent useful
  261. new filters on the fly by manipulating the querystring.
  262. However, it has been demonstrated that this can be abused to gain
  263. access to information outside of an admin user's permissions; for
  264. example, an attacker with access to the admin and sufficient knowledge
  265. of model structure and relations could construct query strings which --
  266. with repeated use of regular-expression lookups supported by the
  267. Django database API -- expose sensitive information such as users'
  268. password hashes.
  269. To remedy this, django.contrib.admin will now validate that
  270. querystring lookup arguments either specify only fields on the model
  271. being viewed, or cross relations which have been explicitly
  272. whitelisted by the application developer using the pre-existing
  273. mechanism mentioned above. This is backwards-incompatible for any
  274. users relying on the prior ability to insert arbitrary lookups.
  275. FileField no longer deletes files
  276. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  277. In earlier Django versions, when a model instance containing a
  278. :class:`~django.db.models.FileField` was deleted,
  279. :class:`~django.db.models.FileField` took it upon itself to also delete the
  280. file from the backend storage. This opened the door to several data-loss
  281. scenarios, including rolled-back transactions and fields on different models
  282. referencing the same file. In Django 1.3, :class:`~django.db.models.FileField`
  283. will never delete files from the backend storage. If you need cleanup of
  284. orphaned files, you'll need to handle it yourself (for instance, with a custom
  285. management command that can be run manually or scheduled to run periodically
  286. via e.g. cron).
  287. PasswordInput default rendering behavior
  288. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  289. The :class:`~django.forms.PasswordInput` form widget, intended for use
  290. with form fields which represent passwords, accepts a boolean keyword
  291. argument ``render_value`` indicating whether to send its data back to
  292. the browser when displaying a submitted form with errors. Prior to
  293. Django 1.3, this argument defaulted to ``True``, meaning that the
  294. submitted password would be sent back to the browser as part of the
  295. form. Developers who wished to add a bit of additional security by
  296. excluding that value from the redisplayed form could instantiate a
  297. :class:`~django.forms.PasswordInput` passing ``render_value=False`` .
  298. Due to the sensitive nature of passwords, however, Django 1.3 takes
  299. this step automatically; the default value of ``render_value`` is now
  300. ``False``, and developers who want the password value returned to the
  301. browser on a submission with errors (the previous behavior) must now
  302. explicitly indicate this. For example::
  303. class LoginForm(forms.Form):
  304. username = forms.CharField(max_length=100)
  305. password = forms.CharField(widget=forms.PasswordInput(render_value=True))
  306. Clearable default widget for FileField
  307. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  308. Django 1.3 now includes a ``ClearableFileInput`` form widget in addition to
  309. ``FileInput``. ``ClearableFileInput`` renders with a checkbox to clear the
  310. field's value (if the field has a value and is not required); ``FileInput``
  311. provided no means for clearing an existing file from a ``FileField``.
  312. ``ClearableFileInput`` is now the default widget for a ``FileField``, so
  313. existing forms including ``FileField`` without assigning a custom widget will
  314. need to account for the possible extra checkbox in the rendered form output.
  315. To return to the previous rendering (without the ability to clear the
  316. ``FileField``), use the ``FileInput`` widget in place of
  317. ``ClearableFileInput``. For instance, in a ``ModelForm`` for a hypothetical
  318. ``Document`` model with a ``FileField`` named ``document``::
  319. from django import forms
  320. from myapp.models import Document
  321. class DocumentForm(forms.ModelForm):
  322. class Meta:
  323. model = Document
  324. widgets = {'document': forms.FileInput}
  325. New index on database session table
  326. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  327. Prior to Django 1.3, the database table used by the database backend
  328. for the :doc:`sessions </topics/http/sessions>` app had no index on
  329. the ``expire_date`` column. As a result, date-based queries on the
  330. session table -- such as the query that is needed to purge old
  331. sessions -- would be very slow if there were lots of sessions.
  332. If you have an existing project that is using the database session
  333. backend, you don't have to do anything to accommodate this change.
  334. However, you may get a significant performance boost if you manually
  335. add the new index to the session table. The SQL that will add the
  336. index can be found by running the :djadmin:`sqlindexes` admin
  337. command::
  338. python manage.py sqlindexes sessions
  339. No more naughty words
  340. ~~~~~~~~~~~~~~~~~~~~~
  341. Django has historically provided (and enforced) a list of profanities.
  342. The :doc:`comments app </ref/contrib/comments/index>` has enforced this
  343. list of profanities, preventing people from submitting comments that
  344. contained one of those profanities.
  345. Unfortunately, the technique used to implement this profanities list
  346. was woefully naive, and prone to the `Scunthorpe problem`_. Fixing the
  347. built in filter to fix this problem would require significant effort,
  348. and since natural language processing isn't the normal domain of a web
  349. framework, we have "fixed" the problem by making the list of
  350. prohibited words an empty list.
  351. If you want to restore the old behavior, simply put a
  352. ``PROFANITIES_LIST`` setting in your settings file that includes the
  353. words that you want to prohibit (see the `commit that implemented this
  354. change`_ if you want to see the list of words that was historically
  355. prohibited). However, if avoiding profanities is important to you, you
  356. would be well advised to seek out a better, less naive approach to the
  357. problem.
  358. .. _Scunthorpe problem: http://en.wikipedia.org/wiki/Scunthorpe_problem
  359. .. _commit that implemented this change: http://code.djangoproject.com/changeset/13996
  360. Localflavor changes
  361. ~~~~~~~~~~~~~~~~~~~
  362. Django 1.3 introduces the following backwards-incompatible changes to
  363. local flavors:
  364. * Indonesia (id) -- The province "Nanggroe Aceh Darussalam (NAD)"
  365. has been removed from the province list in favor of the new
  366. official designation "Aceh (ACE)".
  367. FormSet updates
  368. ~~~~~~~~~~~~~~~
  369. In Django 1.3 ``FormSet`` creation behavior is modified slightly. Historically
  370. the class didn't make a distinction between not being passed data and being
  371. passed empty dictionary. This was inconsistent with behavior in other parts of
  372. the framework. Starting with 1.3 if you pass in empty dictionary the
  373. ``FormSet`` will raise a ``ValidationError``.
  374. For example with a ``FormSet``::
  375. >>> class ArticleForm(Form):
  376. ... title = CharField()
  377. ... pub_date = DateField()
  378. >>> ArticleFormSet = formset_factory(ArticleForm)
  379. the following code will raise a ``ValidationError``::
  380. >>> ArticleFormSet({})
  381. Traceback (most recent call last):
  382. ...
  383. ValidationError: [u'ManagementForm data is missing or has been tampered with']
  384. if you need to instantiate an empty ``FormSet``, don't pass in the data or use
  385. ``None``::
  386. >>> formset = ArticleFormSet()
  387. >>> formset = ArticleFormSet(data=None)
  388. Callables in templates
  389. ~~~~~~~~~~~~~~~~~~~~~~
  390. Previously, a callable in a template would only be called automatically as part
  391. of the variable resolution process if it was retrieved via attribute
  392. lookup. This was an inconsistency that could result in confusing and unhelpful
  393. behaviour::
  394. >>> Template("{{ user.get_full_name }}").render(Context({'user': user}))
  395. u'Joe Bloggs'
  396. >>> Template("{{ full_name }}").render(Context({'full_name': user.get_full_name}))
  397. u'&lt;bound method User.get_full_name of &lt;...
  398. This has been resolved in Django 1.3 - the result in both cases will be ``u'Joe
  399. Bloggs'``. Although the previous behaviour was not useful for a template language
  400. designed for web designers, and was never deliberately supported, it is possible
  401. that some templates may be broken by this change.
  402. Use of custom SQL to load initial data in tests
  403. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404. Django provides a custom SQL hooks as a way to inject hand-crafted SQL
  405. into the database synchronization process. One of the possible uses
  406. for this custom SQL is to insert data into your database. If your
  407. custom SQL contains ``INSERT`` statements, those insertions will be
  408. performed every time your database is synchronized. This includes the
  409. synchronization of any test databases that are created when you run a
  410. test suite.
  411. However, in the process of testing the Django 1.3, it was discovered
  412. that this feature has never completely worked as advertised. When
  413. using database backends that don't support transactions, or when using
  414. a TransactionTestCase, data that has been inserted using custom SQL
  415. will not be visible during the testing process.
  416. Unfortunately, there was no way to rectify this problem without
  417. introducing a backwards incompatibility. Rather than leave
  418. SQL-inserted initial data in an uncertain state, Django now enforces
  419. the policy that data inserted by custom SQL will *not* be visible
  420. during testing.
  421. This change only affects the testing process. You can still use custom
  422. SQL to load data into your production database as part of the syncdb
  423. process. If you require data to exist during test conditions, you
  424. should either insert it using :ref:`test fixtures
  425. <topics-testing-fixtures>`, or using the ``setUp()`` method of your
  426. test case.
  427. Changed priority of translation loading
  428. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  429. Work has been done to homogeneize, simplify, rationalize and properly document
  430. the algorithm used by Django at runtime to build translations from the
  431. differents translations found on disk, namely:
  432. For translatable literals found in Python code and templates (``'django'``
  433. gettext domain):
  434. * Priorities of translations included with applications listed in the
  435. :setting:`INSTALLED_APPS` setting were changed. To provide a behavior
  436. consistent with other parts of Django that also use such setting (templates,
  437. etc.) now, when building the translation that will be made available, the
  438. apps listed first have higher precedence than the ones listed later.
  439. * Now it is possible to override the translations shipped with applications by
  440. using the :setting:`LOCALE_PATHS` setting whose translations have now higher
  441. precedence than the translations of ``INSTALLED_APPS`` applications.
  442. The relative priority among the values listed in this setting has also been
  443. modified so the paths listed first have higher precedence than the
  444. ones listed later.
  445. * The ``locale`` subdirectory of the directory containing the settings, that
  446. usually coincides with and is know as the *project directory* is being
  447. deprecated in this release as a source of translations. (the precedence of
  448. these translations is intermediate between applications and ``LOCALE_PATHS``
  449. translations). See the `corresponding deprecated features section`_
  450. of this document.
  451. For translatable literals found in Javascript code (``'djangojs'`` gettext
  452. domain):
  453. * Similarly to the ``'django'`` domain translations: Overriding of
  454. translations shipped with applications by using the :setting:`LOCALE_PATHS`
  455. setting is now possible for this domain too. These translations have higher
  456. precedence than the translations of Python packages passed to the
  457. :ref:`javascript_catalog view <javascript_catalog-view>`. Paths listed first
  458. have higher precedence than the ones listed later.
  459. * Translations under the ``locale`` sbdirectory of the *project directory* have
  460. never been taken in account for JavaScript translations and remain in the
  461. same situation considering the deprecation of such location.
  462. .. _corresponding deprecated features section: loading_of_translations_from_the_project_directory_
  463. Transaction management
  464. ~~~~~~~~~~~~~~~~~~~~~~
  465. When using managed transactions -- that is, anything but the default
  466. autocommit mode -- it is important when a transaction is marked as
  467. "dirty". Dirty transactions are committed by the
  468. :func:`~django.db.transaction.commit_on_success` decorator or the
  469. :class:`~django.middleware.transaction.TransactionMiddleware`, and
  470. :func:`~django.db.transaction.commit_manually` forces them to be
  471. closed explicitly; clean transactions "get a pass", which means they
  472. are usually rolled back at the end of a request when the connection is
  473. closed.
  474. Until Django 1.3, transactions were only marked dirty when Django was
  475. aware of a modifying operation performed in them; that is, either some
  476. model was saved, some bulk update or delete was performed, or the user
  477. explicitly called ``transaction.set_dirty()``. In Django 1.3, a
  478. transaction is marked dirty when *any* database operation is
  479. performed.
  480. As a result of this change, you no longer need to set a transaction
  481. dirty explicitly when you execute raw SQL or use a data-modifying
  482. ``SELECT``. However, you *do* need to explicitly close any read-only
  483. transactions that are being managed using
  484. :func:`~django.db.transaction.commit_manually`. For example::
  485. @transaction.commit_manually
  486. def my_view(request, name):
  487. obj = get_object_or_404(MyObject, name__iexact=name)
  488. return render_to_response('template', {'object':obj})
  489. Prior to Django 1.3, this would work without error. However, under
  490. Django 1.3, this will raise a :class:`TransactionManagementError` because
  491. the read operation that retrieves the ``MyObject`` instance leaves the
  492. transaction in a dirty state.
  493. .. _deprecated-features-1.3:
  494. Features deprecated in 1.3
  495. ==========================
  496. Django 1.3 deprecates some features from earlier releases.
  497. These features are still supported, but will be gradually phased out
  498. over the next few release cycles.
  499. Code taking advantage of any of the features below will raise a
  500. ``PendingDeprecationWarning`` in Django 1.3. This warning will be
  501. silent by default, but may be turned on using Python's `warnings
  502. module`_, or by running Python with a ``-Wd`` or `-Wall` flag.
  503. .. _warnings module: http://docs.python.org/library/warnings.html
  504. In Django 1.4, these warnings will become a ``DeprecationWarning``,
  505. which is *not* silent. In Django 1.5 support for these features will
  506. be removed entirely.
  507. .. seealso::
  508. For more details, see the documentation :doc:`Django's release process
  509. </internals/release-process>` and our :doc:`deprecation timeline
  510. </internals/deprecation>`.
  511. ``mod_python`` support
  512. ~~~~~~~~~~~~~~~~~~~~~~
  513. The ``mod_python`` library has not had a release since 2007 or a commit since
  514. 2008. The Apache Foundation board voted to remove ``mod_python`` from the set
  515. of active projects in its version control repositories, and its lead developer
  516. has shifted all of his efforts toward the lighter, slimmer, more stable, and
  517. more flexible ``mod_wsgi`` backend.
  518. If you are currently using the ``mod_python`` request handler, you
  519. should redeploy your Django projects using another request handler.
  520. :doc:`mod_wsgi </howto/deployment/modwsgi>` is the request handler
  521. recommended by the Django project, but :doc:`FastCGI
  522. </howto/deployment/fastcgi>` is also supported. Support for
  523. ``mod_python`` deployment will be removed in Django 1.5.
  524. Function-based generic views
  525. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  526. As a result of the introduction of class-based generic views, the
  527. function-based generic views provided by Django have been deprecated.
  528. The following modules and the views they contain have been deprecated:
  529. * :mod:`django.views.generic.create_update`
  530. * :mod:`django.views.generic.date_based`
  531. * :mod:`django.views.generic.list_detail`
  532. * :mod:`django.views.generic.simple`
  533. Test client response ``template`` attribute
  534. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  535. Django's :ref:`test client <test-client>` returns
  536. :class:`~django.test.client.Response` objects annotated with extra testing
  537. information. In Django versions prior to 1.3, this included a
  538. :attr:`~django.test.client.Response.template` attribute containing information
  539. about templates rendered in generating the response: either None, a single
  540. :class:`~django.template.Template` object, or a list of
  541. :class:`~django.template.Template` objects. This inconsistency in return values
  542. (sometimes a list, sometimes not) made the attribute difficult to work with.
  543. In Django 1.3 the :attr:`~django.test.client.Response.template` attribute is
  544. deprecated in favor of a new :attr:`~django.test.client.Response.templates`
  545. attribute, which is always a list, even if it has only a single element or no
  546. elements.
  547. ``DjangoTestRunner``
  548. ~~~~~~~~~~~~~~~~~~~~
  549. As a result of the introduction of support for unittest2, the features
  550. of :class:`django.test.simple.DjangoTestRunner` (including fail-fast
  551. and Ctrl-C test termination) have been made redundant. In view of this
  552. redundancy, :class:`~django.test.simple.DjangoTestRunner` has been
  553. turned into an empty placeholder class, and will be removed entirely
  554. in Django 1.5.
  555. Changes to :ttag:`url` and :ttag:`ssi`
  556. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  557. Most template tags will allow you to pass in either constants or
  558. variables as arguments -- for example::
  559. {% extends "base.html" %}
  560. allows you to specify a base template as a constant, but if you have a
  561. context variable ``templ`` that contains the value ``base.html``::
  562. {% extends templ %}
  563. is also legal.
  564. However, due to an accident of history, the :ttag:`url` and
  565. :ttag:`ssi` are different. These tags use the second, quoteless
  566. syntax, but interpret the argument as a constant. This means it isn't
  567. possible to use a context variable as the target of a :ttag:`url` and
  568. :ttag:`ssi` tag.
  569. Django 1.3 marks the start of the process to correct this historical
  570. accident. Django 1.3 adds a new template library -- ``future`` -- that
  571. provides alternate implementations of the :ttag:`url` and :ttag:`ssi`
  572. template tags. This ``future`` library implement behavior that makes
  573. the handling of the first argument consistent with the handling of all
  574. other variables. So, an existing template that contains::
  575. {% url sample %}
  576. should be replaced with::
  577. {% load url from future %}
  578. {% url 'sample' %}
  579. The tags implementing the old behavior have been deprecated, and in
  580. Django 1.5, the old behavior will be replaced with the new behavior.
  581. To ensure compatibility with future versions of Django, existing
  582. templates should be modified to use the new ``future`` libraries and
  583. syntax.
  584. Changes to the login methods of the admin
  585. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  586. In previous version the admin app defined login methods in multiple locations
  587. and ignored the almost identical implementation in the already used auth app.
  588. A side effect of this duplication was the missing adoption of the changes made
  589. in r12634_ to support a broader set of characters for usernames.
  590. This release refactores the admin's login mechanism to use a subclass of the
  591. :class:`~django.contrib.auth.forms.AuthenticationForm` instead of a manual
  592. form validation. The previously undocumented method
  593. ``'django.contrib.admin.sites.AdminSite.display_login_form'`` has been removed
  594. in favor of a new :attr:`~django.contrib.admin.AdminSite.login_form`
  595. attribute.
  596. .. _r12634: http://code.djangoproject.com/changeset/12634
  597. ``reset`` and ``sqlreset`` management commands
  598. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  599. Those commands have been deprecated. The ``flush`` and ``sqlflush`` commands
  600. can be used to delete everything. You can also use ALTER TABLE or DROP TABLE
  601. statements manually.
  602. GeoDjango
  603. ~~~~~~~~~
  604. * The function-based :setting:`TEST_RUNNER` previously used to execute
  605. the GeoDjango test suite, :func:`django.contrib.gis.tests.run_gis_tests`,
  606. was deprecated for the class-bassed runner,
  607. :class:`django.contrib.gis.tests.GeoDjangoTestSuiteRunner`.
  608. * Previously, calling :meth:`~django.contrib.gis.geos.GEOSGeometry.transform`
  609. would silently do nothing when GDAL wasn't available. Now,
  610. a :class:`~django.contrib.gis.geos.GEOSException` is properly raised
  611. to indicate possible faulty application code. A warning is now raised
  612. if :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` is called when
  613. the SRID of the geometry is less than 0 or ``None``.
  614. ``CZBirthNumberField.clean``
  615. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  616. Previously this field's ``clean()`` method accepted a second, gender, argument
  617. which allowed stronger validation checks to be made, however since this
  618. argument could never actually be passed from the Django form machinery it is
  619. now pending deprecation.
  620. ``CompatCookie``
  621. ~~~~~~~~~~~~~~~~
  622. Previously, ``django.http`` exposed an undocumented ``CompatCookie`` class,
  623. which was a bug-fix wrapper around the standard library ``SimpleCookie``. As the
  624. fixes are moving upstream, this is now deprecated - you should use ``from
  625. django.http import SimpleCookie`` instead.
  626. .. _loading_of_translations_from_the_project_directory:
  627. Loading of translations from the project directory
  628. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  629. This release of Django starts the deprecation process for inclusion of
  630. translations located under the *project path* in the translation building
  631. process performed at runtime. The :setting:`LOCALE_PATHS` setting can be used
  632. for the same task by including in it the filesystem path to the ``locale``
  633. directory containing project-level translations.
  634. Rationale for this decision:
  635. * The *project path* has always been a loosely defined concept (actually, the
  636. directory used for locating project-level translations is the directory
  637. containing the settings module) and there has been a shift in other parts
  638. of the framework to stop using it as a reference for location of assets at
  639. runtime.
  640. * Detection of the ``locale`` subdirectory tends to fail when the deployment
  641. scenario is more complex than the basic one. e.g. it fails when the settings
  642. module is a directory (ticket #10765).
  643. * Potential for strange development- and deployment-time problems like the
  644. fact that the ``project_dir/locale/`` subdir can generate spurious error
  645. messages when the project directory is included in the Python path (default
  646. behavior of ``manage.py runserver``) and then it clashes with the equally
  647. named standard library module, this is a typical warming message::
  648. /usr/lib/python2.6/gettext.py:49: ImportWarning: Not importing directory '/path/to/project/dir/locale': missing __init__.py.
  649. import locale, copy, os, re, struct, sys
  650. * This location wasn't included in the translation building process for
  651. JavaScript literals.