1.3.txt 36 KB

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