Skip to content

Commit

Permalink
除左边栏外, 基本没错误了.
Browse files Browse the repository at this point in the history
  • Loading branch information
y2kconnect committed Oct 15, 2016
1 parent e9b95bc commit 990da9a
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
20 changes: 8 additions & 12 deletions error_info.txt
Original file line number Diff line number Diff line change
@@ -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: <function MainDashboardIndexViewDashboardGlobalSettingCommAdminViewBaseSettingBaseAdminViewBaseAdminObjectViewobject at 0x7f2f24397d90>
cacheable: False
the JSON object must be str, not 'bytes'
[15/Oct/2016 02:51:08] "GET / HTTP/1.1" 200 25380

4. 左边栏, 没有内容.

21 changes: 15 additions & 6 deletions xadmin/filters.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion xadmin/plugins/actions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from collections import OrderedDict
from django import forms
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -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([
Expand All @@ -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
Expand Down
17 changes: 13 additions & 4 deletions xadmin/plugins/filters.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion xadmin/plugins/quickfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion xadmin/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion xadmin/views/list.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]

Expand Down

0 comments on commit 990da9a

Please sign in to comment.