Add Python 3 support
This commit is contained in:
parent
a4ada180e4
commit
a40b33f7d3
|
@ -7,6 +7,11 @@ from django.utils.importlib import import_module
|
|||
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
|
||||
|
@ -203,7 +208,7 @@ class AppIndexDashboard(Dashboard):
|
|||
"""
|
||||
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):
|
||||
|
|
|
@ -456,11 +456,9 @@ class AppList(DashboardModule, AppListElementMixin):
|
|||
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
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""
|
||||
Dashboard utilities.
|
||||
"""
|
||||
import types
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.importlib import import_module
|
||||
from django.utils.text import capfirst
|
||||
|
@ -23,7 +21,7 @@ def get_dashboard(context, location):
|
|||
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)
|
||||
|
|
|
@ -9,8 +9,8 @@ try:
|
|||
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
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import urllib
|
||||
try:
|
||||
from urllib.parse import unquote
|
||||
except ImportError:
|
||||
# Python 2 compatibility
|
||||
from urllib import unquote
|
||||
|
||||
from django import forms
|
||||
|
||||
|
@ -16,7 +20,7 @@ class BookmarkForm(forms.ModelForm):
|
|||
|
||||
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)
|
||||
|
|
|
@ -200,13 +200,11 @@ class AppList(MenuItem, AppListElementMixin):
|
|||
'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)
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
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)
|
||||
|
|
|
@ -9,8 +9,8 @@ try:
|
|||
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
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""
|
||||
Admin ui common utilities.
|
||||
"""
|
||||
import types
|
||||
from fnmatch import fnmatch
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -27,7 +26,7 @@ def get_admin_site(context=None, request=None):
|
|||
'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
|
||||
|
|
|
@ -74,14 +74,14 @@ class CustomIndexDashboard(Dashboard):
|
|||
]
|
||||
))
|
||||
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.*']
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue