diff options
-rw-r--r-- | askbot/management/commands/send_email_alerts.py | 26 | ||||
-rw-r--r-- | askbot/models/__init__.py | 2 | ||||
-rw-r--r-- | askbot/models/answer.py | 13 | ||||
-rw-r--r-- | askbot/models/post.py | 58 | ||||
-rw-r--r-- | askbot/tests/email_alert_tests.py | 1 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 39 | ||||
-rw-r--r-- | askbot/tests/post_model_tests.py | 2 |
7 files changed, 70 insertions, 71 deletions
diff --git a/askbot/management/commands/send_email_alerts.py b/askbot/management/commands/send_email_alerts.py index 870b519f..d7966e83 100644 --- a/askbot/management/commands/send_email_alerts.py +++ b/askbot/management/commands/send_email_alerts.py @@ -190,11 +190,11 @@ class Command(NoArgsCommand): q_ask_B.cutoff_time = cutoff_time elif feed.feed_type == 'q_ans': - q_ans_A = Q_set_A.filter(answers__author=user) + q_ans_A = Q_set_A.filter(thread__posts__author=user, thread__posts__post_type='answer') q_ans_A = q_ans_A[:askbot_settings.MAX_ALERTS_PER_EMAIL] q_ans_A.cutoff_time = cutoff_time - q_ans_B = Q_set_B.filter(answers__author=user) + q_ans_B = Q_set_B.filter(thread__posts__author=user, thread__posts__post_type='answer') q_ans_B = q_ans_B[:askbot_settings.MAX_ALERTS_PER_EMAIL] q_ans_B.cutoff_time = cutoff_time @@ -224,14 +224,14 @@ class Command(NoArgsCommand): feed = user_feeds.get(feed_type='m_and_c') if feed.should_send_now(): cutoff_time = feed.get_previous_report_cutoff_time() - comments = Comment.objects.filter( + comments = Post.objects.get_comments().filter( added_at__lt = cutoff_time, ).exclude( - user = user + author = user ) q_commented = list() for c in comments: - post = c.content_object + post = c.parent if post.author != user: continue @@ -284,7 +284,7 @@ class Command(NoArgsCommand): extend_question_list(q_all_A, q_list, limit=True) extend_question_list(q_all_B, q_list, limit=True) - ctype = ContentType.objects.get_for_model(Question) + ctype = ContentType.objects.get_for_model(Post) EMAIL_UPDATE_ACTIVITY = const.TYPE_ACTIVITY_EMAIL_UPDATE_SENT #up to this point we still don't know if emails about @@ -335,7 +335,7 @@ class Command(NoArgsCommand): #collect info on all sorts of news that happened after #the most recent emailing to the user about this question q_rev = PostRevision.objects.question_revisions().filter( - question=q, + post=q, revised_at__gt=emailed_at ) @@ -349,8 +349,8 @@ class Command(NoArgsCommand): else: meta_data['new_q'] = False - new_ans = Answer.objects.filter( - question=q, + new_ans = Post.objects.get_answers().filter( + thread=q.thread, added_at__gt=emailed_at, deleted=False, ) @@ -358,10 +358,12 @@ class Command(NoArgsCommand): new_ans = new_ans.exclude(author=user) meta_data['new_ans'] = len(new_ans) ans_rev = PostRevision.objects.answer_revisions().filter( - answer__question = q, - answer__deleted = False, + # answer__question = q + post__thread=q.thread, + + post__deleted = False, revised_at__gt = emailed_at - ) + ).distinct() ans_rev = ans_rev.exclude(author=user) meta_data['ans_rev'] = len(ans_rev) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 82b71681..f1b5d2fe 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1701,7 +1701,7 @@ def user_get_tag_filtered_questions(self, questions = None): to the user choices. Parameter ``questions`` can be either ``None`` or a starting query set. """ - if questions == None: + if questions is None: questions = Post.objects.get_questions() if self.email_tag_filter_strategy == const.EXCLUDE_IGNORED: diff --git a/askbot/models/answer.py b/askbot/models/answer.py index d91aa9cf..8bed896f 100644 --- a/askbot/models/answer.py +++ b/askbot/models/answer.py @@ -1,16 +1,6 @@ import datetime from django.db import models from askbot.models.base import AnonymousContent -from askbot.models import content -from askbot import const - - -#class Answer(content.Content): -# post_type = 'answer' -# question = models.ForeignKey('Question', related_name='answers') -# -# class Meta(content.Content.Meta): -# db_table = u'answer' class AnonymousAnswer(AnonymousContent): @@ -18,7 +8,8 @@ class AnonymousAnswer(AnonymousContent): def publish(self, user): added_at = datetime.datetime.now() - Answer.objects.create_new( + from askbot import models + models.Post.objects.create_new_answer( thread=self.question.thread, author=user, added_at=added_at, diff --git a/askbot/models/post.py b/askbot/models/post.py index 8678b372..12a0787b 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -45,32 +45,38 @@ class PostQuerySet(models.query.QuerySet): """returns a query set of questions, matching the full text query """ - #todo - goes to thread - we search whole threads - if getattr(settings, 'USE_SPHINX_SEARCH', False): - matching_questions = Question.sphinx_search.query(search_query) - question_ids = [q.id for q in matching_questions] - return Question.objects.filter(deleted = False, id__in = question_ids) - if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): - return self.filter( - models.Q(thread__title__search = search_query)\ - | models.Q(text__search = search_query)\ - | models.Q(thread__tagnames__search = search_query)\ - | models.Q(answers__text__search = search_query) - ) - elif 'postgresql_psycopg2' in askbot.get_database_engine_name(): - rank_clause = "ts_rank(question.text_search_vector, plainto_tsquery(%s))"; - search_query = '&'.join(search_query.split()) - extra_params = (search_query,) - extra_kwargs = { - 'select': {'relevance': rank_clause}, - 'where': ['text_search_vector @@ plainto_tsquery(%s)'], - 'params': extra_params, - 'select_params': extra_params, - } - return self.extra(**extra_kwargs) - else: - #fallback to dumb title match search - return self.filter(thread__title__icontains=search_query) + return self.filter( + models.Q(thread__title__icontains = search_query)\ + | models.Q(text__icontains = search_query)\ + | models.Q(thread__tagnames = search_query)\ + | models.Q(thread__posts__text__icontains = search_query, thread__posts__post_type='answer') + ) +# #todo - goes to thread - we search whole threads +# if getattr(settings, 'USE_SPHINX_SEARCH', False): +# matching_questions = Question.sphinx_search.query(search_query) +# question_ids = [q.id for q in matching_questions] +# return Question.objects.filter(deleted = False, id__in = question_ids) +# if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): +# return self.filter( +# models.Q(thread__title__search = search_query)\ +# | models.Q(text__search = search_query)\ +# | models.Q(thread__tagnames__search = search_query)\ +# | models.Q(answers__text__search = search_query) +# ) +# elif 'postgresql_psycopg2' in askbot.get_database_engine_name(): +# rank_clause = "ts_rank(question.text_search_vector, plainto_tsquery(%s))"; +# search_query = '&'.join(search_query.split()) +# extra_params = (search_query,) +# extra_kwargs = { +# 'select': {'relevance': rank_clause}, +# 'where': ['text_search_vector @@ plainto_tsquery(%s)'], +# 'params': extra_params, +# 'select_params': extra_params, +# } +# return self.extra(**extra_kwargs) +# else: +# #fallback to dumb title match search +# return self.filter(thread__title__icontains=search_query) # def run_advanced_search( # self, diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py index bd2e5780..abdb1c58 100644 --- a/askbot/tests/email_alert_tests.py +++ b/askbot/tests/email_alert_tests.py @@ -670,6 +670,7 @@ class InstantMentionsAndCommentsEmailAlertTests(EmailAlertTests): body_text = 'yoyo @target do look here' ) + class InstantQAnsEmailAlertTests(EmailAlertTests): @setup_email_alert_tests def setUp(self): diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 318e42e8..be58da4b 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -31,7 +31,6 @@ def patch_jinja2(): (CMAJOR, CMINOR, CMICRO) = package_utils.get_coffin_version() if CMAJOR == 0 and CMINOR == 3 and CMICRO < 4: - import ipdb; ipdb.set_trace() patch_jinja2() @@ -167,7 +166,7 @@ class PageLoadTestCase(AskbotTestCase): 'answer_revisions', status_code=status_code, template='revisions.html', - kwargs={'id': 20} + kwargs={'id': models.Post.objects.get_answers().order_by('id')[0].id} ) #todo: test different sort methods and scopes self.try_url( @@ -244,28 +243,28 @@ class PageLoadTestCase(AskbotTestCase): self.try_url( 'question', status_code=status_code, - kwargs={'id':1}, + kwargs={'id':1}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html' ) self.try_url( 'question', status_code=status_code, - kwargs={'id':2}, + kwargs={'id':2}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html' ) self.try_url( 'question', status_code=status_code, - kwargs={'id':3}, + kwargs={'id':3}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way follow=True, template='question.html' ) self.try_url( 'question_revisions', status_code=status_code, - kwargs={'id':40}, + kwargs={'id':40}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way template='revisions.html' ) self.try_url('users', @@ -354,7 +353,7 @@ class PageLoadTestCase(AskbotTestCase): self.try_url( 'edit_user', template='authopenid/signin.html', - kwargs={'id':4}, + kwargs={'id':4}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, follow=True, ) @@ -381,25 +380,25 @@ class PageLoadTestCase(AskbotTestCase): #self.proto_test_non_user_urls() def proto_test_user_urls(self, status_code): - user = models.User.objects.get(id=2) + user = models.User.objects.get(id=2) # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way name_slug = slugify(user.username) self.try_url( 'user_profile', - kwargs={'id': 2, 'slug': name_slug}, + kwargs={'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, data={'sort':'stats'}, template='user_profile/user_stats.html' ) self.try_url( 'user_profile', - kwargs={'id': 2, 'slug': name_slug}, + kwargs={'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, data={'sort':'recent'}, template='user_profile/user_recent.html' ) self.try_url( 'user_profile', - kwargs={'id': 2, 'slug': name_slug}, + kwargs={'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, data={'sort':'inbox'}, template='authopenid/signin.html', @@ -407,14 +406,14 @@ class PageLoadTestCase(AskbotTestCase): ) self.try_url( 'user_profile', - kwargs={'id': 2, 'slug': name_slug}, + kwargs={'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, data={'sort':'reputation'}, template='user_profile/user_reputation.html' ) self.try_url( 'user_profile', - kwargs={'id': 2, 'slug': name_slug}, + kwargs={'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, data={'sort':'votes'}, template='authopenid/signin.html', @@ -422,14 +421,14 @@ class PageLoadTestCase(AskbotTestCase): ) self.try_url( 'user_profile', - kwargs={'id': 2, 'slug': name_slug}, + kwargs={'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, data={'sort':'favorites'}, template='user_profile/user_favorites.html' ) self.try_url( 'user_profile', - kwargs={'id': 2, 'slug': name_slug}, + kwargs={'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way status_code=status_code, data={'sort':'email_subscriptions'}, template='authopenid/signin.html', @@ -449,25 +448,25 @@ class PageLoadTestCase(AskbotTestCase): def test_user_urls_logged_in(self): - user = models.User.objects.get(id=2) + user = models.User.objects.get(id=2) # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way name_slug = slugify(user.username) #works only with builtin django_authopenid - self.client.login(method = 'force', user_id = 2) + self.client.login(method = 'force', user_id = 2) # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way self.try_url( 'user_subscriptions', - kwargs = {'id': 2, 'slug': name_slug}, + kwargs = {'id': 2, 'slug': name_slug}, # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way template = 'user_profile/user_email_subscriptions.html' ) self.client.logout() def test_inbox_page(self): - asker = models.User.objects.get(id = 2) + asker = models.User.objects.get(id = 2) # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way question = asker.post_question( title = 'How can this happen?', body_text = 'This is the body of my question', tags = 'question answer test', ) - responder = models.User.objects.get(id = 3) + responder = models.User.objects.get(id = 3) # INFO: Hardcoded ID, might fail if DB allocates IDs in some non-continuous way responder.post_answer( question = question, body_text = 'this is the answer text' diff --git a/askbot/tests/post_model_tests.py b/askbot/tests/post_model_tests.py index eedfc149..cf03916c 100644 --- a/askbot/tests/post_model_tests.py +++ b/askbot/tests/post_model_tests.py @@ -70,7 +70,7 @@ class PostModelTests(AskbotTestCase): ) self.assertRaisesRegexp( ValidationError, - r"{'__all__': \[u'Revision_type doesn`t match values in question/answer fields.', u'Post revision with this Question and Revision already exists.'\]}", + r"{'__all__': \[u'Revision_type doesn`t match values in question/answer fields.', u'Post revision with this Post and Revision already exists.'\]}", post_revision.save ) |