Commits

Venelin Stoykov committed 3748051

Add Python 3 support

Comments (0)

Files changed (10)

admin_tools/dashboard/dashboards.py

 from django.utils.translation import ugettext_lazy as _
 from django.core.urlresolvers import reverse
 from django.contrib.contenttypes.models import ContentType
+try:
+    from django.utils.encoding import force_text
+except ImportError:
+    # Django < 1.5
+    from django.utils.encoding import force_unicode as force_text
 
 from admin_tools.dashboard import modules
 from admin_tools.utils import get_admin_site_name, uniquify
         """
         Internal method used to distinguish different dashboards in js code.
         """
-        return '%s-dashboard' % slugify(unicode(self.app_title))
+        return '%s-dashboard' % slugify(force_text(self.app_title))
 
 
 class DefaultIndexDashboard(Dashboard):

admin_tools/dashboard/modules.py

                 model_dict['add_url'] = self._get_admin_add_url(model, context)
             apps[app_label]['models'].append(model_dict)
 
-        apps_sorted = apps.keys()
-        apps_sorted.sort()
-        for app in apps_sorted:
+        for app in sorted(apps.keys()):
             # sort model list alphabetically
-            apps[app]['models'].sort(lambda x, y: cmp(x['title'], y['title']))
+            apps[app]['models'].sort(key=lambda x: x['title'])
             self.children.append(apps[app])
         self._initialized = True
 

admin_tools/dashboard/utils.py

 """
 Dashboard utilities.
 """
-import types
-
 from django.conf import settings
 from django.utils.importlib import import_module
 from django.utils.text import capfirst
     raise ValueError('Invalid dashboard location: "%s"' % location)
 
 def _get_dashboard_cls(dashboard_cls, context):
-    if type(dashboard_cls) is types.DictType:
+    if isinstance(dashboard_cls, dict):
         curr_url = context.get('request').path
         for key in dashboard_cls:
             admin_site_mod, admin_site_inst = key.rsplit('.', 1)

admin_tools/dashboard/views.py

 except ImportError:
     from django.contrib.csrf.middleware import csrf_exempt
 
-from forms import DashboardPreferencesForm
-from models import DashboardPreferences
+from .forms import DashboardPreferencesForm
+from .models import DashboardPreferences
 
 
 @login_required

admin_tools/menu/forms.py

-import urllib
+try:
+    from urllib.parse import unquote
+except ImportError:
+    # Python 2 compatibility
+    from urllib import unquote
 
 from django import forms
 
 
     def clean_url(self):
         url = self.cleaned_data['url']
-        return urllib.unquote(url)
+        return unquote(url)
 
     def save(self, *args, **kwargs):
         bookmark = super(BookmarkForm, self).save(commit=False, *args, **kwargs)

admin_tools/menu/items.py

                 'url': self._get_admin_change_url(model, context)
             })
 
-        apps_sorted = apps.keys()
-        apps_sorted.sort()
-        for app in apps_sorted:
+        for app in sorted(apps.keys()):
             app_dict = apps[app]
             item = MenuItem(title=app_dict['title'], url=app_dict['url'])
             # sort model list alphabetically
-            apps[app]['models'].sort(lambda x, y: cmp(x['title'], y['title']))
+            apps[app]['models'].sort(key=lambda x: x['title'])
             for model_dict in apps[app]['models']:
                 item.children.append(MenuItem(**model_dict))
             self.children.append(item)

admin_tools/menu/utils.py

 Menu utilities.
 """
 
-import types
-
 from django.conf import settings
 from django.utils.importlib import import_module
 from django.core.urlresolvers import reverse
 
 
 def _get_menu_cls(menu_cls, context):
-    if type(menu_cls) is types.DictType:
+    if isinstance(menu_cls, dict):
         curr_url = context.get('request').path
         for key in menu_cls:
             admin_site_mod, admin_site_inst = key.rsplit('.', 1)

admin_tools/menu/views.py

 except ImportError:
     from django.contrib.csrf.middleware import csrf_exempt
 
-from forms import BookmarkForm
-from models import Bookmark
+from .forms import BookmarkForm
+from .models import Bookmark
 
 
 @login_required

admin_tools/utils.py

 """
 Admin ui common utilities.
 """
-import types
 from fnmatch import fnmatch
 
 from django.conf import settings
         'admin_tools.dashboard.dashboards.DefaultIndexDashboard'
     )
 
-    if type(dashboard_cls) is types.DictType:
+    if isinstance(dashboard_cls, dict):
         if context:
             request = context.get('request')
         curr_url = request.path

test_proj/dashboard.py

             ]
         ))
         self.children.append(modules.Group(
-            title=u'Test group',
+            title='Test group',
             children=[
                 modules.ModelList(
-                    u'Tab 1',
+                    'Tab 1',
                     ['django.contrib.*']
                 ),
                 modules.ModelList(
-                    u'Tab 2',
+                    'Tab 2',
                     ['test_app.*']
                 ),
             ]