1.2-alpha-1.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. ================================
  2. Django 1.2 alpha 1 release notes
  3. ================================
  4. January 5, 2010
  5. Welcome to Django 1.2 alpha 1!
  6. This is the first in a series of preview/development releases leading up to the
  7. eventual release of Django 1.2, currently scheduled to take place in March 2010.
  8. This release is primarily targeted at developers who are interested in trying
  9. out new features and testing the Django codebase to help identify and resolve
  10. bugs prior to the final 1.2 release.
  11. As such, this release is *not* intended for production use, and any such use is
  12. discouraged.
  13. Backwards-incompatible changes in 1.2
  14. =====================================
  15. CSRF Protection
  16. ---------------
  17. There have been large changes to the way that CSRF protection works, detailed in
  18. :doc:`the CSRF documentation </ref/contrib/csrf>`. The following are the major
  19. changes that developers must be aware of:
  20. * ``CsrfResponseMiddleware`` and ``CsrfMiddleware`` have been deprecated, and
  21. **will be removed completely in Django 1.4**, in favor of a template tag that
  22. should be inserted into forms.
  23. * All contrib apps use a ``csrf_protect`` decorator to protect the view. This
  24. requires the use of the ``csrf_token`` template tag in the template, so if you
  25. have used custom templates for contrib views, you MUST READ THE UPGRADE
  26. INSTRUCTIONS to fix those templates.
  27. .. admonition:: Documentation removed
  28. The upgrade notes have been removed in current Django docs. Please refer
  29. to the docs for Django 1.3 or older to find these instructions.
  30. * ``CsrfViewMiddleware`` is included in :setting:`MIDDLEWARE_CLASSES` by
  31. default. This turns on CSRF protection by default, so that views that accept
  32. POST requests need to be written to work with the middleware. Instructions
  33. on how to do this are found in the CSRF docs.
  34. * CSRF-related code has moved from ``contrib`` to ``core`` (with
  35. backwards compatible imports in the old locations, which are
  36. deprecated).
  37. :ttag:`if` tag changes
  38. ----------------------
  39. Due to new features in the :ttag:`if` template tag, it no longer accepts 'and',
  40. 'or' and 'not' as valid **variable** names. Previously that worked in some
  41. cases even though these strings were normally treated as keywords. Now, the
  42. keyword status is always enforced, and template code like ``{% if not %}`` or
  43. ``{% if and %}`` will throw a TemplateSyntaxError.
  44. ``LazyObject``
  45. --------------
  46. ``LazyObject`` is an undocumented utility class used for lazily wrapping other
  47. objects of unknown type. In Django 1.1 and earlier, it handled introspection in
  48. a non-standard way, depending on wrapped objects implementing a public method
  49. ``get_all_members()``. Since this could easily lead to name clashes, it has been
  50. changed to use the standard method, involving ``__members__`` and ``__dir__()``.
  51. If you used ``LazyObject`` in your own code, and implemented the
  52. ``get_all_members()`` method for wrapped objects, you need to make the following
  53. changes:
  54. * If your class does not have special requirements for introspection (i.e. you
  55. have not implemented ``__getattr__()`` or other methods that allow for
  56. attributes not discoverable by normal mechanisms), you can simply remove the
  57. ``get_all_members()`` method. The default implementation on ``LazyObject``
  58. will do the right thing.
  59. * If you have more complex requirements for introspection, first rename the
  60. ``get_all_members()`` method to ``__dir__()``. This is the standard method,
  61. from Python 2.6 onwards, for supporting introspection. If you are require
  62. support for Python < 2.6, add the following code to the class::
  63. __members__ = property(lambda self: self.__dir__())
  64. ``__dict__`` on Model instances
  65. -------------------------------
  66. Historically, the ``__dict__`` attribute of a model instance has only contained
  67. attributes corresponding to the fields on a model.
  68. In order to support multiple database configurations, Django 1.2 has
  69. added a ``_state`` attribute to object instances. This attribute will
  70. appear in ``__dict__`` for a model instance. If your code relies on
  71. iterating over __dict__ to obtain a list of fields, you must now
  72. filter the ``_state`` attribute of out ``__dict__``.
  73. ``get_db_prep_*()`` methods on Field
  74. ------------------------------------
  75. Prior to v1.2, a custom field had the option of defining several
  76. functions to support conversion of Python values into
  77. database-compatible values. A custom field might look something like::
  78. class CustomModelField(models.Field):
  79. # ...
  80. def get_db_prep_save(self, value):
  81. # ...
  82. def get_db_prep_value(self, value):
  83. # ...
  84. def get_db_prep_lookup(self, lookup_type, value):
  85. # ...
  86. In 1.2, these three methods have undergone a change in prototype, and
  87. two extra methods have been introduced::
  88. class CustomModelField(models.Field):
  89. # ...
  90. def get_prep_value(self, value):
  91. # ...
  92. def get_prep_lookup(self, lookup_type, value):
  93. # ...
  94. def get_db_prep_save(self, value, connection):
  95. # ...
  96. def get_db_prep_value(self, value, connection, prepared=False):
  97. # ...
  98. def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
  99. # ...
  100. These changes are required to support multiple databases:
  101. ``get_db_prep_*`` can no longer make any assumptions regarding the
  102. database for which it is preparing. The ``connection`` argument now
  103. provides the preparation methods with the specific connection for
  104. which the value is being prepared.
  105. The two new methods exist to differentiate general data preparation
  106. requirements, and requirements that are database-specific. The
  107. ``prepared`` argument is used to indicate to the database preparation
  108. methods whether generic value preparation has been performed. If
  109. an unprepared (i.e., ``prepared=False``) value is provided to the
  110. ``get_db_prep_*()`` calls, they should invoke the corresponding
  111. ``get_prep_*()`` calls to perform generic data preparation.
  112. Conversion functions has been provided which will transparently
  113. convert functions adhering to the old prototype into functions
  114. compatible with the new prototype. However, this conversion function
  115. will be removed in Django 1.4, so you should upgrade your Field
  116. definitions to use the new prototype.
  117. If your ``get_db_prep_*()`` methods made no use of the database
  118. connection, you should be able to upgrade by renaming
  119. ``get_db_prep_value()`` to ``get_prep_value()`` and
  120. ``get_db_prep_lookup()`` to ``get_prep_lookup()`. If you require
  121. database specific conversions, then you will need to provide an
  122. implementation ``get_db_prep_*`` that uses the ``connection``
  123. argument to resolve database-specific values.
  124. Stateful template tags
  125. ----------------------
  126. Template tags that store rendering state on the node itself may experience
  127. problems if they are used with the new :ref:`cached
  128. template loader<template-loaders>`.
  129. All of the built-in Django template tags are safe to use with the cached
  130. loader, but if you're using custom template tags that come from third
  131. party packages, or that you wrote yourself, you should ensure that the
  132. ``Node`` implementation for each tag is thread-safe. For more
  133. information, see
  134. :ref:`template tag thread safety considerations<template_tag_thread_safety>`.
  135. Test runner exit status code
  136. ----------------------------
  137. The exit status code of the test runners (``tests/runtests.py`` and ``python
  138. manage.py test``) no longer represents the number of failed tests, since a
  139. failure of 256 or more tests resulted in a wrong exit status code. The exit
  140. status code for the test runner is now 0 for success (no failing tests) and 1
  141. for any number of test failures. If needed, the number of test failures can be
  142. found at the end of the test runner's output.
  143. Features deprecated in 1.2
  144. ==========================
  145. CSRF response rewriting middleware
  146. ----------------------------------
  147. ``CsrfResponseMiddleware``, the middleware that automatically inserted CSRF
  148. tokens into POST forms in outgoing pages, has been deprecated in favor of a
  149. template tag method (see above), and will be removed completely in Django
  150. 1.4. ``CsrfMiddleware``, which includes the functionality of
  151. ``CsrfResponseMiddleware`` and ``CsrfViewMiddleware`` has likewise been
  152. deprecated.
  153. Also, the CSRF module has moved from contrib to core, and the old
  154. imports are deprecated, as described in the upgrading notes.
  155. .. admonition:: Documentation removed
  156. The upgrade notes have been removed in current Django docs. Please refer
  157. to the docs for Django 1.3 or older to find these instructions.
  158. ``SMTPConnection``
  159. ------------------
  160. The ``SMTPConnection`` class has been deprecated in favor of a generic
  161. Email backend API. Old code that explicitly instantiated an instance
  162. of an SMTPConnection::
  163. from django.core.mail import SMTPConnection
  164. connection = SMTPConnection()
  165. messages = get_notification_email()
  166. connection.send_messages(messages)
  167. should now call :meth:`~django.core.mail.get_connection()` to
  168. instantiate a generic email connection::
  169. from django.core.mail import get_connection
  170. connection = get_connection()
  171. messages = get_notification_email()
  172. connection.send_messages(messages)
  173. Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
  174. may not return an SMTP connection. If you explicitly require an SMTP
  175. connection with which to send email, you can explicitly request an
  176. SMTP connection::
  177. from django.core.mail import get_connection
  178. connection = get_connection('django.core.mail.backends.smtp.EmailBackend')
  179. messages = get_notification_email()
  180. connection.send_messages(messages)
  181. If your call to construct an instance of ``SMTPConnection`` required
  182. additional arguments, those arguments can be passed to the
  183. :meth:`~django.core.mail.get_connection()` call::
  184. connection = get_connection('django.core.mail.backends.smtp.EmailBackend', hostname='localhost', port=1234)
  185. Specifying databases
  186. --------------------
  187. Prior to Django 1.1, Django used a number of settings to control access to a
  188. single database. Django 1.2 introduces support for multiple databases, and as
  189. a result, the way you define database settings has changed.
  190. **Any existing Django settings file will continue to work as expected
  191. until Django 1.4.** Old-style database settings will be automatically
  192. translated to the new-style format.
  193. In the old-style (pre 1.2) format, there were a number of
  194. ``DATABASE_`` settings at the top level of your settings file. For
  195. example::
  196. DATABASE_NAME = 'test_db'
  197. DATABASE_ENGINE = 'postgresql_psycopg2'
  198. DATABASE_USER = 'myusername'
  199. DATABASE_PASSWORD = 's3krit'
  200. These settings are now contained inside a dictionary named
  201. :setting:`DATABASES`. Each item in the dictionary corresponds to a
  202. single database connection, with the name ``'default'`` describing the
  203. default database connection. The setting names have also been
  204. shortened to reflect the fact that they are stored in a dictionary.
  205. The sample settings given previously would now be stored using::
  206. DATABASES = {
  207. 'default': {
  208. 'NAME': 'test_db',
  209. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  210. 'USER': 'myusername',
  211. 'PASSWORD': 's3krit',
  212. }
  213. }
  214. This affects the following settings:
  215. ========================================= ==========================
  216. Old setting New Setting
  217. ========================================= ==========================
  218. :setting:`DATABASE_ENGINE` :setting:`ENGINE`
  219. :setting:`DATABASE_HOST` :setting:`HOST`
  220. :setting:`DATABASE_NAME` :setting:`NAME`
  221. :setting:`DATABASE_OPTIONS` :setting:`OPTIONS`
  222. :setting:`DATABASE_PASSWORD` :setting:`PASSWORD`
  223. :setting:`DATABASE_PORT` :setting:`PORT`
  224. :setting:`DATABASE_USER` :setting:`USER`
  225. :setting:`TEST_DATABASE_CHARSET` :setting:`TEST_CHARSET`
  226. :setting:`TEST_DATABASE_COLLATION` :setting:`TEST_COLLATION`
  227. :setting:`TEST_DATABASE_NAME` :setting:`TEST_NAME`
  228. ========================================= ==========================
  229. These changes are also required if you have manually created a database
  230. connection using ``DatabaseWrapper()`` from your database backend of choice.
  231. In addition to the change in structure, Django 1.2 removes the special
  232. handling for the built-in database backends. All database backends
  233. must now be specified by a fully qualified module name (i.e.,
  234. ``django.db.backends.postgresql_psycopg2``, rather than just
  235. ``postgresql_psycopg2``).
  236. User Messages API
  237. -----------------
  238. The API for storing messages in the user ``Message`` model (via
  239. ``user.message_set.create``) is now deprecated and will be removed in Django
  240. 1.4 according to the standard :doc:`release process </internals/release-process>`.
  241. To upgrade your code, you need to replace any instances of::
  242. user.message_set.create('a message')
  243. with the following::
  244. from django.contrib import messages
  245. messages.add_message(request, messages.INFO, 'a message')
  246. Additionally, if you make use of the method, you need to replace the
  247. following::
  248. for message in user.get_and_delete_messages():
  249. ...
  250. with::
  251. from django.contrib import messages
  252. for message in messages.get_messages(request):
  253. ...
  254. For more information, see the full
  255. :doc:`messages documentation </ref/contrib/messages>`. You should begin to
  256. update your code to use the new API immediately.
  257. Date format helper functions
  258. ----------------------------
  259. ``django.utils.translation.get_date_formats()`` and
  260. ``django.utils.translation.get_partial_date_formats()`` have been deprecated
  261. in favor of the appropriate calls to ``django.utils.formats.get_format()``
  262. which is locale aware when :setting:`USE_L10N` is set to ``True``, and falls
  263. back to default settings if set to ``False``.
  264. To get the different date formats, instead of writing::
  265. from django.utils.translation import get_date_formats
  266. date_format, datetime_format, time_format = get_date_formats()
  267. use::
  268. from django.utils import formats
  269. date_format = formats.get_format('DATE_FORMAT')
  270. datetime_format = formats.get_format('DATETIME_FORMAT')
  271. time_format = formats.get_format('TIME_FORMAT')
  272. or, when directly formatting a date value::
  273. from django.utils import formats
  274. value_formatted = formats.date_format(value, 'DATETIME_FORMAT')
  275. The same applies to the globals found in ``django.forms.fields``:
  276. * ``DEFAULT_DATE_INPUT_FORMATS``
  277. * ``DEFAULT_TIME_INPUT_FORMATS``
  278. * ``DEFAULT_DATETIME_INPUT_FORMATS``
  279. Use ``django.utils.formats.get_format()`` to get the appropriate formats.
  280. What's new in Django 1.2 alpha 1
  281. ================================
  282. The following new features are present as of this alpha release; this
  283. release also marks the end of major feature development for the 1.2
  284. release cycle. Some minor features will continue development until the
  285. 1.2 beta release, however.
  286. CSRF support
  287. ------------
  288. Django now has much improved protection against :doc:`Cross-Site
  289. Request Forgery (CSRF) attacks</ref/contrib/csrf>`. This type of attack
  290. occurs when a malicious Web site contains a link, a form button or
  291. some javascript that is intended to perform some action on your Web
  292. site, using the credentials of a logged-in user who visits the
  293. malicious site in their browser. A related type of attack, 'login
  294. CSRF', where an attacking site tricks a user's browser into logging
  295. into a site with someone else's credentials, is also covered.
  296. Email Backends
  297. --------------
  298. You can now :ref:`configure the way that Django sends email
  299. <topic-email-backends>`. Instead of using SMTP to send all email, you
  300. can now choose a configurable email backend to send messages. If your
  301. hosting provider uses a sandbox or some other non-SMTP technique for
  302. sending mail, you can now construct an email backend that will allow
  303. Django's standard :doc:`mail sending methods</topics/email>` to use
  304. those facilities.
  305. This also makes it easier to debug mail sending - Django ships with
  306. backend implementations that allow you to send email to a
  307. :ref:`file<topic-email-file-backend>`, to the
  308. :ref:`console<topic-email-console-backend>`, or to
  309. :ref:`memory<topic-email-memory-backend>` - you can even configure all
  310. email to be :ref:`thrown away<topic-email-dummy-backend>`.
  311. Messages Framework
  312. ------------------
  313. Django now includes a robust and configurable :doc:`messages framework
  314. </ref/contrib/messages>` with built-in support for cookie- and session-based
  315. messaging, for both anonymous and authenticated clients. The messages framework
  316. replaces the deprecated user message API and allows you to temporarily store
  317. messages in one request and retrieve them for display in a subsequent request
  318. (usually the next one).
  319. Support for multiple databases
  320. ------------------------------
  321. Django 1.2 adds the ability to use :doc:`more than one database
  322. </topics/db/multi-db>` in your Django project. Queries can be
  323. issued at a specific database with the `using()` method on
  324. querysets; individual objects can be saved to a specific database
  325. by providing a ``using`` argument when you save the instance.
  326. 'Smart' if tag
  327. --------------
  328. The :ttag:`if` tag has been upgraded to be much more powerful. First, support
  329. for comparison operators has been added. No longer will you have to type:
  330. .. code-block:: html+django
  331. {% ifnotequal a b %}
  332. ...
  333. {% endifnotequal %}
  334. ...as you can now do:
  335. .. code-block:: html+django
  336. {% if a != b %}
  337. ...
  338. {% endif %}
  339. The operators supported are ``==``, ``!=``, ``<``, ``>``, ``<=``, ``>=`` and
  340. ``in``, all of which work like the Python operators, in addition to ``and``,
  341. ``or`` and ``not`` which were already supported.
  342. Also, filters may now be used in the ``if`` expression. For example:
  343. .. code-block:: html+django
  344. <div
  345. {% if user.email|lower == message.recipient|lower %}
  346. class="highlight"
  347. {% endif %}
  348. >{{ message }}</div>
  349. Template caching
  350. ----------------
  351. In previous versions of Django, every time you rendered a template it
  352. would be reloaded from disk. In Django 1.2, you can use a :ref:`cached
  353. template loader <template-loaders>` to load templates once, then use
  354. the cached result for every subsequent render. This can lead to a
  355. significant performance improvement if your templates are broken into
  356. lots of smaller subtemplates (using the ``{% extends %}`` or ``{%
  357. include %}`` tags).
  358. As a side effect, it is now much easier to support non-Django template
  359. languages. For more details, see the :ref:`notes on supporting
  360. non-Django template languages<topic-template-alternate-language>`.
  361. Natural keys in fixtures
  362. ------------------------
  363. Fixtures can refer to remote objects using
  364. :ref:`topics-serialization-natural-keys`. This lookup scheme is an
  365. alternative to the normal primary-key based object references in a
  366. fixture, improving readability, and resolving problems referring to
  367. objects whose primary key value may not be predictable or known.
  368. ``BigIntegerField``
  369. -------------------
  370. Models can now use a 64 bit :class:`~django.db.models.BigIntegerField` type.
  371. Fast Failure for Tests
  372. ----------------------
  373. The :djadmin:`test` subcommand of ``django-admin.py``, and the ``runtests.py``
  374. script used to run Django's own test suite, support a new ``--failfast`` option.
  375. When specified, this option causes the test runner to exit after encountering
  376. a failure instead of continuing with the test run. In addition, the handling
  377. of ``Ctrl-C`` during a test run has been improved to trigger a graceful exit
  378. from the test run that reports details of the tests run before the interruption.
  379. Improved localization
  380. ---------------------
  381. Django's :doc:`internationalization framework </topics/i18n/index>` has been
  382. expanded by locale aware formatting and form processing. That means, if
  383. enabled, dates and numbers on templates will be displayed using the format
  384. specified for the current locale. Django will also use localized formats
  385. when parsing data in forms.
  386. See :ref:`Format localization <format-localization>` for more details.
  387. Added ``readonly_fields`` to ``ModelAdmin``
  388. -------------------------------------------
  389. :attr:`django.contrib.admin.ModelAdmin.readonly_fields` has been added to
  390. enable non-editable fields in add/change pages for models and inlines. Field
  391. and calculated values can be displayed along side editable fields.
  392. Customizable syntax highlighting
  393. --------------------------------
  394. You can now use the ``DJANGO_COLORS`` environment variable to modify
  395. or disable the colors used by ``django-admin.py`` to provide
  396. :ref:`syntax highlighting <syntax-coloring>`.
  397. The Django 1.2 roadmap
  398. ======================
  399. Before the final Django 1.2 release, several other preview/development
  400. releases will be made available. The current schedule consists of at
  401. least the following:
  402. * Week of **January 26, 2010**: First Django 1.2 beta release. Final
  403. feature freeze for Django 1.2.
  404. * Week of **March 2, 2010**: First Django 1.2 release
  405. candidate. String freeze for translations.
  406. * Week of **March 9, 2010**: Django 1.2 final release.
  407. If necessary, additional alpha, beta or release-candidate packages
  408. will be issued prior to the final 1.2 release. Django 1.2 will be
  409. released approximately one week after the final release candidate.
  410. What you can do to help
  411. =======================
  412. In order to provide a high-quality 1.2 release, we need your help. Although this
  413. alpha release is, again, *not* intended for production use, you can help the
  414. Django team by trying out the alpha codebase in a safe test environment and
  415. reporting any bugs or issues you encounter. The Django ticket tracker is the
  416. central place to search for open issues:
  417. * http://code.djangoproject.com/timeline
  418. Please open new tickets if no existing ticket corresponds to a problem you're
  419. running into.
  420. Additionally, discussion of Django development, including progress toward the
  421. 1.2 release, takes place daily on the django-developers mailing list:
  422. * http://groups.google.com/group/django-developers
  423. ... and in the ``#django-dev`` IRC channel on ``irc.freenode.net``. If you're
  424. interested in helping out with Django's development, feel free to join the
  425. discussions there.
  426. Django's online documentation also includes pointers on how to contribute to
  427. Django:
  428. * :doc:`How to contribute to Django </internals/contributing/index>`
  429. Contributions on any level -- developing code, writing documentation or simply
  430. triaging tickets and helping to test proposed bugfixes -- are always welcome and
  431. appreciated.
  432. Development sprints for Django 1.2 will also be taking place at PyCon
  433. US 2010, on the dedicated sprint days (February 22 through 25), and
  434. anyone who wants to help out is welcome to join in, either in person
  435. at PyCon or virtually in the IRC channel or on the mailing list.