X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/eb1b2a97a14f9a4daa772709972e0d1650ac4fd3..2075ed66ad7cca695634c0a862126ea3ff66ea2e:/forum/views/users.py diff --git a/forum/views/users.py b/forum/views/users.py index 9dbde3e..6eb9baa 100644 --- a/forum/views/users.py +++ b/forum/views/users.py @@ -24,24 +24,22 @@ from forum.utils import pagination from forum.views.readers import QuestionListPaginatorContext, AnswerPaginatorContext from forum.settings import ONLINE_USERS -import bisect import time import datetime import decorators -import unicodedata class UserReputationSort(pagination.SimpleSort): def apply(self, objects): return objects.order_by('-is_active', self.order_by) class UserListPaginatorContext(pagination.PaginatorContext): - def __init__(self): + def __init__(self, pagesizes=(20, 35, 60)): super (UserListPaginatorContext, self).__init__('USERS_LIST', sort_methods=( (_('reputation'), UserReputationSort(_('reputation'), '-reputation', _("sorted by reputation"))), (_('newest'), pagination.SimpleSort(_('recent'), '-date_joined', _("newest members"))), (_('last'), pagination.SimpleSort(_('oldest'), 'date_joined', _("oldest members"))), (_('name'), pagination.SimpleSort(_('by username'), 'username', _("sorted by username"))), - ), pagesizes=(20, 35, 60)) + ), pagesizes=pagesizes) class SubscriptionListPaginatorContext(pagination.PaginatorContext): def __init__(self): @@ -257,8 +255,14 @@ def suspend(request, id): def user_view(template, tab_name, tab_title, tab_description, private=False, tabbed=True, render_to=None, weight=500): def decorator(fn): - def params(request, id, slug=None): - user = get_object_or_404(User, id=id) + def params(request, id=None, slug=None): + # Get the user object by id if the id parameter has been passed + if id is not None: + user = get_object_or_404(User, id=id) + # ...or by slug if the slug has been given + elif slug is not None: + user = get_object_or_404(User, username=slug) + if private and not (user == request.user or request.user.is_superuser): raise ReturnImediatelyException(HttpResponseUnauthorized(request)) @@ -306,7 +310,7 @@ def user_profile(request, user): up_votes = user.vote_up_count down_votes = user.vote_down_count votes_today = user.get_vote_count_today() - votes_total = users.can_vote_count_today() + votes_total = user.can_vote_count_today() user_tags = Tag.objects.filter(Q(nodes__author=user) | Q(nodes__children__author=user)) \ .annotate(user_tag_usage_count=Count('name')).order_by('-user_tag_usage_count') @@ -315,7 +319,7 @@ def user_profile(request, user): Badge.objects.filter(awards__user=user).values('id').annotate(count=Count('cls')).order_by('-count')] return pagination.paginated(request, ( - ('questions', QuestionListPaginatorContext('USER_QUESTION_LIST', _('questions'), 15)), + ('questions', QuestionListPaginatorContext('USER_QUESTION_LIST', _('questions'), default_pagesize=15)), ('answers', UserAnswersPaginatorContext())), { "view_user" : user, "questions" : questions,