summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRosandra Cuello <rosandra.cuello@gmail.com>2011-09-29 17:12:45 -0700
committerRosandra Cuello <rosandra.cuello@gmail.com>2011-09-29 17:12:45 -0700
commit596da522bef06fc7c9b6d7eb84f6aee22e7dab25 (patch)
treef1c2ceb6e66ec03a48792bc8710590b59aab4520
parent8548f2b0bba227ae052d0009ddfc29262b185356 (diff)
downloadaskbot-596da522bef06fc7c9b6d7eb84f6aee22e7dab25.tar.gz
askbot-596da522bef06fc7c9b6d7eb84f6aee22e7dab25.tar.bz2
askbot-596da522bef06fc7c9b6d7eb84f6aee22e7dab25.zip
Basic restfull urls that contain scope/sort/tags/page
-rw-r--r--askbot/search/state_manager.py14
-rw-r--r--askbot/skins/default/templates/macros.html27
-rw-r--r--askbot/skins/default/templates/main_page/content.html2
-rw-r--r--askbot/skins/default/templates/main_page/paginator.html2
-rw-r--r--askbot/skins/default/templates/main_page/sidebar.html7
-rw-r--r--askbot/skins/default/templates/main_page/tab_bar.html23
-rw-r--r--askbot/templatetags/extra_filters.py26
-rw-r--r--askbot/views/readers.py7
8 files changed, 79 insertions, 29 deletions
diff --git a/askbot/search/state_manager.py b/askbot/search/state_manager.py
index d441e33b..761724f0 100644
--- a/askbot/search/state_manager.py
+++ b/askbot/search/state_manager.py
@@ -295,6 +295,20 @@ class SearchState(object):
def reset_scope(self):
self.scope = const.DEFAULT_POST_SCOPE
+ def query_string(self):
+ out = 'scope=%s' % self.scope
+ out += '&sort=%s' % self.sort
+ if self.query:
+ out += '&query=%s' % self.query
+ if hasattr(self, 'search'):
+ if self.search == 'search':
+ out += '&search = search'
+ if self.tags:
+ for tag in self.tags:
+ out += '&tags=%s' % tag
+ #out += '&page=%d' % self.page
+ return '?'+out
+
class ViewLog(object):
"""The ViewLog helper obejcts store the trail of the page visits for a
given user. The trail is recorded only up to a certain depth.
diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html
index 5c035611..f6cab5ce 100644
--- a/askbot/skins/default/templates/macros.html
+++ b/askbot/skins/default/templates/macros.html
@@ -1,3 +1,4 @@
+{% load extra_filters %}
{%- macro user_score_and_badge_summary(user) -%}
<span class="reputation-score"
title="{{user.get_karma_summary}}"
@@ -369,13 +370,13 @@ poor design of the data or methods on data objects #}
<{% if not is_link or tag[-1] == '*' %}span{% else %}a{% endif %}
class="tag tag-right{% if css_class %} {{ css_class }}{% endif %}"
{% if is_link %}
- href="{% url questions %}?tags={{tag|urlencode}}{{
- if_else(
- url_params != None,
- '&' ~ url_params,
- ''
- )|escape
- }}"
+ href="{% url questions %}{{
+ if_else(
+ url_params != None,
+ url_params,
+ '?'
+ )|escape
+ }}{{url_params|add_tag_to_url("tags="+tag|urlencode)}}"
title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}"
{% endif %}
rel="tag"
@@ -410,7 +411,7 @@ poor design of the data or methods on data objects #}
{% endfor %}
{%- endmacro -%}
-{%- macro question_summary(question, extra_class=None) -%}
+{%- macro question_summary(question, extra_class=None, query_string=None) -%}
<div class="short-summary{% if extra_class %} {{extra_class}}{% endif %}" id="question-{{question.id}}">
<div class="counts">
<div class="views
@@ -465,7 +466,7 @@ poor design of the data or methods on data objects #}
</div>
</div>
<h2><a href="{{ question.get_absolute_url() }}" onmouseover="load_question_body(this, {{question.id}})">{{question.get_question_title()|escape}}</a></h2>
- {{ tag_list_widget(question.get_tag_names()) }}
+ {{ tag_list_widget(question.get_tag_names(), url_params=query_string) }}
</div>
{%- endmacro -%}
@@ -585,7 +586,7 @@ for the purposes of the AJAX comment editor #}
{%- endmacro -%}
{%- macro reversible_sort_button(button_sort_criterium=None, asc_tooltip=None,
- desc_tooltip=None, label=None, current_sort_method=None) -%}
+ desc_tooltip=None, label=None, current_sort_method=None, query_string=None) -%}
{#
sort button where descending sort is default
and the search method is togglable between ascending and descending
@@ -598,17 +599,17 @@ for the purposes of the AJAX comment editor #}
{% set sort = current_sort_method %}
{% if sort == key_name + "-asc" %}{# "worst" first #}
<a id="by_{{key_name}}"
- href="?sort={{key_name}}-desc"
+ href={{ query_string|replace_in_url("sort="+key_name+"-desc") }}
class="rev on"
title="{{desc_tooltip}}"><span>{{label}} &#9650;</span></a>
{% elif sort == key_name + "-desc" %}{# "best first" #}
<a id="by_{{key_name}}"
- href="?sort={{key_name}}-asc"
+ href={{ query_string|replace_in_url("sort="+key_name+"-asc") }}
class="rev on"
title="{{asc_tooltip}}"><span>{{label}} &#9660;</span></a>
{% else %}{# default, when other button is active #}
<a id="by_{{key_name}}"
- href="?sort={{key_name}}-desc"
+ href={{ query_string|replace_in_url("sort="+key_name+"-desc") }}
class="off"
title="{{desc_tooltip}}"><span>{{label}}</span></a>
{% endif %}
diff --git a/askbot/skins/default/templates/main_page/content.html b/askbot/skins/default/templates/main_page/content.html
index 72128cdc..55598ff6 100644
--- a/askbot/skins/default/templates/main_page/content.html
+++ b/askbot/skins/default/templates/main_page/content.html
@@ -2,7 +2,7 @@
<div id="question-list">
{% cache 0 "questions" questions search_tags scope sort query context.page context.page_size language_code %}
{% for question in questions.object_list %}
- {{macros.question_summary(question)}}
+ {{macros.question_summary(question, query_string=query_string)}}
{% endfor %}
{% endcache %}
{# comment todo: fix css here #}
diff --git a/askbot/skins/default/templates/main_page/paginator.html b/askbot/skins/default/templates/main_page/paginator.html
index 4a77060f..cf45cc0c 100644
--- a/askbot/skins/default/templates/main_page/paginator.html
+++ b/askbot/skins/default/templates/main_page/paginator.html
@@ -1,5 +1,5 @@
{% import "macros.html" as macros %}
-{% if questions_count > 10 %}{# todo: remove magic number #}
+{% if questions_count > page_size %}{# todo: remove magic number #}
<div id="pager" class="pager">
{{ macros.paginator(context|setup_paginator, position='left') }}
{{ macros.pagesize_switch(context, position='right') }}
diff --git a/askbot/skins/default/templates/main_page/sidebar.html b/askbot/skins/default/templates/main_page/sidebar.html
index 6abc0492..577405d8 100644
--- a/askbot/skins/default/templates/main_page/sidebar.html
+++ b/askbot/skins/default/templates/main_page/sidebar.html
@@ -20,7 +20,7 @@
{% endif %}
{% if tags and settings.SIDEBAR_MAIN_SHOW_TAGS %}
- {% cache 0 "tags" tags search_tags scope sort query context.page context.page_size language_code %}
+ {# cache 0 "tags" tags search_tags scope sort query context.page context.page_size language_code #}
<div class="boxC">
<h2>{% trans %}Related tags{% endtrans %}</h2>
{% if tag_list_type == 'list' %}
@@ -31,7 +31,8 @@
tag.name,
html_tag = 'div',
extra_content = '<span class="tag-number">&#215; ' ~
- tag.local_used_count|intcomma ~ '</span>'
+ tag.local_used_count|intcomma ~ '</span>',
+ url_params = query_string,
)}}
</li>
{% endfor %}
@@ -40,7 +41,7 @@
{{ macros.tag_cloud(tags = tags, font_sizes = font_size) }}
{% endif %}
</div>
- {% endcache %}
+ {# endcache #}
{% endif %}
{{ settings.SIDEBAR_MAIN_FOOTER }}
diff --git a/askbot/skins/default/templates/main_page/tab_bar.html b/askbot/skins/default/templates/main_page/tab_bar.html
index 1b27ab3a..e499ad29 100644
--- a/askbot/skins/default/templates/main_page/tab_bar.html
+++ b/askbot/skins/default/templates/main_page/tab_bar.html
@@ -1,16 +1,17 @@
{% import "macros.html" as macros %}
-{% cache 600 "scope_sort_tabs" search_tags request.user scope sort query context.page context.page_size language_code %}
+{% load extra_filters %}
+{# cache 600 "scope_sort_tabs" search_tags request.user scope sort query context.page context.page_size language_code #}
<div class="tabBar">
<div class="tabsC">
<span class="label">{% trans %}In:{% endtrans %}</span>
<a id="all"
class="{% if scope == 'all' %}on{% else %}off{% endif %}"
- href="?scope=all"
+ href="{{ query_string|replace_in_url("scope=all") }}"
title="{% trans %}see all questions{% endtrans %}"
><span>{% trans %}all{% endtrans %}</span></a>
<a id="unanswered"
class="{% if scope == 'unanswered' %}on{% else %}off{% endif %}"
- href="?scope=unanswered&amp;sort=answers-asc"
+ href="{{ query_string|replace_in_url("scope=unanswered")|replace_in_url("sort=answers-asc") }}"
title="{% trans %}see unanswered questions{% endtrans %}"
><span>{% trans %}unanswered{% endtrans %}</span></a>
{% if request.user.is_authenticated() %}
@@ -30,7 +31,7 @@
{% if query %}
<a id="by_relevance"
{% if sort == "relevance-desc" %}
- href="?sort=relevance-desc"
+ href={{ query_string|replace_in_url("sort=relevance-desc") }}
class="on"
title="{{asc_relevance_tooltip}}"><span>{{relevance_label}} &#9660;</span>
{% else %}
@@ -54,7 +55,8 @@
label = gettext('by date'),
asc_tooltip = gettext('click to see the oldest questions'),
desc_tooltip = gettext('click to see the newest questions'),
- current_sort_method = sort
+ current_sort_method = sort,
+ query_string = query_string,
)
}}
{{macros.reversible_sort_button(
@@ -62,7 +64,8 @@
label = gettext('by activity'),
asc_tooltip = gettext('click to see the least recently updated questions'),
desc_tooltip = gettext('click to see the most recently updated questions'),
- current_sort_method = sort
+ current_sort_method = sort,
+ query_string = query_string,
)
}}
{{macros.reversible_sort_button(
@@ -70,7 +73,8 @@
label = gettext('by answers'),
asc_tooltip = gettext('click to see the least answered questions'),
desc_tooltip = gettext('click to see the most answered questions'),
- current_sort_method = sort
+ current_sort_method = sort,
+ query_string = query_string,
)
}}
{{macros.reversible_sort_button(
@@ -78,9 +82,10 @@
label = gettext('by votes'),
asc_tooltip = gettext('click to see least voted questions'),
desc_tooltip = gettext('click to see most voted questions'),
- current_sort_method = sort
+ current_sort_method = sort,
+ query_string = query_string,
)
}}
</div>
</div>
-{% endcache %}
+{# endcache #}
diff --git a/askbot/templatetags/extra_filters.py b/askbot/templatetags/extra_filters.py
index ffdfd9d8..81776c6c 100644
--- a/askbot/templatetags/extra_filters.py
+++ b/askbot/templatetags/extra_filters.py
@@ -156,3 +156,29 @@ def humanize_counter(number):
@register.filter
def absolute_value(number):
return abs(number)
+
+
+@register.filter
+def replace_in_url(query_string, param):
+ type, value = param.split('=')
+ params = query_string.lstrip('?').split('&')
+
+ for p in params:
+ if type in p:
+ params[params.index(p)] = param
+
+ query_string = "?"+'&'.join(params)
+ return query_string
+
+@register.filter
+def add_tag_to_url(query_string, param):
+ if query_string:
+ params = query_string.lstrip('?').split('&')
+
+ for p in params:
+ if param in p:
+ return ''
+
+ return '&'+param
+
+
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index 1739a4ef..956ad2ed 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -71,7 +71,7 @@ def questions(request):
#don't allow to post to this view
if request.method == 'POST':
raise Http404
-
+ #import pdb; pdb.set_trace()
#update search state
form = AdvancedSearchForm(request.GET)
if form.is_valid():
@@ -119,7 +119,7 @@ def questions(request):
'has_next': page.has_next(),
'previous': page.previous_page_number(),
'next': page.next_page_number(),
- 'base_url' : request.path + '?sort=%s&amp;' % search_state.sort,#todo in T sort=>sort_method
+ 'base_url' : request.path + search_state.query_string() + '&',#todo in T sort=>sort_method
'page_size' : search_state.page_size,#todo in T pagesize -> page_size
}
@@ -280,6 +280,7 @@ def questions(request):
if meta_data.get('author_name',None):
reset_method_count += 1
+ #import pdb; pdb.set_trace()
template_data = {
'active_tab': 'questions',
'author_name' : meta_data.get('author_name',None),
@@ -291,6 +292,7 @@ def questions(request):
'language_code': translation.get_language(),
'name_of_anonymous_user' : models.get_name_of_anonymous_user(),
'page_class': 'main-page',
+ 'page_size': search_state.page_size,
'query': search_state.query,
'questions' : page,
'questions_count' : paginator.count,
@@ -305,6 +307,7 @@ def questions(request):
'font_size' : font_size,
'tag_filter_strategy_choices': const.TAG_FILTER_STRATEGY_CHOICES,
'update_avatar_data': schedules.should_update_avatar_data(request),
+ 'query_string': search_state.query_string(),
}
assert(request.is_ajax() == False)