]> git.openstreetmap.org Git - osqa.git/commitdiff
Makes tags and users lists use the new paginators, completelly remove the old cnprog...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 7 Jul 2010 12:47:35 +0000 (12:47 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Wed, 7 Jul 2010 12:47:35 +0000 (12:47 +0000)
Fixes OSQA 306, Tags are badly sorted.

git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@497 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/skins/default/media/style/style.css
forum/skins/default/templates/book.html [deleted file]
forum/skins/default/templates/question.html
forum/skins/default/templates/questions.html
forum/skins/default/templates/tags.html
forum/skins/default/templates/users/users.html
forum/templatetags/extra_tags.py
forum/utils/pagination.py
forum/views/decorators.py
forum/views/readers.py
forum/views/users.py

index 99edef0997119ca790ee6f926963e81b51b428bb..e74bba65ad4d322ec900207b5fe46040d63ab2eb 100644 (file)
@@ -1103,6 +1103,7 @@ ins {
     line-height: 140%;
     padding: 5px;
     width: 170px;
+    display: inline-block;
 }
 
 .user ul {
diff --git a/forum/skins/default/templates/book.html b/forum/skins/default/templates/book.html
deleted file mode 100644 (file)
index 8574fa7..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-{% extends "base_content.html" %}
-<!-- template book.html -->
-{% load i18n %}
-{% load extra_tags %}
-{% load extra_filters %}
-{% load humanize %}
-{% block title %}{% spaceless %}{{ book.title }}-{% trans "reading channel" %}{% endspaceless %}{% endblock %}
-{% block forejs %}
-       <script type="text/javascript">        
-         $().ready(function(){
-            $("#nav_books").attr('className',"on");
-            //$("#nav_ask").hide();
-        });
-         
-        </script>
-{% endblock %}
-{% block content %}
-    <div class="headNormal"><a href="{{ book.get_absolute_url }}">《{{ book.title }}》</a></div>
-    <div class="bookInfo">
-        <div class="bookCover">
-            <img src="{{ book.cover_img }}" >
-        </div>
-        <div class="bookSummary">
-            <table>
-               <tr>
-                       <td>{% trans "[author]" %}</td>
-                       <td><b><a href="{% url user book.user.id %}" rel="nofollow" >{{ book.author }}</a></b></td>
-               </tr>
-               <tr>
-                       <td>{% trans "[publisher]" %}</td>
-                       <td>{{ book.publication }}</td>
-               </tr>
-                <tr>
-                       <td>{% trans "[publication date]" %}</td>
-                       <td>{{ book.published_at|date:"Y-m" }}</td>
-               </tr>
-                <tr>
-                       <td>{% trans "[price]" %}</td>
-                       <td>{{ book.price }} {% trans "currency unit" %}</td>
-               </tr>
-                <tr>
-                       <td>{% trans "[pages]" %}</td>
-                       <td>{{ book.pages }} {% trans "pages abbreviation" %}</td>
-               </tr>
-                <tr>
-                       <td>{% trans "[tags]" %}</td>
-                       <td>{{ book.tagnames }}</td>
-               </tr>
-                <tr>
-                       <td>&nbsp;</td>
-                       <td> </td>
-               </tr>
-                {% if author_info.blog_url %}
-                <tr>
-                    <td></td>
-                    <td><a href="{{ author_info.blog_url }}" rel="nofollow" >{% trans "author blog" %} »</a></td>
-               </tr>
-                
-                {% endif %}
-                <tr>
-                    <td> </td>
-                    <td><a href="#" rel="nofollow">{% trans "book directory" %} »</a></td>
-               </tr>
-                <tr>
-                    <td> </td>
-                    <td><a href="#" rel="nofollow">{% trans "buy online" %} »</a></td>
-               </tr>
-            </table>
-        </div>
-        <div class="blogRss">
-    
-        </div>
-    </div>
-    
-    <div class="bookQuestions">
-        
-        <div class="tabBar">
-            <div class="tabsB">
-                <a id="qa" class="on" title="{% trans "book technical Q&A %}" href="#">{% trans "reader questions" %}</a>
-            </div>
-        </div>
-        <div class="bookAsk"><a href="{% url ask_book book.short_name %}">{% trans "ask the author" %}</div>
-        <div class="user-stats-table">
-            {% for question in questions.object_list %}
-                {% if question.favourite_count %}
-                    {% if question.favorited_myself %}
-                        <div class="favorites-count">
-                            <img title="{% trans "this question was selected as favorite" %} {{question.favourite_count}} {% trans "number of times" %}" src="{% media  "/media/images/vote-favorite-on.png" %}">
-                            <div><b>{{question.favourite_count|intcomma}}</b></div>
-                        </div>
-                    {% else %}
-                        <div class="favorites-count-off">
-                            <img title="{% trans "this question was selected as favorite" %} {{question.favourite_count}} {% trans "number of times" %}" src="{% media  "/media/images/vote-favorite-off.png" %}">
-                            <div><b>{{question.favourite_count|intcomma}}</b></div>
-                        </div>
-                    {% endif %}
-                {% else %}
-                    <div class="favorites-empty"> </div>
-                {% endif %}
-            <div id="question-summary-{{question.id}}" class="question-summary narrow">
-                <a style="text-decoration: none;" href="{% url questions %}{{question.id}}/{{question.get_question_title}}">
-                    <div class="stats">
-                        <div class="votes">
-                            <div class="vote-count-post">{{question.score|intcomma}}</div> 
-                            {% trans "votes" %}
-                          
-                        </div>
-                        <div title="{% if question.answer_accepted %}{% trans "the answer has been accepted to be correct" %}{% endif %}" class="status {% if question.answer_accepted %}answered-accepted{% endif %} {% ifequal question.answer_count 0 %}unanswered{% endifequal %}{% ifnotequal question.answer_count 0 %}answered{% endifnotequal %}">
-                            <div class="answer-count-post">{{question.answer_count|intcomma}}</div>
-                                                       {% trans "answer" %}
-
-                        </div>
-                        <div class="views">
-                             <div class="views-count-post">{{question.view_count|cnprog_intword|safe}}</div>
-                             {% trans "views" %}
-                        </div>
-                    </div>
-                </a>
-                <div class="bookQuestionItem">
-                    <h3>
-                        <a title="{{question.summary|collapse}}" href="{% url questions %}{{question.id}}/{{question.title}}">{{question.title}}</a>
-                    </h3>
-                    <div class="tags">
-                        {% for tag in question.tagname_list %}
-                        <a href="{% url tag_questions tag|urlencode %}" title="{% "see questions tagged with" %}'{{ tag }}'{% trans "using tags" %}" rel="tag">{{ tag }}</a>
-                        {% endfor %}
-                    </div>
-                    <div class="started">
-                        <span class="author"><a href="{{ question.last_activity_by.get_profile_url }}">{{ question.last_activity_by }}</a></span>
-                        <span class="score">{% get_score_badge question.last_activity_by %} </span>
-                        <span class="date" title="{{ question.last_activity_at }}">{% diff_date question.last_activity_at %}</span>
-                    </div>
-                </div>
-            </div>
-            <br clear="both"/>
-            {% endfor %}
-        </div>
-    </div>
-{% endblock %}
-{% block tail %}
-                        <div class="pager">
-                            {% cnprog_paginator context %}
-                            
-                        </div>
-                        <div class="bookFeed">
-                            <div id="feeds">
-                                <a href="{% media  "/feeds/rss" %} " title="{% trans "subscribe to book RSS feed" %}">{% trans "subscribe to the questions feed" %}</a>
-                            </div>
-                        </div>
-
-{% endblock %}
-<!-- end template book.html -->
index 00bbd51b090bea86002a7356246f14bb4a766e3b..305f62c37ad153f688482ecf223b7af36b3a9114 100644 (file)
                 <div class="tabBar">\r
                     <a name="sort-top"></a>\r
                     <div class="headQuestions">\r
-                    {% blocktrans count answers.count as counter %}\r
+                    {% blocktrans count answers.paginator.count as counter %}\r
                     One Answer:\r
                     {% plural %}\r
                     {{counter}} Answers:\r
                     {% endblocktrans %}\r
                     </div>\r
-                    {{ answers.sort_tabs }}\r
+                    {{ answers.paginator.sort_tabs }}\r
                 </div>\r
-                {{ answers.page_numbers }}\r
+                {{ answers.paginator.page_numbers }}\r
   \r
-                {% for answer in answers.page %}\r
+                {% for answer in answers.paginator.page %}\r
                     <a name="{{ answer.id }}"></a>\r
                     <div id="answer-container-{{ answer.id }}" class="answer {% if answer.nis.accepted %}accepted-answer{% endif %} {% ifequal answer.author_id question.author_id %} answered-by-owner{% endifequal %} {% if answer.nis.deleted %}deleted{% endif %}">\r
                         <table style="width:100%;">\r
                     </div>\r
                 {% endfor %}\r
                 <div class="paginator-container-left">\r
-                    {{ answers.page_numbers }}\r
+                    {{ answers.paginator.page_numbers }}\r
                 </div>\r
             {% endif %}\r
         <form id="fmanswer" action="{% url answer question.id %}" method="post">\r
index c0476d810f47ab678c5f8108694070d5ec0edced..34c81ba42d4854ba074d55a946a1f6eb8e8b0597 100644 (file)
 <div class="tabBar">\r
     {% question_list_title %}\r
     <a class="feed-icon" style="background-image:url('{% media "media/images/feed-icon-small.png" %}');" href="{{ feed_url }}" title="{% trans "subscribe to question RSS feed" %}"></a>\r
-    {{ questions.sort_tabs }}\r
+    {{ questions.paginator.sort_tabs }}\r
 </div>\r
-<div id="listA">{% for question in questions.page %}\r
+<div id="listA">{% for question in questions.paginator.page %}\r
     {% question_list_item question %}\r
 {% endfor %}</div>\r
 {% endblock %}\r
 \r
 {% block tail %}\r
-    <div class="pager">{{ questions.page_numbers }}</div>\r
-    <div class="pagesize">{{ questions.page_sizes }}</div>\r
+    <div class="pager">{{ questions.paginator.page_numbers }}</div>\r
+    <div class="pagesize">{{ questions.paginator.page_sizes }}</div>\r
 {% endblock %}\r
 \r
 {% block sidebar %}\r
@@ -33,7 +33,7 @@
     {% sidebar_upper %}\r
     {% tag_selector %}\r
     {% sidebar_lower %}\r
-    {% question_list_related_tags questions.page %}\r
+    {% question_list_related_tags questions.paginator.page %}\r
 \r
 {% endblock %}\r
 <!-- end questions.html -->\r
index e58fad57cbbdd775b32480d40ff6ecca0211cfad..ec5d88886623b09b664053889c95e19fdea795c1 100644 (file)
 <!-- Tabs -->
 <div class="tabBar">
     <div class="headQuestions">{% trans "Tag list" %}</div>
-    <div class="tabsA">
-        <a id="sort_name" href="{% url tags %}?sort=name" class="off" title="{% trans "sorted alphabetically" %}">{% trans "by name" %}</a>
-        <a id="sort_used" href="{% url tags %}?sort=used" class="off" title="{% trans "sorted by frequency of tag use" %}">{% trans "by popularity" %}</a>
-    </div>
+    {{ tags.paginator.sort_tabs }}
 </div>
 <div id="searchtags">
 <p>
 {% if stag %}
     {% trans "All tags matching query" %} '<span class="darkred"><strong>{{ stag }}</strong></span>':
 {% endif %}
-{% if not tags.object_list %}
+{% if not tags.paginator.count %}
     <span>{% trans "Nothing found" %}</span>
 {% endif %}
 </p>
-{% if tags.object_list %}
+{% if tags.paginator.count %}
 <ul class="tagsList tags">
-{% for tag in tags.object_list %}
+{% for tag in tags.paginator.page %}
    <li>
     <a href="{% url tag_questions tag|urlencode %}" title="{% trans "see questions tagged" %}'{{ tag }}'{% trans "using tags" %}" rel="tag">
         {{ tag }}
@@ -60,7 +57,7 @@
 {% endblock %}
 {% block tail %}
 <div class="pager">
-    {% cnprog_paginator context %}
+    {{ tags.paginator.page_numbers }}
 </div>              
 {% endblock %}
 <!-- end tags.html -->
index 2f08693fdc9e5348944f2300bf933c300e10df35..d7e01dbc8a5c22efeffdbfbaf29227abbca73246 100644 (file)
 {% block content %}
 <div class="tabBar">
     <div class="headUsers">{% trans "Users" %}</div>
-    <div class="tabsA">
-        <a id="sort_reputation" href="{% url users %}?sort=reputation" class="off" title="{% trans "reputation" %}">{% trans "reputation" %}</a>
-        <a id="sort_newest" href="{% url users %}?sort=newest" class="off" title="{% trans "recent" %}">{% trans "recent" %}</a>
-        <a id="sort_last" href="{% url users %}?sort=last" class="off" title="{% trans "oldest" %}">{% trans "oldest" %}</a>
-        <a id="sort_user" href="{% url users %}?sort=user" class="off" title="{% trans "by username" %}">{% trans "by username" %}</a>
-    </div>
+    {{ users.paginator.sort_tabs }}
 </div>
 <div id="main-body" style="width:100%">
     <p>        
                        {% blocktrans %}users matching query {{suser}}:{% endblocktrans %}
         {% endif %}
     
-        {% if not users.object_list %}
+        {% if not users.paginator.count %}
             <span>{% trans "Nothing found." %}</span>
         {% endif %}
     </p>
     <div class="userList">
-        <table class="list-table">
-            <tr>    
-                <td class="list-td">
-                    {% for user in users.object_list %}
-                    
-                    <div class="user">
-                        <ul>
-                            <li class="thumb"><a href="{{ user.get_profile_url }} ">{% gravatar user 32 %}</a></li>
-                            <li><a {% if user.is_suspended %}class="suspended-user" {% endif %}href="{{ user.get_profile_url }}">{{ user.decorated_name }}</a></li>
-                            <li>{% get_score_badge user %}</li>
-                        </ul>
-                    </div>
-                    
-            {% if forloop.counter|divisibleby:"7" %}
-                </td>
-                <td>
-            {% endif %}
-
-                    {% endfor %}
-                </td>
-            </tr>   
-        </table>
+        {% for user in users.paginator.page %}
+        <div class="user">
+            <ul>
+                <li class="thumb"><a href="{{ user.get_profile_url }} ">{% gravatar user 32 %}</a></li>
+                <li><a {% if user.is_suspended %}class="suspended-user" {% endif %}href="{{ user.get_profile_url }}">{{ user.decorated_name }}</a></li>
+                <li>{% get_score_badge user %}</li>
+            </ul>
+        </div>
+        {% endfor %}
     </div>
 </div>
 {% endblock %}
 {% block tail %}
 <div class="pager">
-    {% cnprog_paginator context %}
+    {{ users.paginator.page_numbers }}
 </div>              
 {% endblock %}
 <!-- end users.html -->
index 892f38b981d103d3431c28b114332e3a54816118..302412f93b68f4d0086aff751f72319d5af92e58 100644 (file)
@@ -40,70 +40,6 @@ def gravatar(user, size):
     })
 
 
-LEADING_PAGE_RANGE_DISPLAYED = TRAILING_PAGE_RANGE_DISPLAYED = 5
-LEADING_PAGE_RANGE = TRAILING_PAGE_RANGE = 4
-NUM_PAGES_OUTSIDE_RANGE = 1
-ADJACENT_PAGES = 2
-@register.inclusion_tag("paginator.html")
-def cnprog_paginator(context):
-    """
-    custom paginator tag
-    Inspired from http://blog.localkinegrinds.com/2007/09/06/digg-style-pagination-in-django/
-    """
-    if (context["is_paginated"]):
-        " Initialize variables "
-        in_leading_range = in_trailing_range = False
-        pages_outside_leading_range = pages_outside_trailing_range = range(0)
-
-        if (context["pages"] <= LEADING_PAGE_RANGE_DISPLAYED):
-            in_leading_range = in_trailing_range = True
-            page_numbers = [n for n in range(1, context["pages"] + 1) if n > 0 and n <= context["pages"]]
-        elif (context["page"] <= LEADING_PAGE_RANGE):
-            in_leading_range = True
-            page_numbers = [n for n in range(1, LEADING_PAGE_RANGE_DISPLAYED + 1) if n > 0 and n <= context["pages"]]
-            pages_outside_leading_range = [n + context["pages"] for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)]
-        elif (context["page"] > context["pages"] - TRAILING_PAGE_RANGE):
-            in_trailing_range = True
-            page_numbers = [n for n in range(context["pages"] - TRAILING_PAGE_RANGE_DISPLAYED + 1, context["pages"] + 1)
-                            if n > 0 and n <= context["pages"]]
-            pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)]
-        else:
-            page_numbers = [n for n in range(context["page"] - ADJACENT_PAGES, context["page"] + ADJACENT_PAGES + 1) if
-                            n > 0 and n <= context["pages"]]
-            pages_outside_leading_range = [n + context["pages"] for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)]
-            pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)]
-
-        extend_url = context.get('extend_url', '')
-        return {
-        "base_url": context["base_url"],
-        "is_paginated": context["is_paginated"],
-        "previous": context["previous"],
-        "has_previous": context["has_previous"],
-        "next": context["next"],
-        "has_next": context["has_next"],
-        "page": context["page"],
-        "pages": context["pages"],
-        "page_numbers": page_numbers,
-        "in_leading_range" : in_leading_range,
-        "in_trailing_range" : in_trailing_range,
-        "pages_outside_leading_range": pages_outside_leading_range,
-        "pages_outside_trailing_range": pages_outside_trailing_range,
-        "extend_url" : extend_url
-        }
-
-@register.inclusion_tag("pagesize.html")
-def cnprog_pagesize(context):
-    """
-    display the pagesize selection boxes for paginator
-    """
-    if (context["is_paginated"]):
-        return {
-        "base_url": context["base_url"],
-        "pagesize" : context["pagesize"],
-        "is_paginated": context["is_paginated"]
-        }
-
-
 @register.simple_tag
 def get_score_badge(user):
     if user.is_suspended():
index afadb285ab465e81a3782d2a3bea0ef784aa40bf..3f873ddcafe46d445ad91cd2bb405a8e099e6338 100644 (file)
@@ -171,8 +171,8 @@ def paginated(request, list_name, context, tpl_context):
 
         if hasattr(object_list, 'lazy'):
             return object_list.lazy()
-        return page_obj.object_list
-    objects.page = get_page
+        return object_list
+    paginator.page = get_page()
 
     total_pages = paginator.num_pages
 
@@ -225,9 +225,9 @@ def paginated(request, list_name, context, tpl_context):
                 'current': page,
                 'page_numbers': page_numbers
             }))
-        objects.page_numbers = page_nums
+        paginator.page_numbers = page_nums
     else:
-        objects.page_numbers = ''
+        paginator.page_numbers = ''
 
     if pagesize:
         def page_sizes():
@@ -243,9 +243,9 @@ def paginated(request, list_name, context, tpl_context):
                 'sizes': sizes
             }))
 
-        objects.page_sizes = page_sizes
+        paginator.page_sizes = page_sizes
     else:
-        objects.page_sizes = ''
+        paginator.page_sizes = ''
 
     if sort:
         def sort_tabs():
@@ -257,10 +257,11 @@ def paginated(request, list_name, context, tpl_context):
                 'sorts': sorts,
                 'sticky': session_prefs.get('sticky_sort', False)
             }))
-        objects.sort_tabs = sort_tabs()
+        paginator.sort_tabs = sort_tabs()
     else:
-        objects.sort_tabs = ''
+        paginator.sort_tabs = ''
 
     request.session['paginator_%s' % context.id] = session_prefs
+    objects.paginator = paginator
     tpl_context[list_name] = objects
     return tpl_context
\ No newline at end of file
index d86a62eee838e1d2bd639bb608a4168de6da124c..2219f98174a36b4721c46f2676ac33b3145c51a0 100644 (file)
@@ -10,7 +10,7 @@ import logging
 \r
 def render(template=None, tab=None, tab_title='', weight=500, tabbed=True):\r
     def decorator(func):\r
-        def decorated(request, *args, **kwargs):\r
+        def decorated(func, request, *args, **kwargs):\r
             context = func(request, *args, **kwargs)\r
 \r
             if isinstance(context, HttpResponse):\r
@@ -26,7 +26,7 @@ def render(template=None, tab=None, tab_title='', weight=500, tabbed=True):
             ui.register(ui.PAGE_TOP_TABS,\r
                         ui.PageTab(tab, tab_title, lambda: reverse(func.__name__), weight=weight))\r
             \r
-        return decorated\r
+        return decorate.withfn(decorated)(func)\r
 \r
     return decorator\r
 \r
index 9420ce059820e1b6a7f862c938c41033cf281561..999d320c86cc9d60db6d67173ca639441a11888e 100644 (file)
@@ -31,18 +31,6 @@ from forum.http_responses import HttpResponseUnauthorized
 from forum.feed import RssQuestionFeed
 import decorators
 
-# used in index page
-#refactor - move these numbers somewhere?
-INDEX_PAGE_SIZE = 30
-INDEX_AWARD_SIZE = 15
-INDEX_TAGS_SIZE = 25
-# used in tags list
-DEFAULT_PAGE_SIZE = 60
-# used in questions
-QUESTIONS_PAGE_SIZE = 30
-# used in answers
-ANSWERS_PAGE_SIZE = 10
-
 class QuestionListPaginatorContext(pagination.PaginatorContext):
     def __init__(self):
         super (QuestionListPaginatorContext, self).__init__('QUESTIONS_LIST', sort_methods=(
@@ -66,6 +54,13 @@ class AnswerPaginatorContext(pagination.PaginatorContext):
             (_('newest'), AnswerSort(_('newest answers'), '-added_at', _("newest answers will be shown first"))),
             (_('votes'), AnswerSort(_('popular answers'), '-score', _("most voted answers will be shown first"))),
         ), default_sort=_('votes'), sticky_sort = True, pagesizes=(5, 10, 20))
+
+class TagPaginatorContext(pagination.PaginatorContext):
+    def __init__(self):
+        super (TagPaginatorContext, self).__init__('TAG_LIST', sort_methods=(
+            (_('name'), pagination.SimpleSort(_('by name'), 'name', _("sorted alphabetically"))),
+            (_('used'), pagination.SimpleSort(_('by popularity'), '-used_count', _("sorted by frequency of tag use"))),
+        ), default_sort=_('used'), pagesizes=(30, 60, 120))
     
 
 def feed(request):
@@ -221,44 +216,18 @@ def question_search(request, keywords):
 @decorators.render('tags.html', 'tags', _('tags'), weight=100)
 def tags(request):
     stag = ""
-    is_paginated = True
-    sortby = request.GET.get('sort', 'used')
-    try:
-        page = int(request.GET.get('page', '1'))
-    except ValueError:
-        page = 1
+    tags = Tag.active.all()
 
     if request.method == "GET":
         stag = request.GET.get("q", "").strip()
-        if stag != '':
-            objects_list = Paginator(Tag.active.filter(name__contains=stag), DEFAULT_PAGE_SIZE)
-        else:
-            if sortby == "name":
-                objects_list = Paginator(Tag.active.order_by("name"), DEFAULT_PAGE_SIZE)
-            else:
-                objects_list = Paginator(Tag.active.order_by("-used_count"), DEFAULT_PAGE_SIZE)
-
-    try:
-        tags = objects_list.page(page)
-    except (EmptyPage, InvalidPage):
-        tags = objects_list.page(objects_list.num_pages)
+        if stag:
+            tags = tags.filter(name__contains=stag)
 
-    return {
+    return pagination.paginated(request, 'tags', TagPaginatorContext(), {
         "tags" : tags,
         "stag" : stag,
-        "tab_id" : sortby,
-        "keywords" : stag,
-        "context" : {
-            'is_paginated' : is_paginated,
-            'pages': objects_list.num_pages,
-            'page': page,
-            'has_previous': tags.has_previous(),
-            'has_next': tags.has_next(),
-            'previous': tags.previous_page_number(),
-            'next': tags.next_page_number(),
-            'base_url' : reverse('tags') + '?sort=%s&' % sortby
-        }
-    }
+        "keywords" : stag
+    })
 
 def update_question_view_times(request, question):
     if not 'last_seen_in_question' in request.session:
index 2bda26368c419bf75cd5f64a66bcb257ed8ddef0..9cac193ff0625591602fe083d65d89c443a13fb5 100644 (file)
@@ -21,60 +21,38 @@ from datetime import datetime, date
 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