瀏覽代碼

Merge branch 'issue-5' into dev

Denis K 9 年之前
父節點
當前提交
918499303a
共有 6 個文件被更改,包括 20 次插入12 次删除
  1. 1 1
      jet/dashboard.py
  2. 3 2
      jet/forms.py
  3. 7 3
      jet/models.py
  4. 4 2
      jet/modules.py
  5. 3 2
      jet/utils.py
  6. 2 2
      jet/views.py

+ 1 - 1
jet/dashboard.py

@@ -91,7 +91,7 @@ class Dashboard(object):
     def render(self):
         context = self.context
         context.update({
-            'columns': xrange(self.columns),
+            'columns': range(self.columns),
             'modules': self.modules,
             'app_label': self.app_label,
         })

+ 3 - 2
jet/forms.py

@@ -10,6 +10,7 @@ except ImportError:
 import operator
 from jet.models import Bookmark, PinnedApplication, UserDashboardModule
 from jet.utils import get_current_dashboard, get_model_instance_label
+from functools import reduce
 
 
 class AddBookmarkForm(forms.ModelForm):
@@ -235,10 +236,10 @@ class ModelLookupForm(forms.Form):
         page = self.cleaned_data['page'] or 1
         offset = (page - 1) * limit
 
-        items = map(
+        items = list(map(
             lambda instance: {'id': instance.pk, 'text': get_model_instance_label(instance)},
             qs.all()[offset:offset + limit]
-        )
+        ))
         total = qs.count()
 
         return items, total

+ 7 - 3
jet/models.py

@@ -1,9 +1,11 @@
 from importlib import import_module
 from django.db import models
 from django.utils import timezone
+from django.utils.encoding import python_2_unicode_compatible
 from django.utils.translation import ugettext_lazy as _
 
 
+@python_2_unicode_compatible
 class Bookmark(models.Model):
     url = models.URLField(verbose_name=_('URL'))
     title = models.CharField(verbose_name=_('title'), max_length=255)
@@ -15,10 +17,11 @@ class Bookmark(models.Model):
         verbose_name_plural = _('bookmarks')
         ordering = ('date_add',)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.title
 
 
+@python_2_unicode_compatible
 class PinnedApplication(models.Model):
     app_label = models.CharField(verbose_name=_('application name'), max_length=255)
     user = models.PositiveIntegerField(verbose_name=_('user'))
@@ -29,10 +32,11 @@ class PinnedApplication(models.Model):
         verbose_name_plural = _('pinned applications')
         ordering = ('date_add',)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.app_label
 
 
+@python_2_unicode_compatible
 class UserDashboardModule(models.Model):
     title = models.CharField(verbose_name=_('Title'), max_length=255)
     module = models.CharField(verbose_name=_('module'), max_length=255)
@@ -49,7 +53,7 @@ class UserDashboardModule(models.Model):
         verbose_name_plural = _('user dashboard modules')
         ordering = ('column', 'order')
 
-    def __unicode__(self):
+    def __str__(self):
         return self.module
 
     def load_module(self):

+ 4 - 2
jet/modules.py

@@ -129,7 +129,7 @@ class LinkList(DashboardModule):
     child_name_plural = _('Links')
 
     def __init__(self, title=None, children=list(), **kwargs):
-        children = map(self.parse_link, children)
+        children = list(map(self.parse_link, children))
         kwargs.update({'children': children})
         super(LinkList, self).__init__(title, **kwargs)
 
@@ -184,8 +184,9 @@ class AppList(DashboardModule):
                 lambda model: self.exclude is None or model['object_name'] not in self.exclude and app['app_label'] + '.*' not in self.exclude,
                 app['models']
             )
+            app['models'] = list(app['models'])
 
-            if self.hide_empty and len(app['models']) == 0:
+            if self.hide_empty and len(list(app['models'])) == 0:
                 app_to_remove.append(app)
 
         for app in app_to_remove:
@@ -224,6 +225,7 @@ class ModelList(DashboardModule):
                 lambda model: self.exclude is None or model['object_name'] not in self.exclude and app['app_label'] + '.*' not in self.exclude,
                 app['models']
             )
+            app['models'] = list(app['models'])
 
             models.extend(app['models'])
 

+ 3 - 2
jet/utils.py

@@ -5,7 +5,8 @@ from django.http import HttpResponse
 from django.core.urlresolvers import reverse, resolve
 from django.contrib import admin
 from django.contrib.admin import AdminSite
-from django.utils.encoding import force_unicode, smart_text
+from django.utils.encoding import force_text
+from django.utils.encoding import smart_text
 from django.utils.functional import Promise
 from jet import settings
 
@@ -74,7 +75,7 @@ def get_current_dashboard(location):
 class LazyEncoder(json.JSONEncoder):
     def default(self, obj):
         if isinstance(obj, Promise):
-            return force_unicode(obj)
+            return force_text(obj)
         return obj
 
 

+ 2 - 2
jet/views.py

@@ -63,10 +63,10 @@ class UpdateDashboardModuleView(SuccessMessageMixin, UpdateView):
             return formset_factory(self.module.child_form, can_delete=True, extra=1)(**self.get_children_formset_kwargs())
 
     def clean_children_data(self, children):
-        children = filter(
+        children = list(filter(
             lambda item: isinstance(item, dict) and item and item.get('DELETE') is not True,
             children
-        )
+        ))
         for item in children:
             item.pop('DELETE')
         return children