From 990da9a7c3e5999e0c3d90d9a979ddabed3326df Mon Sep 17 00:00:00 2001 From: wy Date: Sat, 15 Oct 2016 22:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=A4=E5=B7=A6=E8=BE=B9=E6=A0=8F=E5=A4=96,?= =?UTF-8?q?=20=E5=9F=BA=E6=9C=AC=E6=B2=A1=E9=94=99=E8=AF=AF=E4=BA=86.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- error_info.txt | 20 ++++++++------------ xadmin/filters.py | 21 +++++++++++++++------ xadmin/plugins/actions.py | 5 ++++- xadmin/plugins/filters.py | 17 +++++++++++++---- xadmin/plugins/quickfilter.py | 6 +++++- xadmin/views/base.py | 6 +++++- xadmin/views/list.py | 6 +++++- 7 files changed, 55 insertions(+), 26 deletions(-) diff --git a/error_info.txt b/error_info.txt index 5b88984de..bc5f98e78 100644 --- a/error_info.txt +++ b/error_info.txt @@ -1,15 +1,11 @@ xadmin for py3中, 暂时无法解决的问题: -2. demo_app中, - - File "/mnt/backup/data/src/code/Django/xadmin-wy/demo_app/../xadmin/filters.py", line 270, in __init__ - self.lookup_isnull_name: False -AttributeError: 'DateFieldListFilter' object has no attribute 'lookup_isnull_name' -[12/Oct/2016 18:54:52] "GET /app/accessrecord/chart/user_count/?_p_date__lt=2013-01-29&p=1&_p_date__gte=2013-01-08 HTTP/1.1" 500 15756 -[12/Oct/2016 18:54:52] "GET /favicon.ico HTTP/1.1" 404 6219 -^C(py3)u01@asus:~/src/env/py3/xadmin-wy/demo_app$ - - -3. 看到 xadmin-wy/xadmin/filters.py 的 DateFieldListFilter.__init__() - +3. 启动时报错. +xadmin/sites.py --> AdminSite.admin_view(): ... + view: + cacheable: False +the JSON object must be str, not 'bytes' +[15/Oct/2016 02:51:08] "GET / HTTP/1.1" 200 25380 + +4. 左边栏, 没有内容. diff --git a/xadmin/filters.py b/xadmin/filters.py index b4da9b43c..0c136cb76 100644 --- a/xadmin/filters.py +++ b/xadmin/filters.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +import sys from django.db import models from django.core.exceptions import ImproperlyConfigured from django.utils.encoding import smart_text @@ -46,8 +47,10 @@ def query_string(self, new_params=None, remove=None): return self.admin_view.get_query_string(new_params, remove) def form_params(self): - return self.admin_view.get_form_params( - remove=map(lambda k: FILTER_PREFIX + k, self.used_params.keys())) + arr = map(lambda k: FILTER_PREFIX + k, self.used_params.keys()) + if 2 < sys.version_info.major: + arr = list(arr) + return self.admin_view.get_form_params(remove=arr) def has_output(self): """ @@ -121,14 +124,20 @@ def __init__(self, field, request, params, model, admin_view, field_path): else: self.context_params["%s_val" % name] = '' - map(lambda kv: setattr( - self, 'lookup_' + kv[0], kv[1]), self.context_params.items()) + arr = map( + lambda kv: setattr(self, 'lookup_' + kv[0], kv[1]), + self.context_params.items() + ) + if 2 < sys.version_info.major: + list(arr) def get_context(self): context = super(FieldFilter, self).get_context() context.update(self.context_params) - context['remove_url'] = self.query_string( - {}, map(lambda k: FILTER_PREFIX + k, self.used_params.keys())) + obj = map(lambda k: FILTER_PREFIX + k, self.used_params.keys()) + if 2 < sys.version_info.major: + obj = list(obj) + context['remove_url'] = self.query_string({}, obj) return context def has_output(self): diff --git a/xadmin/plugins/actions.py b/xadmin/plugins/actions.py index fd8a2bf57..c16934159 100644 --- a/xadmin/plugins/actions.py +++ b/xadmin/plugins/actions.py @@ -1,3 +1,4 @@ +import sys from collections import OrderedDict from django import forms from django.core.exceptions import PermissionDenied @@ -227,6 +228,8 @@ def get_actions(self): # get_action might have returned None, so filter any of those out. actions = filter(None, actions) + if 2 < sys.version_info.major: + actions = list(actions) # Convert the actions into a OrderedDict keyed by name. actions = OrderedDict([ @@ -242,7 +245,7 @@ def get_action_choices(self): tuple (name, description). """ choices = [] - for ac, name, description, icon in self.actions.itervalues(): + for ac, name, description, icon in self.actions.values(): choice = (name, description % model_format_dict(self.opts), icon) choices.append(choice) return choices diff --git a/xadmin/plugins/filters.py b/xadmin/plugins/filters.py index ff60d90c2..ae01d8955 100644 --- a/xadmin/plugins/filters.py +++ b/xadmin/plugins/filters.py @@ -1,4 +1,5 @@ import operator +import sys from future.utils import iteritems from xadmin import widgets from xadmin.plugins.utils import get_context_dict @@ -140,8 +141,10 @@ def get_list_queryset(self, queryset): self.has_filters = bool(self.filter_specs) self.admin_view.filter_specs = self.filter_specs - self.admin_view.used_filter_num = len( - filter(lambda f: f.is_used, self.filter_specs)) + obj = filter(lambda f: f.is_used, self.filter_specs) + if 2 < sys.version_info.major: + obj = list(obj) + self.admin_view.used_filter_num = len(obj) try: for key, value in lookup_params.items(): @@ -191,10 +194,16 @@ def construct_search(field_name): # Media def get_media(self, media): - if bool(filter(lambda s: isinstance(s, DateFieldListFilter), self.filter_specs)): + arr = filter(lambda s: isinstance(s, DateFieldListFilter), self.filter_specs) + if 2 < sys.version_info.major: + arr = list(arr) + if bool(arr): media = media + self.vendor('datepicker.css', 'datepicker.js', 'xadmin.widget.datetime.js') - if bool(filter(lambda s: isinstance(s, RelatedFieldSearchFilter), self.filter_specs)): + arr = filter(lambda s: isinstance(s, RelatedFieldSearchFilter), self.filter_specs) + if 2 < sys.version_info.major: + arr = list(arr) + if bool(arr): media = media + self.vendor( 'select.js', 'select.css', 'xadmin.widget.select.js') return media + self.vendor('xadmin.plugin.filters.js') diff --git a/xadmin/plugins/quickfilter.py b/xadmin/plugins/quickfilter.py index e6caf6da8..cae51c463 100644 --- a/xadmin/plugins/quickfilter.py +++ b/xadmin/plugins/quickfilter.py @@ -3,6 +3,7 @@ @author: LAB_ADM ''' +import sys from future.utils import iteritems from django.utils.translation import ugettext_lazy as _ from xadmin.filters import manager,MultiSelectFieldListFilter @@ -147,7 +148,10 @@ def get_list_queryset(self, queryset): self.has_filters = bool(self.filter_specs) self.admin_view.quickfilter['filter_specs'] = self.filter_specs - self.admin_view.quickfilter['used_filter_num'] = len(filter(lambda f: f.is_used, self.filter_specs)) + obj = filter(lambda f: f.is_used, self.filter_specs) + if 2 < sys.version_info.major: + obj = list(obj) + self.admin_view.quickfilter['used_filter_num'] = len(obj) if use_distinct: return queryset.distinct() diff --git a/xadmin/views/base.py b/xadmin/views/base.py index c3cda64a1..1f89fa1a4 100644 --- a/xadmin/views/base.py +++ b/xadmin/views/base.py @@ -86,9 +86,13 @@ def wrap(func): def method(self, context, nodes, *arg, **kwargs): _dict = func(self, context, nodes, *arg, **kwargs) from django.template.loader import get_template, select_template + if 2 < sys.version_info.major: + cls_string = str + else: + cls_string = basestring if isinstance(file_name, Template): t = file_name - elif not isinstance(file_name, basestring) and is_iterable(file_name): + elif not isinstance(file_name, cls_string) and is_iterable(file_name): t = select_template(file_name) else: t = get_template(file_name) diff --git a/xadmin/views/list.py b/xadmin/views/list.py index d18d56032..203aae1a2 100644 --- a/xadmin/views/list.py +++ b/xadmin/views/list.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +import sys from collections import OrderedDict from django.core.exceptions import PermissionDenied, ObjectDoesNotExist from django.core.paginator import InvalidPage, Paginator @@ -460,7 +461,10 @@ def result_header(self, field_name, row): if field_name in ordering_field_columns: sorted = True order_type = ordering_field_columns.get(field_name).lower() - sort_priority = ordering_field_columns.keys().index(field_name) + 1 + arr = ordering_field_columns.keys() + if 2 < sys.version_info.major: + arr = list(arr) + sort_priority = arr.index(field_name) + 1 th_classes.append('sorted %sending' % order_type) new_order_type = {'asc': 'desc', 'desc': 'asc'}[order_type]