Commits

James Bennett committed 8a1de44

Refactor the "already activated" string into a constant attached to RegistrationProfile

  • Participants
  • Parent commits d814f48

Comments (0)

Files changed (2)

registration/models.py

                 user = profile.user
                 user.is_active = True
                 user.save()
-                profile.activation_key = "ALREADY_ACTIVATED"
+                profile.activation_key = self.model.ACTIVATED
                 profile.save()
                 return user
         return False
     ``RegistrationManager``.
     
     """
+    ACTIVATED = u"ALREADY_ACTIVATED"
+    
     user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
     activation_key = models.CharField(_('activation key'), max_length=40)
     
         
         """
         expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)
-        return self.activation_key == "ALREADY_ACTIVATED" or \
+        return self.activation_key == self.ACTIVATED or \
                (self.user.date_joined + expiration_date <= datetime.datetime.now())
     activation_key_expired.boolean = True

registration/tests.py

         self.failUnless(User.objects.get(pk=self.sample_user.pk).is_active)
         
         # The activation key must now be the string "ALREADY_ACTIVATED".
-        self.failUnlessEqual(RegistrationProfile.objects.get(user=self.sample_user).activation_key, u"ALREADY_ACTIVATED")
+        self.failUnlessEqual(RegistrationProfile.objects.get(user=self.sample_user).activation_key,
+                             RegistrationProfile.ACTIVATED)
         
         # Activating an expired user returns False.
         self.failIf(RegistrationProfile.objects.activate_user(RegistrationProfile.objects.get(user=self.expired_user).activation_key))