import decorators\r
from forum.actions import EditProfileAction, FavoriteAction, BonusRepAction, SuspendAction\r
from forum.modules import ui\r
+from forum.utils import pagination\r
\r
import time\r
import decorators\r
\r
+class UserReputationSort(pagination.SimpleSort):\r
+ def apply(self, objects):\r
+ return objects.order_by('-is_active', self.order_by)\r
+\r
+class UserListPaginatorContext(pagination.PaginatorContext):\r
+ def __init__(self):\r
+ super (UserListPaginatorContext, self).__init__('USERS_LIST', sort_methods=(\r
+ (_('reputation'), UserReputationSort(_('reputation'), '-reputation', _("sorted by reputation"))),\r
+ (_('newest'), pagination.SimpleSort(_('recent'), '-date_joined', _("newest members"))),\r
+ (_('last'), pagination.SimpleSort(_('oldest'), 'date_joined', _("oldest members"))),\r
+ (_('name'), pagination.SimpleSort(_('by username'), 'username', _("sorted by username"))),\r
+ ), pagesizes=(20, 35, 60))\r
+\r
USERS_PAGE_SIZE = 35# refactor - move to some constants file\r
\r
@decorators.render('users/users.html', 'users', _('users'), weight=200)\r
def users(request):\r
- is_paginated = True\r
- sortby = request.GET.get('sort', 'reputation')\r
suser = request.REQUEST.get('q', "")\r
- try:\r
- page = int(request.GET.get('page', '1'))\r
- except ValueError:\r
- page = 1\r
+ users = User.objects.all()\r
\r
if suser == "":\r
- if sortby == "newest":\r
- objects_list = Paginator(User.objects.all().order_by('-date_joined'), USERS_PAGE_SIZE)\r
- elif sortby == "last":\r
- objects_list = Paginator(User.objects.all().order_by('date_joined'), USERS_PAGE_SIZE)\r
- elif sortby == "user":\r
- objects_list = Paginator(User.objects.all().order_by('username'), USERS_PAGE_SIZE)\r
- # default\r
- else:\r
- objects_list = Paginator(User.objects.all().order_by('-is_active', '-reputation'), USERS_PAGE_SIZE)\r
- base_url = reverse('users') + '?sort=%s&' % sortby\r
- else:\r
- sortby = "reputation"\r
- objects_list = Paginator(User.objects.filter(username__icontains=suser).order_by('-reputation'), USERS_PAGE_SIZE\r
- )\r
- base_url = reverse('users') + '?name=%s&sort=%s&' % (suser, sortby)\r
+ users = users.filter(username__icontains=suser)\r
\r
- try:\r
- users = objects_list.page(page)\r
- except (EmptyPage, InvalidPage):\r
- users = objects_list.page(objects_list.num_pages)\r
-\r
- return {\r
+ return pagination.paginated(request, 'users', UserListPaginatorContext(), {\r
"users" : users,\r
"suser" : suser,\r
- "keywords" : suser,\r
- "tab_id" : sortby,\r
- "context" : {\r
- 'is_paginated' : is_paginated,\r
- 'pages': objects_list.num_pages,\r
- 'page': page,\r
- 'has_previous': users.has_previous(),\r
- 'has_next': users.has_next(),\r
- 'previous': users.previous_page_number(),\r
- 'next': users.next_page_number(),\r
- 'base_url' : base_url\r
- }\r
- }\r
+ })\r
\r
\r
@login_required\r