Peter Wright  committed bb013d5 Merge

Merged dready fork.

  • Participants
  • Parent commits 2d4cf44, 4a6e360
  • Branches default

Comments (0)

Files changed (2)

File registration/backends/default/

         rendered using two templates. See the documentation for
         ``RegistrationProfile.send_activation_email()`` for
         information about these templates and the contexts provided to
-        them.
+        them. An additional context dict may be specified using the
+        ``extra_context`` argument.
         After the ``User`` and ``RegistrationProfile`` are created and
         the activation email is sent, the signal
         class of this backend as the sender.
-        username, email, password = kwargs['username'], kwargs['email'], kwargs['password1']
+        username, email, password = kwargs.pop('username'), kwargs.pop('email'), kwargs.pop('password1')
+        kwargs.pop('password2', None) # don't want this for create_inactive_user either
         if Site._meta.installed:
             site = Site.objects.get_current()
             site = RequestSite(request)
         new_user = RegistrationProfile.objects.create_inactive_user(username, email,
-                                                                    password, site)
+                                                                    password, site, **kwargs)

File registration/

         return False
     def create_inactive_user(self, username, email, password,
-                             site, send_email=True):
+                             site, send_email=True, **kwargs):
         Create a new, inactive ``User``, generate a
         ``RegistrationProfile`` and email its activation key to the
         By default, an activation email will be sent to the new
         user. To disable this, pass ``send_email=False``.
+        ``kwargs`` are passed to ``RegistrationProfile.send_activation_email``.
         new_user = User.objects.create_user(username, email, password)
         new_user.is_active = False
         registration_profile = self.create_profile(new_user)
         if send_email:
-            registration_profile.send_activation_email(site)
+            registration_profile.send_activation_email(site, **kwargs)
         return new_user
     create_inactive_user = transaction.commit_on_success(create_inactive_user)
                (self.user.date_joined + expiration_date <=
     activation_key_expired.boolean = True
-    def send_activation_email(self, site):
+    def send_activation_email(self, site,
+                              extra_context=None,
+                              subject_template='registration/activation_email_subject.txt',
+                              body_template='registration/activation_email.txt'):
         Send an activation email to the user associated with this
+        ``extra_context`` - additional context variables to be made available when rendering the templates.
         The activation email will make use of two templates:
-        ``registration/activation_email_subject.txt``
+        ``subject_template`` (default: ``registration/activation_email_subject.txt``)
             This template will be used for the subject line of the
             email. Because it is used as the subject line of an email,
             this template's output **must** be only a single line of
             text; output longer than one line will be forcibly joined
             into only a single line.
-        ``registration/activation_email.txt``
+        ``body_template`` (default: ``registration/activation_email.txt``)
             This template will be used for the body of the email.
         These templates will each receive the following context
         ctx_dict = {'activation_key': self.activation_key,
                     'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
                     'site': site}
-        subject = render_to_string('registration/activation_email_subject.txt',
-                                   ctx_dict)
+        ctx_dict.update(extra_context or {})
+        subject = render_to_string(subject_template, ctx_dict)
         # Email subject *must not* contain newlines
         subject = ''.join(subject.splitlines())
-        message = render_to_string('registration/activation_email.txt',
-                                   ctx_dict)
+        message = render_to_string(body_template, ctx_dict)
         self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)