kopia lustrzana https://github.com/wagtail/wagtail
Fix assumptions about user model fields, issue #1433
rodzic
a67c971f4f
commit
ac5d6e4945
|
@ -47,6 +47,8 @@ Changelog
|
|||
* Fix: SASS compilation errors during Wagtail development no longer cause exit of Gulp process, instead throws error to console and continues (Thomas Winter)
|
||||
* Fix: Explorer page listing now uses specific page models, so that custom URL schemes defined on Page subclasses are respected
|
||||
* Fix: Made settings menu clickable again in Firefox 46.0a2 (Juha Kujala)
|
||||
* Fix: User management index view no longer assumes the presence of `username`, `first_name`, `last_name` and `email` fields on the user model (Eirik Krogstad)
|
||||
|
||||
|
||||
1.3.1 (05.01.2016)
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -114,6 +114,7 @@ Contributors
|
|||
* Mike Dingjan
|
||||
* Loic Teixeira
|
||||
* Juha Kujala
|
||||
* Eirik Krogstad
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -91,6 +91,7 @@ Bug fixes
|
|||
* SASS compilation errors during Wagtail development no longer cause exit of Gulp process, instead throws error to console and continues (Thomas Winter)
|
||||
* Explorer page listing now uses specific page models, so that custom URL schemes defined on Page subclasses are respected
|
||||
* Made settings menu clickable again in Firefox 46.0a2 (Juha Kujala)
|
||||
* User management index view no longer assumes the presence of ``username``, ``first_name``, ``last_name`` and ``email`` fields on the user model (Eirik Krogstad)
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
|
|
@ -28,39 +28,42 @@ def index(request):
|
|||
q = None
|
||||
is_searching = False
|
||||
|
||||
model_fields = [f.name for f in User._meta.get_fields()]
|
||||
|
||||
if 'q' in request.GET:
|
||||
form = SearchForm(request.GET, placeholder=_("Search users"))
|
||||
if form.is_valid():
|
||||
q = form.cleaned_data['q']
|
||||
|
||||
is_searching = True
|
||||
conditions = Q()
|
||||
|
||||
if User.USERNAME_FIELD == 'username':
|
||||
users = User.objects.filter(
|
||||
Q(username__icontains=q) |
|
||||
Q(first_name__icontains=q) |
|
||||
Q(last_name__icontains=q) |
|
||||
Q(email__icontains=q)
|
||||
)
|
||||
else:
|
||||
users = User.objects.filter(
|
||||
Q(first_name__icontains=q) |
|
||||
Q(last_name__icontains=q) |
|
||||
Q(email__icontains=q)
|
||||
)
|
||||
if 'username' in model_fields:
|
||||
conditions |= Q(username__icontains=q)
|
||||
|
||||
if 'first_name' in model_fields:
|
||||
conditions |= Q(first_name__icontains=q)
|
||||
|
||||
if 'last_name' in model_fields:
|
||||
conditions |= Q(last_name__icontains=q)
|
||||
|
||||
if 'email' in model_fields:
|
||||
conditions |= Q(email__icontains=q)
|
||||
|
||||
users = User.objects.filter(conditions)
|
||||
else:
|
||||
form = SearchForm(placeholder=_("Search users"))
|
||||
|
||||
if not is_searching:
|
||||
users = User.objects
|
||||
users = User.objects.all()
|
||||
|
||||
users = users.order_by('last_name', 'first_name')
|
||||
if 'last_name' in model_fields and 'first_name' in model_fields:
|
||||
users = users.order_by('last_name', 'first_name')
|
||||
|
||||
if 'ordering' in request.GET:
|
||||
ordering = request.GET['ordering']
|
||||
|
||||
if ordering == 'username':
|
||||
users = users.order_by(ordering)
|
||||
users = users.order_by(User.USERNAME_FIELD)
|
||||
else:
|
||||
ordering = 'name'
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue