From 8b8d1d711a72827607c3ee3634a9505ca9473cc2 Mon Sep 17 00:00:00 2001 From: kane-c Date: Fri, 7 Mar 2014 11:36:28 +1100 Subject: [PATCH 1/2] Fixed exception when menu config is Unicode If the menu config is Unicode (e.g. `from __future__ import unicode_literals` or `u'string'`), the Suit menu will trigger an exception. Tested on Python 2.7 with Django 1.6. --- suit/templatetags/suit_menu.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/suit/templatetags/suit_menu.py b/suit/templatetags/suit_menu.py index 07c61f2c..696dd91d 100644 --- a/suit/templatetags/suit_menu.py +++ b/suit/templatetags/suit_menu.py @@ -3,6 +3,7 @@ from django.contrib.admin import AdminSite from django.core.handlers.wsgi import WSGIRequest from django.core.urlresolvers import reverse, resolve +from django.utils import six import warnings from suit.config import get_config @@ -107,7 +108,7 @@ def make_menu(self, config): def make_app(self, app_def): if isinstance(app_def, dict): app = app_def.copy() - elif isinstance(app_def, str): + elif isinstance(app_def, six.string_types): if app_def == '-': app = self.make_separator() else: @@ -246,7 +247,7 @@ def process_models(self, app): def make_model(self, model_def, app_name): if isinstance(model_def, dict): model = model_def.copy() - elif isinstance(model_def, str): + elif isinstance(model_def, six.string_types): model = self.make_model_from_native(model_def, app_name) else: raise TypeError('MENU list item must be string or dict. Got %s' @@ -447,7 +448,7 @@ def make_menu_from_old_format(self, conf_order): if isinstance(order, (tuple, list)): app_name = order[0] models_order = order[1] if len(order) > 1 else None - if isinstance(app_name, str): + if isinstance(app_name, six.string_types): new_app['app'] = app_name elif isinstance(app_name, (tuple, list)): mapping = ('label', 'url', 'icon', 'permissions') @@ -456,7 +457,7 @@ def make_menu_from_old_format(self, conf_order): if models_order and isinstance(models_order, (tuple, list)): models = [] for model in models_order: - if isinstance(model, str): + if isinstance(model, six.string_types): models.append({'model': model}) elif isinstance(model, (list, tuple)): mapping = ('label', 'url', 'permissions') From 95ba602af5958af40b5139686e94e13f7d9c6c31 Mon Sep 17 00:00:00 2001 From: kane-c Date: Tue, 11 Mar 2014 10:28:37 +1100 Subject: [PATCH 2/2] Restored Django < 1.4.2 compatibility --- suit/templatetags/suit_menu.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/suit/templatetags/suit_menu.py b/suit/templatetags/suit_menu.py index 696dd91d..0d58d743 100644 --- a/suit/templatetags/suit_menu.py +++ b/suit/templatetags/suit_menu.py @@ -3,7 +3,13 @@ from django.contrib.admin import AdminSite from django.core.handlers.wsgi import WSGIRequest from django.core.urlresolvers import reverse, resolve -from django.utils import six + +try: + from django.utils.six import string_types +except ImportError: + # For Django < 1.4.2 + string_types = basestring, + import warnings from suit.config import get_config @@ -108,7 +114,7 @@ def make_menu(self, config): def make_app(self, app_def): if isinstance(app_def, dict): app = app_def.copy() - elif isinstance(app_def, six.string_types): + elif isinstance(app_def, string_types): if app_def == '-': app = self.make_separator() else: @@ -247,7 +253,7 @@ def process_models(self, app): def make_model(self, model_def, app_name): if isinstance(model_def, dict): model = model_def.copy() - elif isinstance(model_def, six.string_types): + elif isinstance(model_def, string_types): model = self.make_model_from_native(model_def, app_name) else: raise TypeError('MENU list item must be string or dict. Got %s' @@ -448,7 +454,7 @@ def make_menu_from_old_format(self, conf_order): if isinstance(order, (tuple, list)): app_name = order[0] models_order = order[1] if len(order) > 1 else None - if isinstance(app_name, six.string_types): + if isinstance(app_name, string_types): new_app['app'] = app_name elif isinstance(app_name, (tuple, list)): mapping = ('label', 'url', 'icon', 'permissions') @@ -457,7 +463,7 @@ def make_menu_from_old_format(self, conf_order): if models_order and isinstance(models_order, (tuple, list)): models = [] for model in models_order: - if isinstance(model, six.string_types): + if isinstance(model, string_types): models.append({'model': model}) elif isinstance(model, (list, tuple)): mapping = ('label', 'url', 'permissions')