diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-04-25 22:06:41 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-04-25 22:06:41 -0400 |
commit | b687846b99efda0ef69fb73084d3f64d5b6ddcb1 (patch) | |
tree | 0960c1e2135fddc45ee72fe424d24ea261ebb858 /forum | |
parent | f7c685c68c503119b4ff7541a06337613bfce137 (diff) | |
download | askbot-b687846b99efda0ef69fb73084d3f64d5b6ddcb1.tar.gz askbot-b687846b99efda0ef69fb73084d3f64d5b6ddcb1.tar.bz2 askbot-b687846b99efda0ef69fb73084d3f64d5b6ddcb1.zip |
page size selector works again - some changes in templates
Diffstat (limited to 'forum')
-rwxr-xr-x | forum/const.py | 2 | ||||
-rw-r--r-- | forum/documentation/scratch | 4 | ||||
-rwxr-xr-x | forum/forms.py | 6 | ||||
-rwxr-xr-x | forum/middleware/pagesize.py | 28 | ||||
-rw-r--r-- | forum/skins/default/templates/index.html | 98 | ||||
-rw-r--r-- | forum/skins/default/templates/index_.html | 125 | ||||
-rw-r--r-- | forum/skins/default/templates/pagesize.html | 12 | ||||
-rw-r--r-- | forum/skins/default/templates/paginator.html | 4 | ||||
-rwxr-xr-x | forum/templatetags/extra_tags.py | 2 | ||||
-rw-r--r-- | forum/views/readers.py | 2 |
10 files changed, 34 insertions, 249 deletions
diff --git a/forum/const.py b/forum/const.py index bc9a7a8f..a3ab2a47 100755 --- a/forum/const.py +++ b/forum/const.py @@ -55,7 +55,7 @@ POST_SCOPE_LIST = ( ) DEFAULT_POST_SCOPE = 'all' DEFAULT_QUESTIONS_PAGE_SIZE = 30 -PAGE_SIZES = (10,30,50) +PAGE_SIZE_CHOICES = (('10','10',),('30','30',),('50','50',),) UNANSWERED_MEANING_LIST = ('NO_ANSWERS','NO_UPVOTED_ANSWERS','NO_ACCEPTED_ANSWERS') UNANSWERED_MEANING = 'NO_ACCEPTED_ANSWERS' diff --git a/forum/documentation/scratch b/forum/documentation/scratch index d63b1f50..ca4e67e9 100644 --- a/forum/documentation/scratch +++ b/forum/documentation/scratch @@ -1,3 +1,7 @@ Error upon restarting Apache: Name duplicates previous WSGI daemon definition + +different keys - empty space counts for translation keys +{% blocktrans %}page number {{num}} {% endblocktrans %} +{% blocktrans %}page number {{num}}{% endblocktrans %} diff --git a/forum/forms.py b/forum/forms.py index 4139abb8..e0452d82 100755 --- a/forum/forms.py +++ b/forum/forms.py @@ -139,7 +139,7 @@ class AdvancedSearchForm(forms.Form): start_over = forms.BooleanField(required=False) tags = forms.CharField(max_length=256,required=False) author = forms.IntegerField(required=False) - page_size = forms.ChoiceField(choices=const.PAGE_SIZES, required=False) + page_size = forms.ChoiceField(choices=const.PAGE_SIZE_CHOICES, required=False) page = forms.IntegerField(required=False) def clean_tags(self): @@ -170,6 +170,10 @@ class AdvancedSearchForm(forms.Form): if 'page_size' in self.cleaned_data: if self.cleaned_data['page_size'] == '': self.cleaned_data['page_size'] = None + else: + page_size = self.cleaned_data['page_size'] + #by this time it is guaranteed to be castable as int + self.cleaned_data['page_size'] = int(page_size) return self.cleaned_data['page_size'] def clean(self): diff --git a/forum/middleware/pagesize.py b/forum/middleware/pagesize.py index f6e6fcfd..486193dc 100755 --- a/forum/middleware/pagesize.py +++ b/forum/middleware/pagesize.py @@ -3,30 +3,30 @@ QUESTIONS_PAGE_SIZE = 10 class QuestionsPageSizeMiddleware(object): def process_request(self, request): # Set flag to False by default. If it is equal to True, then need to be saved. - pagesize_changed = False - # get pagesize from session, if failed then get default value - user_page_size = request.session.get("pagesize", QUESTIONS_PAGE_SIZE) - # set pagesize equal to logon user specified value in database + page_size_changed = False + # get page_size from session, if failed then get default value + user_page_size = request.session.get("page_size", QUESTIONS_PAGE_SIZE) + # set page_size equal to logon user specified value in database if request.user.is_authenticated() and request.user.questions_per_page > 0: user_page_size = request.user.questions_per_page try: - # get new pagesize from UI selection - pagesize = int(request.GET.get('pagesize', user_page_size)) - if pagesize <> user_page_size: - pagesize_changed = True + # get new page_size from UI selection + page_size = int(request.GET.get('page_size', user_page_size)) + if page_size <> user_page_size: + page_size_changed = True except ValueError: - pagesize = user_page_size + page_size = user_page_size - # save this pagesize to user database - if pagesize_changed: + # save this page_size to user database + if page_size_changed: if request.user.is_authenticated(): user = request.user - user.questions_per_page = pagesize + user.questions_per_page = page_size user.save() - # put pagesize into session - request.session["pagesize"] = pagesize + # put page_size into session + request.session["page_size"] = page_size def process_exception(self,request,exception): import logging diff --git a/forum/skins/default/templates/index.html b/forum/skins/default/templates/index.html deleted file mode 100644 index f94f84fc..00000000 --- a/forum/skins/default/templates/index.html +++ /dev/null @@ -1,98 +0,0 @@ -{% extends "base.html" %}
-<!-- index.html -->
-{% load i18n %}
-{% load extra_tags %}
-{% load humanize %}
-{% load extra_filters %}
-{% load smart_if %}
-{% load cache %}
-{% block title %}{% spaceless %}{% trans "Home" %}{% endspaceless %}{% endblock %}
-{% block meta %}<meta name="keywords" content="{{ settings.APP_KEYWORDS }}" />
- <meta name="description" content="{{ settings.APP_DESCRIPTION }}" />{% endblock %}
-{% block forejs %}
- <script type="text/javascript">
- var tags = {{ tags_autocomplete|safe }};
- $().ready(function(){
- var tab_id = "{{ tab_id }}";
- $("#"+tab_id).attr('className',"on");
- $("#nav_questions").attr('className',"on");
- });
- </script>
- <script type='text/javascript' src='{% media "/media/js/com.cnprog.editor.js" %}'></script>
- <script type='text/javascript' src='{% media "/media/js/com.cnprog.tag_selector.js" %}'></script>
-{% endblock %}
-{% block content %}
-<div class="tabBar">
- <div class="headUsers">{% trans "Questions" %}</div>
- <div class="tabsA">
- <a id="latest" href="{% url questions %}?sort=latest" title="{% trans "last updated questions" %}" >{% trans "newest" %}</a>
- <a id="hottest" href="{% url questions %}?sort=hottest" title="{% trans "hottest questions" %}" >{% trans "hottest" %}</a>
- <a id="mostvoted" href="{% url questions %}?sort=mostvoted" title="{% trans "most voted questions" %}" >{% trans "most voted" %}</a>
- <a id="all" href="{% url questions %}" title="{% trans "all questions" %}" >{% trans "all questions" %}</a>
- </div>
-</div>
-<!-- ???? -->
-<div id="listA">
-{% include "question_list.html" %}
-</div>
-{% endblock %}
-
-{% block sidebar %}
-{% if not request.user.is_authenticated %}
-<div class="boxA">
- <h3>{% trans "welcome to website" %}</h3>
- <div class="body">
- {{ settings.APP_INTRO|safe }}
- <div class="more"><a href="{% url about %}">{% trans "about" %} </a></div>
- <div class="more"><a href="{% url faq %}">{% trans "faq" %} </a></div>
- </div>
-</div>
-{% else %}
-{% include "tag_selector.html" %}
-{% endif %}
-<div class="boxC">
- <h3>{% trans "Recent tags" %}</h3>
- <div class="body">
- <div class="tags">
- {% cache 60 recent_tags %}
- {% for tag in tags %}
- <a rel="tag"
- title="{% blocktrans with tag.name as tagname %}see questions tagged '{{tagname}}'{% endblocktrans %}"
- href="{% url questions %}?tags={{tag.name|urlencode}}">{{ tag.name }}</a>
- {% endfor %}
- {% endcache %}
- </div>
- <div class="more"><a href="{% url tags %}">{% trans "see all tags" %}</a> </div>
- </div>
-</div>
-{% if awards %}
-<div class="boxC">
- <h3>{% trans "Recent awards" %}</h3>
- <div class="body">
- <ul class="badge-list">
- {% cache 60 recent_awards %}
- {% for award in awards %}
- <li>
- <a href="{% url badges %}{{award.badge_id}}/{{award.badge_name}}" title="{{ award.badge_description }}" class="medal">
- <span class="badge{{ award.badge_type }}">●</span> {{ award.badge_name }}</a>
- <a href="{% url user_profile award.user_id award.user_name|slugify %}">{{ award.user_name }}</a>
- </li>
- {% endfor %}
- {% endcache %}
- </ul>
- <div class="more"><a href="{% url badges %}">{% trans "all awards" %} </a> </div>
- </div>
-</div>
-{% endif %}
-<div id="feeds">
-<a href="{% url latest_questions_feed %}" title="{% trans "subscribe to last 30 questions by RSS" %}">{% trans "subscribe to the questions feed" %}</a>
-</div>
-{% endblock %}
-{% block tail %}
-<div class="pager">{% cnprog_paginator context %}</div>
- <div class="pagesize">{% cnprog_pagesize context %}</div>
-<!-- <div style="padding:5px 0 5px 5px;">
-<span class="evenMore">{% trans "Still looking for more? See" %} <a href="{% url questions %}">{% trans "complete list of questions" %}</a> {% trans "or" %} <a href="{% url tags %}">{% trans "popular tags" %}</a>{% trans "." %} {% trans "Please help us answer" %} <a href="{% url questions %}unanswered">{% trans "list of unanswered questions" %}</a>{% trans "." %}</span>
-</div> -->
-{% endblock %}
-<!-- index.html -->
diff --git a/forum/skins/default/templates/index_.html b/forum/skins/default/templates/index_.html deleted file mode 100644 index 36531f62..00000000 --- a/forum/skins/default/templates/index_.html +++ /dev/null @@ -1,125 +0,0 @@ -{% extends "base.html" %}
-<!-- index.html -->
-{% load i18n %}
-{% load extra_tags %}
-{% load humanize %}
-{% load extra_filters %}
-{% load smart_if %}
-{% block title %}{% spaceless %}{% trans "Home" %}{% endspaceless %}{% endblock %}
-{% block meta %}<meta name="keywords" content="{{ settings.APP_KEYWORDS }}" />
- <meta name="description" content="{{ settings.APP_DESCRIPTION }}" />{% endblock %}
-{% block forejs %}
- <script type="text/javascript">
- var tags = {{ tags_autocomplete|safe }};
- $().ready(function(){
- var tab_id = "{{ tab_id }}";
- $("#"+tab_id).attr('className',"on");
- $("#nav_questions").attr('className',"on");
- });
- </script>
- <script type='text/javascript' src='{% media "/media/js/com.cnprog.editor.js" %}'></script>
- <script type='text/javascript' src='{% media "/media/js/com.cnprog.tag_selector.js" %}'></script>
-{% endblock %}
-{% block content %}
-<div class="tabBar">
- <div class="headUsers">{% trans "Questions" %}</div>
- <div class="tabsA">
- <a id="latest" href="{% url index %}?sort=latest" title="{% trans "last updated questions" %}" >{% trans "newest" %}</a>
- <a id="hottest" href="{% url index %}?sort=hottest" title="{% trans "hottest questions" %}" >{% trans "hottest" %}</a>
- <a id="mostvoted" href="{% url index %}?sort=mostvoted" title="{% trans "most voted questions" %}" >{% trans "most voted" %}</a>
- <a id="all" href="{% url index %}" title="{% trans "all questions" %}" >{% trans "all questions" %}</a>
- </div>
-</div>
-
-<div id="listA">
- {% for question in questions.object_list %}
- <div class="short-summary">
- <div class="counts">
- <div class="votes">
- <div class="item-count">{{question.score|intcomma}}</div>
- <div>{% trans "votes" %}</div>
- </div >
- <div {% if question.answer_accepted %}title="{% trans "this 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="item-count">{{question.answer_count|intcomma}}</div>
- <div>{% trans "answers" %}</div>
- </div>
- <div class="views">
- <div class="item-count">{{question.view_count|cnprog_intword|safe}}</div>
- <div>{% trans "views" %}</div>
- </div>
- </div>
-
- <h2><a title="{{question.summary}}" href="{% url question id=question.id %}{{question.title|slugify}}">{{question.title}}</a></h2>
-
- <div class="userinfo">
- <span class="relativetime" title="{{question.last_activity_at}}">{% diff_date question.last_activity_at %}</span>
- {% if question.last_activity_by %}
- <a href="{{ question.last_activity_by.get_profile_url }}">{{ question.last_activity_by }}</a> {% get_score_badge question.last_activity_by %}
- {% endif %}
- </div>
-
- <div class="tags">
- {% for tag in question.tagname_list %}
- <a href="{% url questions %}?tags={{tag|urlencode}}" title="{% blocktrans %}see questions tagged '{{ tag }}'{% endblocktrans %}" rel="tag">{{ tag }}</a>
- {% endfor %}
- </div>
- </div>
- {% endfor %}
-</div>
-{% endblock %}
-
-{% block sidebar %}
-{% if not request.user.is_authenticated %}
-<div class="boxA">
- <h3>{% trans "welcome to website" %}</h3>
- <div class="body">
- {{ settings.APP_INTRO|safe }}
- <div class="more"><a href="{% url about %}">{% trans "about" %} »</a></div>
- <div class="more"><a href="{% url faq %}">{% trans "faq" %} »</a></div>
- </div>
-</div>
-{% else %}
-{% include "tag_selector.html" %}
-{% endif %}
-<div class="boxC">
- <h3>{% trans "Recent tags" %}</h3>
- <div class="body">
- <div class="tags">
- {% for tag in tags %}
- <a rel="tag"
- title="{% blocktrans with tag.name as tagname %}see questions tagged '{{tagname}}'{% endblocktrans %}"
- href="{% url questions %}?tags={{tag.name|urlencode}}">{{ tag.name }}</a>
- {% endfor %}
- </div>
- <div class="more"><a href="{% url tags %}">{% trans "popular tags" %} »</a> </div>
- </div>
-</div>
-{% if awards %}
-<div class="boxC">
- <h3>{% trans "Recent awards" %}</h3>
- <div class="body">
- <ul class="badge-list">
- {% for award in awards %}
- <li>
- <a href="{% url badges %}{{award.badge_id}}/{{award.badge_name}}" title="{{ award.badge_description }}" class="medal">
- <span class="badge{{ award.badge_type }}">●</span> {{ award.badge_name }}</a>
- <a href="{% url users %}{{award.user_id}}/{{award.user_name}}">{{ award.user_name }}</a>
- </li>
- {% endfor %}
- </ul>
- <div class="more"><a href="{% url badges %}">{% trans "all awards" %} »</a> </div>
- </div>
-</div>
-{% endif %}
-<div id="feeds">
-<a href="{% media "/feeds/rss" %}" title="{% trans "subscribe to last 30 questions by RSS" %}">{% trans "subscribe to the questions feed" %}</a>
-</div>
-{% endblock %}
-{% block tail %}
-<div class="pager">{% cnprog_paginator context %}</div>
- <div class="pagesize">{% cnprog_pagesize context %}</div>
-<!-- <div style="padding:5px 0 5px 5px;">
-<span class="evenMore">{% trans "Still looking for more? See" %} <a href="{% url questions %}">{% trans "complete list of questions" %}</a> {% trans "or" %} <a href="{% url tags %}">{% trans "popular tags" %}</a>{% trans "." %} {% trans "Please help us answer" %} <a href="{% url questions %}unanswered">{% trans "list of unanswered questions" %}</a>{% trans "." %}</span>
-</div> -->
-{% endblock %}
-<!-- index.html -->
diff --git a/forum/skins/default/templates/pagesize.html b/forum/skins/default/templates/pagesize.html index 5037f1f6..5fb28e20 100644 --- a/forum/skins/default/templates/pagesize.html +++ b/forum/skins/default/templates/pagesize.html @@ -4,22 +4,22 @@ {% if is_paginated %} <div class="paginator"> <span class="text">{% trans "posts per page" %}</span> - {% ifequal pagesize 10 %} + {% ifequal page_size 10 %} <span class="curr">10</span> {% else %} - <span class="page"><a href="{{base_url}}pagesize=10">10</a></span> + <span class="page"><a href="{{base_url}}page_size=10">10</a></span> {% endifequal %} - {% ifequal pagesize 30 %} + {% ifequal page_size 30 %} <span class="curr">30</span> {% else %} - <span class="page"><a href="{{base_url}}pagesize=30">30</a></span> + <span class="page"><a href="{{base_url}}page_size=30">30</a></span> {% endifequal %} - {% ifequal pagesize 50 %} + {% ifequal page_size 50 %} <span class="curr">50</span> {% else %} - <span class="page"><a href="{{base_url}}pagesize=50">50</a></span> + <span class="page"><a href="{{base_url}}page_size=50">50</a></span> {% endifequal %} </div> {% endif %} diff --git a/forum/skins/default/templates/paginator.html b/forum/skins/default/templates/paginator.html index 2fba5425..4c1f55b0 100644 --- a/forum/skins/default/templates/paginator.html +++ b/forum/skins/default/templates/paginator.html @@ -19,14 +19,14 @@ <span class="curr" title="{% trans "current page" %}">{{ num }}</span> {% endifequal %} {% else %} - <span class="page"><a href="{{base_url}}page={{ num }}{{ extend_url }}" title="{% trans "page number " %}{{ num }}{% trans "number - make blank in english" %}">{{ num }}</a></span> + <span class="page"><a href="{{base_url}}page={{ num }}{{ extend_url }}" title="{% blocktrans %}page number {{num}}{% endblocktrans %}">{{ num }}</a></span> {% endifequal %} {% endfor %} {% if not in_trailing_range %} ... {% for num in pages_outside_leading_range reversed %} - <span class="page"><a href="{{base_url}}page={{ num }}{{ extend_url }}" title="{% trans "page number " %}{{ num }}{% trans "number - make blank in english" %}">{{ num }}</a></span> + <span class="page"><a href="{{base_url}}page={{ num }}{{ extend_url }}" title="{% blocktrans %}page number {{ num }}{% endblocktrans %}">{{ num }}</a></span> {% endfor %} {% endif %} diff --git a/forum/templatetags/extra_tags.py b/forum/templatetags/extra_tags.py index 83aeb4c7..22dafe5a 100755 --- a/forum/templatetags/extra_tags.py +++ b/forum/templatetags/extra_tags.py @@ -126,7 +126,7 @@ def cnprog_pagesize(context): if (context["is_paginated"]): return { "base_url": context["base_url"], - "pagesize" : context["pagesize"], + "page_size" : context["page_size"], "is_paginated": context["is_paginated"] } diff --git a/forum/views/readers.py b/forum/views/readers.py index 89a9550b..5b1de34c 100644 --- a/forum/views/readers.py +++ b/forum/views/readers.py @@ -157,7 +157,7 @@ def questions(request):#a view generating listing of questions, used by 'unanswe 'previous': questions.previous_page_number(), 'next': questions.next_page_number(), 'base_url' : request.path + '?sort=%s&' % search_state.sort,#todo in T sort=>sort_method - 'pagesize' : search_state.page_size,#todo in T pagesize -> page_size + 'page_size' : search_state.page_size,#todo in T pagesize -> page_size }}, context_instance=RequestContext(request)) def search(request): #generates listing of questions matching a search query - including tags and just words |