From f40ced58a388b945c255e637e9a63233e8715cd2 Mon Sep 17 00:00:00 2001 From: Rosandra Cuello Date: Wed, 16 Nov 2011 21:49:59 -0400 Subject: Changes to url structure (still missing some parts). --- askbot/forms.py | 2 + askbot/search/state_manager.py | 29 ++++++++++----- askbot/skins/default/templates/macros.html | 14 ++----- .../skins/default/templates/main_page/tab_bar.html | 10 ++--- askbot/templatetags/extra_filters.py | 43 ++++++++++++++++------ askbot/urls.py | 10 +++++ askbot/views/readers.py | 39 +++++++++++++++++++- 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 #} {{label}} ▲ {% elif sort == key_name + "-desc" %}{# "best first" #} {{label}} ▼ {% else %}{# default, when other button is active #} {{label}} {% 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 @@ {% trans %}In:{% endtrans %} {% trans %}all{% endtrans %} {% trans %}unanswered{% endtrans %} {% if request.user.is_authenticated() %} {% trans %}followed{% endtrans %} {% endif %} @@ -31,11 +31,11 @@ {% if query %} {{relevance_label}} ▼ {% else %} - href="?sort=relevance-desc" + href="{% url questions %}{{ query_string|replace_in_url("sort:relevance-desc") }}" class="off" title="{{desc_relevance_tooltip}}">{{relevance_label}} {% 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 @@ -64,6 +64,16 @@ urlpatterns = patterns('', kwargs = {'object_name': 'Answer'}, name='answer_revisions' ), + url(#this url works both normally and through ajax + r'^%s/section:(?P\w+)/sort:(?P[\w\-]+)/tags:(?P[\w\-\+]+)/$' % _('questions'), + views.readers.questions, + name='questions' + ), + url(#this url works both normally and through ajax + r'^%s/section:(?P\w+)/sort:(?P[\w\-]+)/$' % _('questions'), + views.readers.questions, + name='questions' + ), url(#this url works both normally and through ajax r'^%s$' % _('questions/'), views.readers.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) -- cgit v1.2.3-1-g7c22