summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-01-14 22:10:35 -0500
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-01-14 22:10:35 -0500
commit61964ded64a8184b7639bf3b9a804061013f56b9 (patch)
tree2db3cbffd57a6adc492aebc783580e568efcc7cd
parentd1777563360257e6e83cdf08d25a5bef99117f05 (diff)
downloadaskbot-61964ded64a8184b7639bf3b9a804061013f56b9.tar.gz
askbot-61964ded64a8184b7639bf3b9a804061013f56b9.tar.bz2
askbot-61964ded64a8184b7639bf3b9a804061013f56b9.zip
small refactoring - moved ViewLog class definition to the search subsystem, because it is part of the search functionality
-rw-r--r--askbot/middleware/view_log.py35
-rw-r--r--askbot/models/__init__.py2
-rw-r--r--askbot/search/indexer.py9
-rw-r--r--askbot/search/state_manager.py41
-rw-r--r--askbot/views/readers.py6
5 files changed, 45 insertions, 48 deletions
diff --git a/askbot/middleware/view_log.py b/askbot/middleware/view_log.py
index f6077e12..58815f89 100644
--- a/askbot/middleware/view_log.py
+++ b/askbot/middleware/view_log.py
@@ -1,7 +1,7 @@
"""This module records the site visits by the authenticaded
users and heps maintain the state of the search (for all visitors).
-Included here is the ViewLogMiddleware and the helper class ViewLog.
+Included here is the ViewLogMiddleware
"""
import logging
import datetime
@@ -12,44 +12,13 @@ from askbot.views.readers import questions as questions_view
from askbot.views.commands import vote
from askbot.views.writers import delete_comment, post_comments, retag_question
from askbot.views.readers import revisions
+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, delete_comment, post_comments,
retag_question, revisions)
-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
class ViewLogMiddleware(object):
"""ViewLogMiddleware does two things: tracks visits of pages for the
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 1bc42b89..7d8347f0 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -3,7 +3,6 @@ import re
import hashlib
import datetime
from django.core.urlresolvers import reverse
-from askbot.search.indexer import create_fulltext_indexes
from django.db.models import signals as django_signals
from django.template import Context
from django.utils.translation import ugettext as _
@@ -2093,7 +2092,6 @@ signals.post_updated.connect(
sender=Question
)
signals.site_visited.connect(record_user_visit)
-#post_syncdb.connect(create_fulltext_indexes)
#todo: wtf??? what is x=x about?
signals = signals
diff --git a/askbot/search/indexer.py b/askbot/search/indexer.py
deleted file mode 100644
index c7c45c59..00000000
--- a/askbot/search/indexer.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from django.conf import settings
-from django.db import connection
-
-def create_fulltext_indexes():
- if settings.DATABASE_ENGINE == 'mysql':
- cursor = connection.cursor()
- cursor.execute('ALTER TABLE question ADD FULLTEXT (title, text, tagnames)')
- cursor.execute('ALTER TABLE answer ADD FULLTEXT (title, text, tagnames)')
-
diff --git a/askbot/search/state_manager.py b/askbot/search/state_manager.py
index b50a0405..0fcb0031 100644
--- a/askbot/search/state_manager.py
+++ b/askbot/search/state_manager.py
@@ -172,3 +172,44 @@ class SearchState(object):
def reset_scope(self):
self.scope = const.DEFAULT_POST_SCOPE
+
+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 should_reset_search_state(self):
+ """return True if user stepped too far from the home page
+ and False otherwise"""
+ if self.get_previous(1) != 'questions':
+ if self.get_previous(2) != 'questions':
+ return True
+ return False
+
+ 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/views/readers.py b/askbot/views/readers.py
index 4c462081..759c1ddc 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -86,10 +86,8 @@ def questions(request):
view_log = request.session['view_log']
- if view_log.get_previous(1) != 'questions':
- if view_log.get_previous(2) != 'questions':
- #print 'user stepped too far, resetting search state'
- search_state.reset()
+ if view_log.should_reset_search_state():
+ search_state.reset()
if request.user.is_authenticated():
search_state.set_logged_in()