summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-11 23:06:30 +0100
committerTomasz Zielinski <tomasz.zielinski@pyconsultant.eu>2012-01-11 23:11:23 +0100
commit9ba647898a7f181848d54d1af08ef2a8b211eefc (patch)
tree737574219f240ffa4c5ea53d88f02a3d756f1595
parent2f399da2fd6d353804c1c92c47c5baea552c9817 (diff)
downloadaskbot-9ba647898a7f181848d54d1af08ef2a8b211eefc.tar.gz
askbot-9ba647898a7f181848d54d1af08ef2a8b211eefc.tar.bz2
askbot-9ba647898a7f181848d54d1af08ef2a8b211eefc.zip
Removed some unused code related directly or indirectly to SearchState
-rw-r--r--askbot/middleware/view_log.py57
-rw-r--r--askbot/search/state_manager.py53
-rw-r--r--askbot/skins/default/templates/main_page/javascript.html14
-rw-r--r--askbot/urls.py5
-rw-r--r--askbot/views/readers.py16
5 files changed, 7 insertions, 138 deletions
diff --git a/askbot/middleware/view_log.py b/askbot/middleware/view_log.py
index 0880ae1b..52127148 100644
--- a/askbot/middleware/view_log.py
+++ b/askbot/middleware/view_log.py
@@ -1,33 +1,16 @@
-"""This module records the site visits by the authenticaded
-users and heps maintain the state of the search (for all visitors).
+"""
+This module records the site visits by the authenticated users
Included here is the ViewLogMiddleware
"""
-import logging
import datetime
-from django.conf import settings
-from django.views.static import serve
-from django.views.i18n import javascript_catalog
from askbot.models import signals
-from askbot.views.readers import questions as questions_view
-from askbot.views.commands import vote, get_tag_list
-from askbot.views.writers import delete_comment, post_comments, retag_question
-from askbot.views.readers import revisions, get_question_body
-from askbot.views.meta import media
-from askbot.search.state_manager import ViewLog
-
-#todo: the list is getting bigger and bigger - maybe there is a better way to
-#trigger reset of sarch state?
-IGNORED_VIEWS = (
- serve, vote, media, delete_comment, post_comments,
- retag_question, revisions, javascript_catalog,
- get_tag_list, get_question_body
-)
class ViewLogMiddleware(object):
- """ViewLogMiddleware does two things: tracks visits of pages for the
- stateful site search and sends the site_visited signal
+ """
+ ViewLogMiddleware sends the site_visited signal
+
"""
def process_view(self, request, view_func, view_args, view_kwargs):
#send the site_visited signal for the authenticated users
@@ -36,33 +19,3 @@ class ViewLogMiddleware(object):
user = request.user,
timestamp = datetime.datetime.now()
)
-
- #remaining stuff is for the search state
- if view_func == questions_view:
- view_str = 'questions'
- elif view_func in IGNORED_VIEWS:
- return
- else:
- view_str = view_func.__name__
- if view_str == 'wrap':
- return
-
- if settings.DEBUG == True:
- #todo: dependency!
- try:
- from debug_toolbar.views import debug_media as debug_media_view
- if view_func == debug_media_view:
- return
- except ImportError:
- pass
-
- logging.debug('user %s, view %s' % (request.user.username, view_str))
- logging.debug('next url is %s' % request.REQUEST.get('next','nothing'))
-
- if 'view_log' in request.session:
- view_log = request.session['view_log']
- else:
- view_log = ViewLog()
-
- view_log.set_current(view_str)
- request.session['view_log'] = view_log
diff --git a/askbot/search/state_manager.py b/askbot/search/state_manager.py
index ae5157e3..adb56138 100644
--- a/askbot/search/state_manager.py
+++ b/askbot/search/state_manager.py
@@ -123,14 +123,6 @@ class SearchState(object):
out += 'logged_in=%s\n' % str(self.logged_in)
return out
- def set_logged_out(self):
- if self.scope == 'favorite':
- self.scope = None
- self.logged_in = False
-
- def set_logged_in(self):
- self.logged_in = True
-
def reset(self):
#re-initialize, but keep login state
is_logged_in = self.logged_in
@@ -146,12 +138,6 @@ class SearchState(object):
if reset_page == True:
self.reset_page()
- def relax_stickiness(self, input_dict, view_log):
- if view_log.get_previous(1) == 'questions':
- if not some_in(ACTIVE_COMMANDS, input_dict):
- self.reset()
- #todo also relax if 'all' scope was clicked twice
-
def update_from_user_input(self, input_dict, user_logged_in):
#todo: this function will probably not
#fit the case of multiple parameters entered at the same tiem
@@ -168,8 +154,8 @@ class SearchState(object):
self.reset_page()#todo may be smarter here - start with ~same q
if 'scope' in input_dict:
- if input_dict['scope'] == 'favorite' and user_logged_in is False:
- self.reset_scope()
+ if input_dict['scope'] == 'favorite' and not user_logged_in:
+ self.scope = const.DEFAULT_POST_SCOPE
else:
self.update_value('scope', input_dict, reset_page=reset_page)
@@ -260,8 +246,6 @@ class SearchState(object):
def reset_sort(self):
self.sort = const.DEFAULT_POST_SORT_METHOD
- def reset_scope(self):
- self.scope = const.DEFAULT_POST_SCOPE
def query_string(self):
out = 'section:%s' % self.scope
@@ -284,36 +268,3 @@ class SearchState(object):
'page_size': self.page_size
}
return params_dict
-
-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.
-
- The purpose to record this info is to reset the search state
- when the user walks "too far away" from the search page.
-
- These objects must be modified only in this middlware.
- """
- def __init__(self):
- self.views = []
- self.depth = 3 #todo maybe move this to const.py
-
- def get_previous(self, num):
- """get a previous record from a certain depth"""
- if num > self.depth - 1:
- raise Exception("view log depth exceeded")
- elif num < 0:
- raise Exception("num must be positive")
- elif num <= len(self.views) - 1:
- return self.views[num]
- else:
- return None
-
- def set_current(self, view_name):
- """insert a new record"""
- self.views.insert(0, view_name)
- if len(self.views) > self.depth:
- self.views.pop()
-
- def __str__(self):
- return str(self.views) + ' depth=%d' % self.depth
diff --git a/askbot/skins/default/templates/main_page/javascript.html b/askbot/skins/default/templates/main_page/javascript.html
index 4b668cb4..8e12f0a7 100644
--- a/askbot/skins/default/templates/main_page/javascript.html
+++ b/askbot/skins/default/templates/main_page/javascript.html
@@ -15,20 +15,6 @@
{% endif %}
});
- askbot['data']['questions-titles'] = {};
- function load_question_body(element, question_id){
- var key = 'question-' + question_id;
- if ( askbot['data']['questions-titles'][key] == null){
- $.getJSON('{% url get_question_body %}', function(data){
- askbot['data']['questions-titles'] = data['questions-titles'];
- console.debug(data);
- element.title = askbot['data']['questions-titles'][key];//repeated due to async
- });
- } else {
- element.title = askbot['data']['questions-titles'][key];
- }
- }
-
askbot['urls']['mark_interesting_tag'] = '{% url mark_interesting_tag %}';
askbot['urls']['mark_ignored_tag'] = '{% url mark_ignored_tag %}';
askbot['urls']['unmark_tag'] = '{% url unmark_tag %}';
diff --git a/askbot/urls.py b/askbot/urls.py
index ab2efd01..794660f2 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -154,11 +154,6 @@ urlpatterns = patterns('',
views.readers.get_comment,
name='get_comment'
),
- url(#ajax only
- r'^question/get_body/$',
- views.readers.get_question_body,
- name='get_question_body'
- ),
url(
r'^%s$' % _('tags/'),
views.readers.tags,
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index 85afeaed..72d3f06a 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -626,22 +626,6 @@ def get_comment(request):
request.user.assert_can_edit_comment(comment)
return {'text': comment.text}
-@csrf.csrf_exempt
-@ajax_only
-@get_only
-def get_question_body(request):
- search_state = request.session.get('search_state', SearchState())
- (qs, meta_data, related_tags) = models.Thread.objects.run_advanced_search(
- request_user = request.user,
- search_state = search_state)
- paginator = Paginator(qs, search_state.page_size)
- page = paginator.page(search_state.page)
- questions_dict = {}
- for question in page.object_list:
- questions_dict['question-%s' % question.id] = question.summary
-
- return {'questions-titles': questions_dict}
-
def widget_questions(request):
"""Returns the first x questions based on certain tags.
@returns template with those questions listed."""