Commits

Roberto Rosario committed 26ced99

Allow overriding the names of the activation email and activation email subject templates

Comments (0)

Files changed (1)

registration/models.py

         return False
     
     def create_inactive_user(self, username, email, password,
-                             site, send_email=True):
+                             site, send_email=True,
+			     activation_email_subject_template=None,
+                             activation_email_template=None):
         """
         Create a new, inactive ``User``, generate a
         ``RegistrationProfile`` and email its activation key to the
         new_user.is_active = False
         new_user.save()
 
-        registration_profile = self.create_profile(new_user)
+        registration_profile = self.create_profile(new_user,
+                               activation_email_subject_template,
+                               activation_email_template)
 
-        if send_email:
+       if send_email:
             registration_profile.send_activation_email(site)
 
         return new_user
     create_inactive_user = transaction.commit_on_success(create_inactive_user)
 
-    def create_profile(self, user):
+    def create_profile(self, user, activation_email_subject_template=None,
+                       activation_email_template=None):
         """
         Create a ``RegistrationProfile`` for a given
         ``User``, and return the ``RegistrationProfile``.
         if isinstance(username, unicode):
             username = username.encode('utf-8')
         activation_key = hashlib.sha1(salt+username).hexdigest()
-        return self.create(user=user,
-                           activation_key=activation_key)
+        profile = self.create(user=user,
+                  activation_key=activation_key)
+
+        if activation_email_subject_template:
+            profile.activation_email_subject_template = activation_email_subject_template
+
+        if activation_email_template:
+            profile.activation_email_template = activation_email_template
+
+        return profile
         
     def delete_expired_users(self):
         """
     
     """
     ACTIVATED = u"ALREADY_ACTIVATED"
-    
+    activation_email_subject_template = 'registration/activation_email_subject.txt'
+    activation_email_template = 'registration/activation_email.txt'
+
     user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
     activation_key = models.CharField(_('activation key'), max_length=40)
     
                     'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
                     'site': site,
                     'user': self.user}
-        subject = render_to_string('registration/activation_email_subject.txt',
-                                   ctx_dict)
+        subject = render_to_string(self.activation_email_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(self.activation_email_template, ctx_dict)
         
         self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)