summaryrefslogtreecommitdiffstats
path: root/forum
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2009-12-09 12:13:32 -0500
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2009-12-09 12:13:32 -0500
commit4be0491e6adef6bf5817545ec9e050555066352f (patch)
treeb95f6107872ed32c5632aad61eb973522a2730d4 /forum
parent9655bd421022dd6488b21184cc9fd0242c6b345e (diff)
downloadaskbot-4be0491e6adef6bf5817545ec9e050555066352f.tar.gz
askbot-4be0491e6adef6bf5817545ec9e050555066352f.tar.bz2
askbot-4be0491e6adef6bf5817545ec9e050555066352f.zip
better selector of ignored questions, split javascript tag_selector into separate file, fixed question counter messages in the english lang file
Diffstat (limited to 'forum')
-rw-r--r--forum/management/commands/send_email_alerts.py4
-rw-r--r--forum/models.py4
-rw-r--r--forum/views.py84
3 files changed, 17 insertions, 75 deletions
diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py
index 563aab69..4a636e87 100644
--- a/forum/management/commands/send_email_alerts.py
+++ b/forum/management/commands/send_email_alerts.py
@@ -41,11 +41,11 @@ class Command(NoArgsCommand):
#todo: still need to add back individually selected and other questions....
#these may be filtered out by tags
if user.tag_filter_setting == 'ignored':
- ignored_tags = user.markedtag_set.filter(reason='bad').values_list('tag', flat=True).distinct()
+ ignored_tags = Tag.objects.filter(user_selections___reason='bad',user_selections__user=user)
Q_set1 = Q_set1.exclude( tags__in=ignored_tags )
logging.debug('removed ignored tags')
else:
- selected_tags = user.markedtag_set.filter(reason='good').values_list('tag', flat=True).distinct()
+ selected_tags = Tag.objects.filter(user_selections___reason='good',user_selections__user=user)
Q_set1 = Q_set1.filter( tags__in=selected_tags )
logging.debug('filtered for only selected tags')
diff --git a/forum/models.py b/forum/models.py
index 8873fd87..b031b0c8 100644
--- a/forum/models.py
+++ b/forum/models.py
@@ -346,8 +346,8 @@ class FavoriteQuestion(models.Model):
class MarkedTag(models.Model):
TAG_MARK_REASONS = (('good',_('interesting')),('bad',_('ignored')))
- tag = models.ForeignKey(Tag)
- user = models.ForeignKey(User)
+ tag = models.ForeignKey(Tag, related_name='user_selections')
+ user = models.ForeignKey(User, related_name='tag_selections')
reason = models.CharField(max_length=16, choices=TAG_MARK_REASONS)
class QuestionRevision(models.Model):
diff --git a/forum/views.py b/forum/views.py
index f1eb4d0c..c76abf3b 100644
--- a/forum/views.py
+++ b/forum/views.py
@@ -205,6 +205,16 @@ def questions(request, tagname=None, unanswered=False):
+ 'AND forum_markedtag.reason = "good" '
+ 'AND question_tags.question_id = question.id'
),
+ ]),
+ select_params = (uid_str,),
+ )
+ if request.user.hide_ignored_questions:
+ ignored_tags = Tag.objects.filter(user_selections__reason='bad',
+ user_selections__user = request.user)
+ qs = qs.exclude(tags__in=ignored_tags)
+ else:
+ qs = qs.extra(
+ select = SortedDict([
(
'ignored_score',
'SELECT COUNT(1) FROM forum_markedtag, question_tags '
@@ -214,81 +224,13 @@ def questions(request, tagname=None, unanswered=False):
+ 'AND question_tags.question_id = question.id'
)
]),
- select_params = (uid_str, uid_str)
+ select_params = (uid_str, )
)
- #if request.user.hide_ignored_questions:
- # qs = qs.extra(where=['ignored_score=0']) #this doesn't work,
- #no way to filter on ignored_score!
qs = qs.select_related(depth=1).order_by(orderby)
- #don't know how to get around this - maybe have to use raw sql?
- #the probjem is that it seems to be impossible to exclude ingored questions
- #from the query set - 'the django way'
- #the erzatz paginator below compensates for the current lack of proper SQL statement
- class DummyQuerySet(list):
- def __init__(self,items):
- super(DummyQuerySet, self).__init__(items)
- def count(self):
- return len(self)
-
- class DummyPage(list):
- def __init__(self,items,num=1,has_next=True):
- self.object_list = DummyQuerySet(items)
- self.num = num
- self.has_next_page = has_next
- def count(self):
- return len(self.object_list)
- def has_next(self):
- return self.has_next_page
- def has_previous(self):
- return (self.num > 1)
- def previous_page_number(self):
- if self.has_previous():
- return self.num - 1
- return self.num
- def next_page_number(self):
- if self.has_next():
- return self.num + 1
- return self.num
-
- class HidingIgnoredPaginator(object):
- def __init__(self,query_set,page_size):
- self.query_set = list(query_set)#force db hit
- self.page_size = page_size
- self.pages = []
- self.count = 0
- cpage = []
- for q in self.query_set:
- if self.count % page_size == 0:
- if len(cpage) > 0:
- self.pages.append(cpage)
- cpage = []
- if q.ignored_score == 0:
- cpage.append(q)
- self.count += 1
- if cpage not in self.pages and len(cpage) > 0:
- self.pages.append(cpage)
- self.num_pages = len(self.pages)
-
- def page(self,num):
- if self.num_pages == 0:
- return DummyPage([],num=1,has_next=False)
- elif num >= self.num_pages:
- page_content = self.pages[-1]
- num = self.num_pages
- has_next = False
- else:
- page_content = self.pages[num-1]
- has_next = True
- return DummyPage(page_content,num=num,has_next=has_next)
-
- if request.user.is_authenticated() and request.user.hide_ignored_questions:
- objects_list = HidingIgnoredPaginator(qs, pagesize)
- questions = objects_list.page(page)
- else: #otherwise just use the paginator
- objects_list = Paginator(qs, pagesize)
- questions = objects_list.page(page)
+ objects_list = Paginator(qs, pagesize)
+ questions = objects_list.page(page)
# Get related tags from this page objects
if questions.object_list.count() > 0: