server/users: sort by name by default

This commit is contained in:
rr- 2016-04-11 19:19:19 +02:00
parent 543d0fca57
commit 0b5f436f40
3 changed files with 6 additions and 1 deletions

View File

@ -46,6 +46,7 @@ class SearchExecutor(object):
query = self._handle_anonymous(
query, self._create_criterion(token, negated))
query = self._search_config.finalize_query(query)
return query
def _handle_key_value(self, query, key, value, negated):

View File

@ -8,6 +8,9 @@ class UserSearchConfig(BaseSearchConfig):
def create_query(self, session):
return session.query(db.User)
def finalize_query(self, query):
return query.order_by(db.User.name.asc())
@property
def anonymous_filter(self):
return self._create_basic_filter(db.User.name, allow_ranged=False)

View File

@ -124,8 +124,9 @@ class TestUserSearchExecutor(DatabaseTestCase):
self._test('', 2, 1, 2, ['u2'])
def test_order_by_name(self):
self.session.add(util.mock_user('u1'))
self.session.add(util.mock_user('u2'))
self.session.add(util.mock_user('u1'))
self._test('', 1, 100, 2, ['u1', 'u2'])
self._test('order:name', 1, 100, 2, ['u1', 'u2'])
self._test('-order:name', 1, 100, 2, ['u2', 'u1'])
self._test('order:name,asc', 1, 100, 2, ['u1', 'u2'])