From 6d0e2b215c2a69cb32b3c2108bc67926394c745c Mon Sep 17 00:00:00 2001
From: zubair-arbi <zubair.afzal@arbisoft.com>
Date: Wed, 21 May 2014 18:31:19 +0500
Subject: [PATCH] update _xmodule_recurse method

---
 cms/djangoapps/contentstore/views/helpers.py | 19 +++++++------------
 cms/djangoapps/contentstore/views/item.py    |  6 +++---
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/cms/djangoapps/contentstore/views/helpers.py b/cms/djangoapps/contentstore/views/helpers.py
index 466ed17..06b9258 100644
--- a/cms/djangoapps/contentstore/views/helpers.py
+++ b/cms/djangoapps/contentstore/views/helpers.py
@@ -4,7 +4,6 @@ from django.http import HttpResponse
 from django.shortcuts import redirect
 from edxmako.shortcuts import render_to_string, render_to_response
 from xmodule.modulestore.django import loc_mapper, modulestore
-from xmodule.modulestore.exceptions import DuplicateItemError, ItemNotFoundError
 
 __all__ = ['edge', 'event', 'landing']
 
@@ -37,24 +36,20 @@ def render_from_lms(template_name, dictionary, context=None, namespace='main'):
     return render_to_string(template_name, dictionary, context, namespace="lms." + namespace)
 
 
-def _xmodule_recurse(item, action, ignore_exception=None):
+def _xmodule_recurse(item, action, ignore_exception=()):
     """
     Recursively apply provided action on item and its children
 
-    ignore_duplicate_exception (str): A optional argument; when set to a certain value then ignores the corresponding
-        exception raised while xmodule recursion
+    ignore_exception (Exception Object): A optional argument; when passed ignores the corresponding
+        exception raised during xmodule recursion,
     """
     for child in item.get_children():
         _xmodule_recurse(child, action, ignore_exception)
 
-    if ignore_exception in ['ItemNotFoundError', 'DuplicateItemError']:
-        # In case of valid provided exception; ignore it and continue recursion
-        try:
-            return action(item)
-        except (ItemNotFoundError, DuplicateItemError):
-            return
-
-    action(item)
+    try:
+        return action(item)
+    except ignore_exception:
+        return
 
 
 def get_parent_xblock(xblock):
diff --git a/cms/djangoapps/contentstore/views/item.py b/cms/djangoapps/contentstore/views/item.py
index 4ed5e29..60753f3 100644
--- a/cms/djangoapps/contentstore/views/item.py
+++ b/cms/djangoapps/contentstore/views/item.py
@@ -21,7 +21,7 @@ from xblock.fragment import Fragment
 
 import xmodule
 from xmodule.modulestore.django import modulestore, loc_mapper
-from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationError
+from xmodule.modulestore.exceptions import ItemNotFoundError, InvalidLocationError, DuplicateItemError
 from xmodule.modulestore.inheritance import own_metadata
 from xmodule.modulestore.locator import BlockUsageLocator
 from xmodule.modulestore import Location
@@ -313,7 +313,7 @@ def _save_item(request, usage_loc, item_location, data=None, children=None, meta
             _xmodule_recurse(
                 existing_item,
                 lambda i: modulestore().unpublish(i.location),
-                ignore_exception='ItemNotFoundError'
+                ignore_exception=ItemNotFoundError
             )
         elif publish == 'create_draft':
             # This recursively clones the existing item location to a draft location (the draft is
@@ -321,7 +321,7 @@ def _save_item(request, usage_loc, item_location, data=None, children=None, meta
             _xmodule_recurse(
                 existing_item,
                 lambda i: modulestore().convert_to_draft(i.location),
-                ignore_exception='DuplicateItemError'
+                ignore_exception=DuplicateItemError
             )
 
     if data:
--
libgit2 0.26.0