Commits

James Bennett  committed 869d085

Add an admin action for manually activating users.

  • Participants
  • Parent commits 6502163

Comments (0)

Files changed (2)

File registration/admin.py

 
 
 class RegistrationAdmin(admin.ModelAdmin):
-    actions = ['resend_activation_email']
-    list_display = ('__unicode__', 'activation_key_expired')
+    actions = ['activate_users', 'resend_activation_email']
+    list_display = ('user', 'activation_key_expired')
     raw_id_fields = ['user']
     search_fields = ('user__username', 'user__first_name')
 
+    def activate_users(self, request, queryset):
+        """
+        Activates the selected users, if they are not alrady
+        activated.
+        
+        """
+        for profile in queryset:
+            RegistrationProfile.objects.activate_user(profile.activation_key)
+    activate_users.short_description = _("Activate users")
+
     def resend_activation_email(self, request, queryset):
         """
         Re-sends activation emails for the selected users.

File registration/tests/backends.py

         admin_class.resend_activation_email(_mock_request(),
                                             RegistrationProfile.objects.all())
         self.assertEqual(len(mail.outbox), 2) # No additional email because the account has activated.
+
+    def test_activation_action(self):
+        """
+        Test manual activation of users view admin action.
+        
+        """
+        admin_class = RegistrationAdmin(RegistrationProfile, admin.site)
+
+        alice = self.backend.register(_mock_request(),
+                                      username='alice',
+                                      email='alice@example.com',
+                                      password1='swordfish')
+
+        admin_class.activate_users(_mock_request(),
+                                   RegistrationProfile.objects.all())
+        self.failUnless(User.objects.get(username='alice').is_active)