David Jean Louis avatar David Jean Louis committed efc413f

fixed issue #11: use builtin django.utils.simplejson instead of json/simplejson

Comments (0)

Files changed (2)

admin_tools/menu/models.py

     def __init__(self, **kwargs):
         super(BookmarkMenuItem, self).__init__(**kwargs)
         self.title = kwargs.get('title', _('Bookmarks'))
+        if 'bookmark' not in self.css_classes:
+            self.css_classes.append('bookmark')
 
     def init_with_context(self, context):
         """
         Please refer to the ``MenuItem::init_with_context()`` documentation.
         """
-        try:
-            bookmarks = get_menu_bookmarks(context['request'])
-        except Exception, exc:
-            warning_item = MenuItem(
-                title='Bookmark menu item requires the simplejson module'
-            )
-            warning_item.css_classes.append('warning')
-            self.children.append(warning_item)
-            return
-
-        for b in bookmarks:
+        for b in get_menu_bookmarks(context['request']):
             self.children.append(MenuItem(
                 url=b['url'],
                 title=mark_safe(b['title'])
             ))
         if not len(self.children):
             self.enabled = False
-        if 'bookmark' not in self.css_classes:
-            self.css_classes.append('bookmark')
 
 
 class DefaultMenu(Menu):

admin_tools/menu/utils.py

 Menu utilities.
 """
 
+import urllib
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
 from django.utils.importlib import import_module
+from django.utils import simplejson
 
 
 def get_admin_menu():
     """
     Returns the bookmarked items or raise an exception.
     """
-    import urllib
-    try:
-        import json
-    except ImportError:
-        # python < 2.6 
-        import simplejson as json
     json_str = urllib.unquote(request.COOKIES.get('menu.bookmarks'))
     if json_str is not None:
-        return json.loads(json_str)
+        return simplejson.loads(json_str)
     return []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.