/docs/upgrade.rst

https://github.com/yishenggudou/django-registration · ReStructuredText · 120 lines · 95 code · 25 blank · 0 comment · 0 complexity · 171153f70c47ab8d486ac3a80cc2fda8 MD5 · raw file

  1. .. _upgrade:
  2. Upgrade guide
  3. =============
  4. The |version| release of django-registration represents a complete
  5. rewrite of the previous codebase, and introduces several new features
  6. which greatly enhance the customizability and extensibility of
  7. django-registration. Whenever possible, changes were made in ways
  8. which preserve backwards compatibility with previous releases, but
  9. some changes to existing installations will still be required in order
  10. to upgrade to |version|. This document provides a summary of those
  11. changes, and of the new features available in the |version| release.
  12. Django version requirement
  13. --------------------------
  14. As of |version|, django-registration requires Django 1.1 or newer;
  15. older Django releases will not work, as django-registration |version|
  16. takes advantage of several Django features which are only present as
  17. of 1.1.
  18. Backwards-incompatible changes
  19. ------------------------------
  20. If you're upgrading from an older release of django-registration, and
  21. if you were using the default setup (i.e., the included default
  22. URLconf and no custom URL patterns or custom arguments to views), most
  23. things will continue to work as normal (although you will need to
  24. create one new template; see the section on views below). However, the
  25. old default URLconf has been deprecated and will be removed in version
  26. 1.0 of django-registration, so it is recommended that you begin
  27. migrating now. To do so, change any use of ``registration.urls`` to
  28. ``registration.backends.default.urls``. For example, if you had the
  29. following in your root URLconf::
  30. (r'^accounts/', include('registration.urls')),
  31. you should change it to::
  32. (r'^accounts/', include('registration.backends.default.urls')),
  33. The older include will continue to work until django-registration 1.0;
  34. in |version| it raises a ``PendingDeprecationWarning`` (which is
  35. ignored by default in Python), in 0.9 it will raise
  36. ``DeprecationWarning`` (which will begin printing warning messages on
  37. import) and in 1.0 it will be removed entirely.
  38. Changes to registration views
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. :ref:`The views used to handle user registration <views>` have changed
  41. significantly as of django-registration |version|. Both views now
  42. require the keyword argument ``backend``, which specifies the
  43. :ref:`registration backend <backend-api>` to use, and so any URL
  44. pattern for these views must supply that argument. The URLconf
  45. provided with :ref:`the default backend <default-backend>` properly
  46. passes this argument.
  47. The ``profile_callback`` argument of the
  48. :func:`~registration.views.register` view has been removed; the
  49. functionality it provided can now be implemented easily via a custom
  50. backend, or by connecting listeners to :ref:`the signals sent during
  51. the registration process <signals>`.
  52. The :func:`~registration.views.activate` view now issues a redirect
  53. upon successful activation; in the default backend this is to the URL
  54. pattern named ``registration_activation_complete``; in the default
  55. setup, this will redirect to a view which renders the template
  56. ``registration/activation_complete.html``, and so this template should
  57. be present when using the default backend and default
  58. configuration. Other backends can specify the location to redirect to
  59. through their ``post_activation_redirect()`` method, and this can be
  60. overridden on a case-by-case basis by passing the (new) keyword
  61. argument ``success_url`` to the ``activate()`` view. On unsuccessful
  62. activation, the ``activate()`` view still displays the same template,
  63. but its context has changed: the context will simply consist of any
  64. keyword arguments captured in the URL and passed to the view.
  65. Changes to registration forms
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. Previously, the form used to collect data during registration was
  68. expected to implement a ``save()`` method which would create the new
  69. user account. This is no longer the case; creating the account is
  70. handled by the backend, and so any custom logic should be moved into a
  71. custom backend, or by connecting listeners to :ref:`the signals sent
  72. during the registration process <signals>`.
  73. Changes to the :class:`~registration.models.RegistrationProfile` model
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. The
  76. :meth:`~registration.models.RegistrationManager.create_inactive_user`
  77. method of :class:`~registration.models.RegistrationManager` now has an
  78. additional required argument: ``site``. This allows
  79. django-registration to easily be used regardless of whether
  80. ``django.contrib.sites`` is installed, since a ``RequestSite`` object
  81. can be passed in place of a regular ``Site`` object.
  82. The :data:`~registration.signals.user_registered` signal is no longer
  83. sent by ``create_inactive_user()``, and the
  84. :data:`~registration.signals.user_activated` signal is no longer sent
  85. by :meth:`~registration.models.RegistrationManager.activate_user`;
  86. these signals are now sent by the backend after these methods have
  87. been called. Note that :ref:`these signals <signals>` were added after
  88. the django-registration 0.7 release but before the refactoring which
  89. introduced :ref:`the backend API <backend-api>`, so only installations
  90. which were tracking the in-development codebase will have made use of
  91. them.
  92. The sending of activation emails has been factored out of
  93. ``create_inactive_user()``, and now exists as the method
  94. :meth:`~registration.models.RegistrationProfile.send_activation_email`
  95. on instances of ``RegistrationProfile``.