summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRosandra Cuello <rosandra.cuello@gmail.com>2011-11-16 21:49:59 -0400
committerRosandra Cuello <rosandra.cuello@gmail.com>2011-11-16 21:49:59 -0400
commitf40ced58a388b945c255e637e9a63233e8715cd2 (patch)
tree40f6b46689794963da84ed93aedd0f42881a605b
parentc91981b3f7b92e4fb51fd622c0074c57edf6cb42 (diff)
downloadaskbot-f40ced58a388b945c255e637e9a63233e8715cd2.tar.gz
askbot-f40ced58a388b945c255e637e9a63233e8715cd2.tar.bz2
askbot-f40ced58a388b945c255e637e9a63233e8715cd2.zip
Changes to url structure (still missing some parts).
-rw-r--r--askbot/forms.py2
-rw-r--r--askbot/search/state_manager.py29
-rw-r--r--askbot/skins/default/templates/macros.html14
-rw-r--r--askbot/skins/default/templates/main_page/tab_bar.html10
-rw-r--r--askbot/templatetags/extra_filters.py43
-rw-r--r--askbot/urls.py10
-rw-r--r--askbot/views/readers.py39
7 files changed, 109 insertions, 38 deletions
diff --git a/askbot/forms.py b/askbot/forms.py
index 0769f180..982c7e32 100644
--- a/askbot/forms.py
+++ b/askbot/forms.py
@@ -481,6 +481,7 @@ class AdvancedSearchForm(forms.Form):
page = forms.IntegerField(required=False)
def clean_tags(self):
+ #import pdb;pdb.set_trace()
if 'tags' in self.cleaned_data:
tags_input = self.cleaned_data['tags'].strip()
split_re = re.compile(const.TAG_SPLIT_REGEX)
@@ -516,6 +517,7 @@ class AdvancedSearchForm(forms.Form):
def clean(self):
#todo rewrite
+ #import pdb;pdb.set_trace()
data = self.cleaned_data
cleanup_dict(data, 'scope', '')
cleanup_dict(data, 'tags', None)
diff --git a/askbot/search/state_manager.py b/askbot/search/state_manager.py
index 761724f0..74cf62a6 100644
--- a/askbot/search/state_manager.py
+++ b/askbot/search/state_manager.py
@@ -296,18 +296,29 @@ class SearchState(object):
self.scope = const.DEFAULT_POST_SCOPE
def query_string(self):
- out = 'scope=%s' % self.scope
- out += '&sort=%s' % self.sort
+ out = 'section:%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'
+ out += '/query:%s' % '+'.join(self.query.split(' '))
+ #import pdb; pdb.set_trace()
if self.tags:
- for tag in self.tags:
- out += '&tags=%s' % tag
+ out += '/tags:%s' % '+'.join(self.tags)
+ if self.author:
+ out += '/author:%s' % self.author
#out += '&page=%d' % self.page
- return '?'+out
+ return out+'/'
+
+ def make_parameters(self):
+ #import pdb; pdb.set_trace()
+ params_dict = {
+ 'scope': self.scope,
+ 'sort': self.sort,
+ 'query': '+'.join(self.query.split(' ')) if self.query else None,
+ 'tags': '+'.join(self.tags) if self.tags else None,
+ 'author': self.author,
+ 'page_size': self.page_size
+ }
+ return params_dict
class ViewLog(object):
"""The ViewLog helper obejcts store the trail of the page visits for a
diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html
index f6cab5ce..432e6c4c 100644
--- a/askbot/skins/default/templates/macros.html
+++ b/askbot/skins/default/templates/macros.html
@@ -370,13 +370,7 @@ 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 %}{{
- if_else(
- url_params != None,
- url_params,
- '?'
- )|escape
- }}{{url_params|add_tag_to_url("tags="+tag|urlencode)}}"
+ href="{% url questions %}{{url_params|add_tag_to_url(tag|urlencode)}}"
title="{% trans %}see questions tagged '{{ tag }}'{% endtrans %}"
{% endif %}
rel="tag"
@@ -599,17 +593,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={{ query_string|replace_in_url("sort="+key_name+"-desc") }}
+ href={% url questions %}{{ 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={{ query_string|replace_in_url("sort="+key_name+"-asc") }}
+ href={% url questions %}{{ 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={{ query_string|replace_in_url("sort="+key_name+"-desc") }}
+ href={% url questions %}{{ 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/tab_bar.html b/askbot/skins/default/templates/main_page/tab_bar.html
index e499ad29..03146171 100644
--- a/askbot/skins/default/templates/main_page/tab_bar.html
+++ b/askbot/skins/default/templates/main_page/tab_bar.html
@@ -6,18 +6,18 @@
<span class="label">{% trans %}In:{% endtrans %}</span>
<a id="all"
class="{% if scope == 'all' %}on{% else %}off{% endif %}"
- href="{{ query_string|replace_in_url("scope=all") }}"
+ href="{% url questions %}{{ query_string|replace_in_url("section: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="{{ query_string|replace_in_url("scope=unanswered")|replace_in_url("sort=answers-asc") }}"
+ href="{% url questions %}{{ query_string|replace_in_url("section:unanswered")|replace_in_url("sort:answers-asc") }}"
title="{% trans %}see unanswered questions{% endtrans %}"
><span>{% trans %}unanswered{% endtrans %}</span></a>
{% if request.user.is_authenticated() %}
<a id="favorite"
class="{% if scope == 'favorite' %}on{% else %}off{% endif %}"
- href="?scope=favorite"
+ href="{% url questions %}{{ query_string|replace_in_url("section:favorite") }}"
title="{% trans %}see your followed questions{% endtrans %}"
><span>{% trans %}followed{% endtrans %}</span></a>
{% endif %}
@@ -31,11 +31,11 @@
{% if query %}
<a id="by_relevance"
{% if sort == "relevance-desc" %}
- href={{ query_string|replace_in_url("sort=relevance-desc") }}
+ href="{% url questions %}{{ query_string|replace_in_url("sort:relevance-desc") }}"
class="on"
title="{{asc_relevance_tooltip}}"><span>{{relevance_label}} &#9660;</span>
{% else %}
- href="?sort=relevance-desc"
+ href="{% url questions %}{{ query_string|replace_in_url("sort:relevance-desc") }}"
class="off"
title="{{desc_relevance_tooltip}}"><span>{{relevance_label}}</span>
{% endif %}
diff --git a/askbot/templatetags/extra_filters.py b/askbot/templatetags/extra_filters.py
index 81776c6c..b6dee686 100644
--- a/askbot/templatetags/extra_filters.py
+++ b/askbot/templatetags/extra_filters.py
@@ -160,25 +160,44 @@ def absolute_value(number):
@register.filter
def replace_in_url(query_string, param):
- type, value = param.split('=')
- params = query_string.lstrip('?').split('&')
+ try:
+ type, value = param.split(':')
+ params = query_string.rstrip('/').split('/')
+
+ for p in params:
+ if type in p:
+ params[params.index(p)] = param
+
+ query_string = '/'.join(params)+'/'
+ except:
+ type, value = param.split('=')
+ params = query_string.lstrip('?').split('&')
- for p in params:
- if type in p:
- params[params.index(p)] = param
+ for p in params:
+ if type in p:
+ params[params.index(p)] = param
- query_string = "?"+'&'.join(params)
+ 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('&')
-
+ params = query_string.rstrip('/').split('/')
+ flag = False
for p in params:
- if param in p:
- return ''
-
- return '&'+param
+ if p.startswith('tags:'):
+ flag = True
+ type, value = p.split(':')
+ values = value.split('+')
+ if param in values:
+ return query_string
+ else:
+ values.append(param)
+ params[params.index(p)] = 'tags:'+'+'.join(values)
+ if not flag:
+ params.append('tags:'+param)
+ query_string = '/'.join(params)+'/'
+ return query_string
diff --git a/askbot/urls.py b/askbot/urls.py
index 8c1e3c3a..60a955f7 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -65,6 +65,16 @@ urlpatterns = patterns('',
name='answer_revisions'
),
url(#this url works both normally and through ajax
+ r'^%s/section:(?P<scope>\w+)/sort:(?P<sort>[\w\-]+)/tags:(?P<tags>[\w\-\+]+)/$' % _('questions'),
+ views.readers.questions,
+ name='questions'
+ ),
+ url(#this url works both normally and through ajax
+ r'^%s/section:(?P<scope>\w+)/sort:(?P<sort>[\w\-]+)/$' % _('questions'),
+ views.readers.questions,
+ name='questions'
+ ),
+ url(#this url works both normally and through ajax
r'^%s$' % _('questions/'),
views.readers.questions,
name='questions'
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index 091c3266..c5a289ed 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -62,18 +62,50 @@ def index(request):#generates front page - shows listing of questions sorted in
"""
return HttpResponseRedirect(reverse('questions'))
-def questions(request):
+def questions(request, scope=const.DEFAULT_POST_SCOPE, sort=const.DEFAULT_POST_SORT_METHOD, query=None, \
+ search=None, tags=None, author=None, page=None, reset_tags=None, \
+ reset_author=None, reset_query=None, start_over=None, \
+ remove_tag=None, page_size=None):
"""
List of Questions, Tagged questions, and Unanswered questions.
matching search query or user selection
"""
+ #make parameters dictionary
+ params_dict = {
+ 'scope': scope,
+ 'sort': sort,
+ }
+ if query:
+ params_dict['query'] = ' '.join(query.split('+'))
+ if search:
+ params_dict['search'] = search
+ if tags:
+ params_dict['tags'] = ' '.join(tags.split('+'))
+ if author:
+ params_dict['author'] = author
+ if page:
+ params_dict['page'] = page
+ if reset_tags:
+ params_dict['reset_tags'] = reset_tags
+ if reset_author:
+ params_dict['reset_author'] = reset_author
+ if reset_query:
+ params_dict['reset_query'] = reset_query
+ if start_over:
+ params_dict['start_over'] = start_over
+ if remove_tag:
+ params_dict['remove_tag'] = remove_tag
+ if page_size:
+ params_dict['page_size'] = page_size
+
#before = datetime.datetime.now()
#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)
+ #form = AdvancedSearchForm(request.GET)
+ form = AdvancedSearchForm(params_dict)
if form.is_valid():
user_input = form.cleaned_data
else:
@@ -121,6 +153,7 @@ def questions(request):
'next': page.next_page_number(),
'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
+ 'parameters': search_state.make_parameters(),
}
if request.is_ajax():
@@ -170,6 +203,7 @@ def questions(request):
'related_tags': list(),
'faces': list(),
'query_string': search_state.query_string(),
+ 'parameters': search_state.make_parameters(),
}
badge_levels = dict(const.BADGE_TYPE_CHOICES)
@@ -309,6 +343,7 @@ def questions(request):
'tag_filter_strategy_choices': const.TAG_FILTER_STRATEGY_CHOICES,
'update_avatar_data': schedules.should_update_avatar_data(request),
'query_string': search_state.query_string(),
+ 'parameters': search_state.make_parameters(),
}
assert(request.is_ajax() == False)