Forráskód Böngészése

Fixed tests failures after Django upgrade.

bc Wong 15 éve
szülő
commit
5c8bfd2b9a

+ 8 - 2
apps/beeswax/src/beeswax/test_base.py

@@ -228,14 +228,20 @@ def verify_history(client, fragment, design=None, reverse=False):
   """
   Verify that the query fragment and/or design are in the query history.
   If reverse is True, verify the opposite.
-  Return the size of the history.
+  Return the size of the history; -1 if we fail to determine it.
   """
   resp = client.get('/beeswax/query_history')
   my_assert = reverse and assert_false or assert_true
   my_assert(fragment in resp.content)
   if design:
     my_assert(design in resp.content)
-  return len(resp.context['page'].object_list)
+
+  context = resp.context
+  if context:
+    return len(context['page'].object_list)
+  else:
+    LOG.warn('Cannot find history size. Response context is None')
+    return -1
 
 
 class BeeswaxSampleProvider(object):

+ 34 - 31
apps/useradmin/src/useradmin/views.py

@@ -104,38 +104,41 @@ def edit_user(request, username=None):
   if request.method == 'POST':
     form = UserChangeForm(request.POST, instance=instance)
     if form.is_valid(): # All validation rules pass
-      #
-      # Check for 3 more conditions:
-      # (1) A user cannot inactivate oneself;
-      # (2) Non-superuser cannot promote himself; and
-      # (3) The last active superuser cannot demote/inactivate himself.
-      #
-      form_is_super = form.cleaned_data["is_superuser"]
-      form_is_active = form.cleaned_data["is_active"]
-      if request.user.username == username and not form_is_active:
-        raise MessageException("You cannot make yourself inactive.")
-
-      global __users_lock
-      __users_lock.acquire()
-      try:
-        if form.instance.is_superuser:
-          if not form_is_super or not form_is_active:
-            # Is there any other active superuser left?
-            all_active_su = User.objects.filter(is_superuser__exact = True,
-                                                is_active__exact = True)
-            num_active_su = all_active_su.count()
-            assert num_active_su >= 1, "No active superuser configured"
-            if num_active_su == 1:
-              raise MessageException("You cannot remove the last active "
-                                     "superuser from the configuration.")
-        else:
-          if form_is_super and not request.user.is_superuser:
-            raise MessageException("You cannot make yourself a superuser.")
-
-        # All ok
+      if instance is None:
         form.save()
-      finally:
-        __users_lock.release()
+      else:
+        #
+        # Check for 3 more conditions:
+        # (1) A user cannot inactivate oneself;
+        # (2) Non-superuser cannot promote himself; and
+        # (3) The last active superuser cannot demote/inactivate himself.
+        #
+        if request.user.username == username and not form.instance.is_active:
+          raise MessageException("You cannot make yourself inactive.")
+
+        global __users_lock
+        __users_lock.acquire()
+        try:
+          # form.instance (and instance) now carry the new data
+          orig = User.objects.get(username=username)
+          if orig.is_superuser:
+            if not form.instance.is_superuser or not form.instance.is_active:
+              # Is there any other active superuser left?
+              all_active_su = User.objects.filter(is_superuser__exact = True,
+                                                  is_active__exact = True)
+              num_active_su = all_active_su.count()
+              assert num_active_su >= 1, "No active superuser configured"
+              if num_active_su == 1:
+                raise MessageException("You cannot remove the last active "
+                                       "superuser from the configuration.")
+          else:
+            if form.instance.is_superuser and not request.user.is_superuser:
+              raise MessageException("You cannot make yourself a superuser.")
+
+          # All ok
+          form.save()
+        finally:
+          __users_lock.release()
 
       request.path = urlresolvers.reverse(list_users)
       return list_users(request)