diff options
-rw-r--r-- | askbot/media/js/live_search.js | 2 | ||||
-rw-r--r-- | askbot/media/js/live_search_new_thread.js | 2 | ||||
-rw-r--r-- | askbot/media/js/utils.js | 5 | ||||
-rw-r--r-- | askbot/templates/embed/ask_by_widget.html | 2 | ||||
-rw-r--r-- | askbot/templates/meta/bottom_scripts.html | 2 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 6 | ||||
-rw-r--r-- | askbot/urls.py | 7 | ||||
-rw-r--r-- | askbot/views/commands.py | 17 |
8 files changed, 24 insertions, 19 deletions
diff --git a/askbot/media/js/live_search.js b/askbot/media/js/live_search.js index 98e01179..1aebb6ce 100644 --- a/askbot/media/js/live_search.js +++ b/askbot/media/js/live_search.js @@ -461,7 +461,7 @@ FullTextSearch.prototype.sendTitleSearchQuery = function(query_text) { var data = {query_text: query_text}; var me = this; $.ajax({ - url: askbot['urls']['titleSearch'], + url: askbot['urls']['apiGetQuestions'], data: data, dataType: 'json', success: function(data, text_status, xhr){ diff --git a/askbot/media/js/live_search_new_thread.js b/askbot/media/js/live_search_new_thread.js index d17951eb..21b5c876 100644 --- a/askbot/media/js/live_search_new_thread.js +++ b/askbot/media/js/live_search_new_thread.js @@ -2,7 +2,7 @@ var liveSearchNewThreadInit = function(auto_focus_out) { var query = $('input#id_title.questionTitleInput'); var prev_text = $.trim(query.val()); - var search_url = askbot['urls']['titleSearch']; + var search_url = askbot['urls']['apiGetQuestions']; var running = false; var q_list_sel = 'question-list'; //id of question listing div diff --git a/askbot/media/js/utils.js b/askbot/media/js/utils.js index db15b656..f2cc0108 100644 --- a/askbot/media/js/utils.js +++ b/askbot/media/js/utils.js @@ -54,6 +54,11 @@ var getSingletonController = function(controllerClass, name) { return controller; }; +var setController = function(controller, name) { + askbot['controllers'] = askbot['controllers'] || {}; + askbot['controllers'][name] = controller; +}; + var getUniqueValues = function(values) { var uniques = new Object(); var out = new Array(); diff --git a/askbot/templates/embed/ask_by_widget.html b/askbot/templates/embed/ask_by_widget.html index 5060301c..0ad03d82 100644 --- a/askbot/templates/embed/ask_by_widget.html +++ b/askbot/templates/embed/ask_by_widget.html @@ -210,7 +210,7 @@ <script type="text/javascript" src='{{"/js/live_search_new_thread.js"|media}}'></script> <script type="text/javascript" charset="utf-8"> askbot['settings']['minSearchWordLength'] = {{ min_search_word_length }}; - askbot['urls']['titleSearch'] = '{% url title_search %}'; + askbot['urls']['apiGetQuestions'] = '{% url "api_get_questions" %}'; askbot['urls']['upload'] = '{% url upload %}'; $(document).ready(function(){ var searchInput = $('#id_title'); diff --git a/askbot/templates/meta/bottom_scripts.html b/askbot/templates/meta/bottom_scripts.html index aa63560f..7af1d50d 100644 --- a/askbot/templates/meta/bottom_scripts.html +++ b/askbot/templates/meta/bottom_scripts.html @@ -22,7 +22,7 @@ askbot['urls']['unfollow_user'] = '/followit/unfollow/user/{{'{{'}}userId{{'}}'}}/'; askbot['urls']['user_signin'] = '{{ settings.LOGIN_URL }}'; askbot['urls']['getEditor'] = '{% url "get_editor" %}'; - askbot['urls']['titleSearch'] = '{% url "title_search" %}'; + askbot['urls']['apiGetQuestions'] = '{% url "api_get_questions" %}'; askbot['urls']['ask'] = '{% url "ask" %}'; askbot['urls']['questions'] = '{% url "questions" %}'; askbot['settings']['groupsEnabled'] = {{ settings.GROUPS_ENABLED|as_js_bool }}; diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 6421ee75..f76d94a2 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -160,7 +160,7 @@ class PageLoadTestCase(AskbotTestCase): @with_settings(GROUPS_ENABLED=False) def test_title_search_groups_disabled(self): data = {'query_text': 'Question'} - response = self.client.get(reverse('title_search'), data) + response = self.client.get(reverse('api_get_questions'), data) data = simplejson.loads(response.content) self.assertTrue(len(data) > 1) @@ -175,13 +175,13 @@ class PageLoadTestCase(AskbotTestCase): #ask for data anonymously - should get nothing query_data = {'query_text': 'alibaba'} - response = self.client.get(reverse('title_search'), query_data) + response = self.client.get(reverse('api_get_questions'), query_data) response_data = simplejson.loads(response.content) self.assertEqual(len(response_data), 0) #log in - should get the question self.client.login(method='force', user_id=user.id) - response = self.client.get(reverse('title_search'), query_data) + response = self.client.get(reverse('api_get_questions'), query_data) response_data = simplejson.loads(response.content) self.assertEqual(len(response_data), 1) diff --git a/askbot/urls.py b/askbot/urls.py index bd0c3a15..a8eebf95 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -67,16 +67,15 @@ urlpatterns = patterns('', r'(%s)?' % r'/author:(?P<author>\d+)' + r'(%s)?' % r'/page:(?P<page>\d+)' + r'/$'), - views.readers.questions, name='questions' ), # END main page urls url( - r'^api/title_search/', - views.commands.title_search, - name='title_search' + r'^api/get_questions/', + views.commands.api_get_questions, + name='api_get_questions' ), url( r'^get-thread-shared-users/', diff --git a/askbot/views/commands.py b/askbot/views/commands.py index 1436d3c8..19a956ef 100644 --- a/askbot/views/commands.py +++ b/askbot/views/commands.py @@ -807,21 +807,22 @@ def delete_bulk_tag_subscription(request): return HttpResponseRedirect(reverse('list_bulk_tag_subscription')) @decorators.get_only -def title_search(request): +def api_get_questions(request): """json api for retrieving questions by title match""" - query = request.GET.get('query_text') - - if query is None: - return HttpResponseBadRequest('Invalid query') - - query = query.strip() + query = request.GET.get('query_text', '').strip() + tag_name = request.GET.get('tag_name', None) if askbot_settings.GROUPS_ENABLED: threads = models.Thread.objects.get_visible(user=request.user) else: threads = models.Thread.objects.all() - threads = threads.get_for_title_query(query) + if tag_name: + threads = threads.filter(tags__name=tag_name) + + if query: + threads = threads.get_for_title_query(query) + #todo: filter out deleted threads, for now there is no way threads = threads.distinct()[:30] |