diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-09-25 23:58:12 -0600 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-09-25 23:58:12 -0600 |
commit | 9128764388140b5a0b46eba0d0286a86b7faad58 (patch) | |
tree | cb01a75fae7fa0f25dc2921ffec1b356b6e9e749 | |
parent | 81b4b2d799b9e5c5d67d6a8bd7838b10c4ad34a8 (diff) | |
parent | 3fdc78352a7a80451944af75c46e1cde790a0033 (diff) | |
download | askbot-9128764388140b5a0b46eba0d0286a86b7faad58.tar.gz askbot-9128764388140b5a0b46eba0d0286a86b7faad58.tar.bz2 askbot-9128764388140b5a0b46eba0d0286a86b7faad58.zip |
Merge branch 'master' into notifications-delay
-rw-r--r-- | askbot/models/__init__.py | 2 | ||||
-rw-r--r-- | askbot/models/post.py | 42 | ||||
-rw-r--r-- | askbot/models/question.py | 40 | ||||
-rw-r--r-- | askbot/models/user.py | 7 | ||||
-rw-r--r-- | askbot/templates/main_page/tag_search.html | 1 | ||||
-rw-r--r-- | askbot/templates/user_inbox/base.html | 6 | ||||
-rw-r--r-- | askbot/templatetags/extra_filters_jinja.py | 11 | ||||
-rw-r--r-- | askbot/tests/email_alert_tests.py | 24 | ||||
-rw-r--r-- | askbot/tests/templatefilter_tests.py | 4 |
9 files changed, 99 insertions, 38 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 9491f9ea..9c777ea7 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1754,7 +1754,7 @@ def user_create_post_reject_reason( added_at = timestamp, text = details ) - details.parse_and_save(author = self) + details.parse_and_save(author=self) details.add_revision( author = self, revised_at = timestamp, diff --git a/askbot/models/post.py b/askbot/models/post.py index 72b1b680..57847088 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -225,7 +225,18 @@ class PostManager(BaseQuerySetManager): is_private = is_private or \ (thread and thread.requires_response_moderation(author)) - post.parse_and_save(author=author, is_private=is_private) + parse_results = post.parse_and_save(author=author, is_private=is_private) + + from askbot.models import signals + signals.post_updated.send( + post=post, + updated_by=author, + newly_mentioned_users=parse_results['newly_mentioned_users'], + timestamp=added_at, + created=True, + diff=parse_results['diff'], + sender=post.__class__ + ) post.add_revision( author = author, @@ -529,19 +540,6 @@ class Post(models.Model): timestamp = self.get_time_of_last_edit() - #todo: this is handled in signal because models for posts - #are too spread out - from askbot.models import signals - signals.post_updated.send( - post = self, - updated_by = author, - newly_mentioned_users = newly_mentioned_users, - timestamp = timestamp, - created = created, - diff = diff, - sender = self.__class__ - ) - try: from askbot.conf import settings as askbot_settings if askbot_settings.GOOGLE_SITEMAP_CODE != '': @@ -549,6 +547,8 @@ class Post(models.Model): except Exception: logging.debug('cannot ping google - did you register with them?') + return {'diff': diff, 'newly_mentioned_users': newly_mentioned_users} + def is_question(self): return self.post_type == 'question' @@ -1626,7 +1626,19 @@ class Post(models.Model): by_email = by_email ) - self.parse_and_save(author=edited_by, is_private=is_private) + parse_results = self.parse_and_save(author=edited_by, is_private=is_private) + + from askbot.models import signals + signals.post_updated.send( + post=self, + updated_by=edited_by, + newly_mentioned_users=parse_results['newly_mentioned_users'], + timestamp=edited_at, + created=False, + diff=parse_results['diff'], + sender=self.__class__ + ) + def _answer__apply_edit( self, diff --git a/askbot/models/question.py b/askbot/models/question.py index a4b3233a..6b233188 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -133,7 +133,8 @@ class ThreadManager(BaseQuerySetManager): question.wikified_at = added_at #this is kind of bad, but we save assign privacy groups to posts and thread - question.parse_and_save(author = author, is_private = is_private) + #this call is rather heavy, we should split into several functions + parse_results = question.parse_and_save(author=author, is_private=is_private) revision = question.add_revision( author=author, @@ -155,7 +156,19 @@ class ThreadManager(BaseQuerySetManager): thread.make_public() # INFO: Question has to be saved before update_tags() is called - thread.update_tags(tagnames = tagnames, user = author, timestamp = added_at) + thread.update_tags(tagnames=tagnames, user=author, timestamp=added_at) + + #todo: this is handled in signal because models for posts + #are too spread out + signals.post_updated.send( + post=question, + updated_by=author, + newly_mentioned_users=parse_results['newly_mentioned_users'], + timestamp=added_at, + created=True, + diff=parse_results['diff'], + sender=question.__class__ + ) return thread @@ -246,16 +259,19 @@ class ThreadManager(BaseQuerySetManager): if askbot_settings.TAG_SEARCH_INPUT_ENABLED: #todo: this may be gone or disabled per option #"tag_search_box_enabled" - existing_tags = set( - Tag.objects.filter( - name__in = tags - ).values_list( - 'name', - flat = True - ) - ) - - non_existing_tags = set(tags) - existing_tags + existing_tags = set() + non_existing_tags = set() + #we're using a one-by-one tag retreival, b/c + #we want to take advantage of case-insensitive search indexes + #in postgresql, plus it is most likely that there will be + #only one or two search tags anyway + for tag in tags: + try: + tag_record = Tag.objects.get(name__iexact=tag) + existing_tags.add(tag_record.name) + except Tag.DoesNotExist: + non_existing_tags.add(tag) + meta_data['non_existing_tags'] = list(non_existing_tags) tags = existing_tags else: diff --git a/askbot/models/user.py b/askbot/models/user.py index bdb94100..39bb8ea9 100644 --- a/askbot/models/user.py +++ b/askbot/models/user.py @@ -271,6 +271,13 @@ class EmailFeedSetting(models.Model): 'q_sel': 'n', 'm_and_c': 'n' } + MAX_EMAIL_SCHEDULE = { + 'q_ask': 'i', + 'q_ans': 'i', + 'q_all': 'i', + 'q_sel': 'i', + 'm_and_c': 'i' + } FEED_TYPE_CHOICES = ( ('q_all',_('Entire forum')), ('q_ask',_('Questions that I asked')), diff --git a/askbot/templates/main_page/tag_search.html b/askbot/templates/main_page/tag_search.html index 0d81bf4e..45f12b2f 100644 --- a/askbot/templates/main_page/tag_search.html +++ b/askbot/templates/main_page/tag_search.html @@ -1,6 +1,5 @@ <div id="tagSearch" class="box"> <h2>{% trans %}Tag search{% endtrans %}</h2> - <label for="ab-tag-search">{% trans %}Please note that tag search is case sensitive!{% endtrans %}</label> <div class="inputs"> <input id="ab-tag-search" autocomplete="off" type="text"/> <input id="ab-tag-search-add" type="submit" value="{% trans %}search{% endtrans %}"/> diff --git a/askbot/templates/user_inbox/base.html b/askbot/templates/user_inbox/base.html index 890cb0f7..2f8b805e 100644 --- a/askbot/templates/user_inbox/base.html +++ b/askbot/templates/user_inbox/base.html @@ -13,10 +13,10 @@ <div id="re_sections"> {% trans %}Sections:{% endtrans %} {% set sep = joiner('|') %} - {{ sep() }} - <a href="{{request.user.get_absolute_url()}}?sort=inbox§ion=messages" + {#{ sep() }} + {<a href="{{request.user.get_absolute_url()}}?sort=inbox§ion=messages" {% if inbox_section == 'messages' %}class="on"{% endif %} - >{% trans %}messages{% endtrans %}</a> + >{% trans %}messages{% endtrans %}</a>#} {% if re_count > 0 %}{{ sep() }} <a href="{{request.user.get_absolute_url()}}?sort=inbox§ion=forum" {% if inbox_section == 'forum' %}class="on"{% endif %} diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py index 62a41895..ba13166b 100644 --- a/askbot/templatetags/extra_filters_jinja.py +++ b/askbot/templatetags/extra_filters_jinja.py @@ -26,16 +26,19 @@ register = coffin_template.Library() @register.filter def absolutize_urls(text): - url_re1 = re.compile(r'(?P<prefix><img[^<]+src=)"(?P<url>/[^"]+)"', re.I) - url_re2 = re.compile(r"(?P<prefix><img[^<]+src=)'(?P<url>/[^']+)'", re.I) + #temporal fix for bad regex with wysiwyg editor + url_re1 = re.compile(r'(?P<prefix><img[^<]+src=)"(?P<url>[/\..][^"]+)"', re.I) + url_re2 = re.compile(r"(?P<prefix><img[^<]+src=)'(?P<url>[/\..][^']+)'", re.I) url_re3 = re.compile(r'(?P<prefix><a[^<]+href=)"(?P<url>/[^"]+)"', re.I) url_re4 = re.compile(r"(?P<prefix><a[^<]+href=)'(?P<url>/[^']+)'", re.I) - img_replacement = '\g<prefix>"%s\g<url>" style="max-width:500px;"' % askbot_settings.APP_URL + img_replacement = '\g<prefix>"%s/\g<url>" style="max-width:500px;"' % askbot_settings.APP_URL replacement = '\g<prefix>"%s\g<url>"' % askbot_settings.APP_URL text = url_re1.sub(img_replacement, text) text = url_re2.sub(img_replacement, text) text = url_re3.sub(replacement, text) - return url_re4.sub(replacement, text) + #temporal fix for bad regex with wysiwyg editor + return url_re4.sub(replacement, text).replace('%s//' % askbot_settings.APP_URL, + '%s/' % askbot_settings.APP_URL) TIMEZONE_STR = pytz.timezone( diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py index 1937da6f..f5b5e43b 100644 --- a/askbot/tests/email_alert_tests.py +++ b/askbot/tests/email_alert_tests.py @@ -10,6 +10,7 @@ from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import Client from askbot.tests import utils +from askbot.tests.utils import with_settings from askbot import models from askbot import mail from askbot.conf import settings as askbot_settings @@ -954,6 +955,29 @@ class EmailFeedSettingTests(utils.AskbotTestCase): data_after = TO_JSON(self.get_user_feeds()) self.assertEquals(data_before, data_after) + +class EmailAlertTestsWithGroupsEnabled(utils.AskbotTestCase): + + def setUp(self): + self.backup = askbot_settings.GROUPS_ENABLED + askbot_settings.update('GROUPS_ENABLED', True) + + def tearDown(self): + askbot_settings.update('GROUPS_ENABLED', self.backup) + + @with_settings({'MIN_REP_TO_TRIGGER_EMAIL': 1}) + def test_notification_for_global_group_works(self): + sender = self.create_user('sender') + recipient = self.create_user( + 'recipient', + notification_schedule=models.EmailFeedSetting.MAX_EMAIL_SCHEDULE + ) + self.post_question(user=sender) + outbox = django.core.mail.outbox + self.assertEqual(len(outbox), 1) + self.assertEqual(outbox[0].recipients(), [recipient.email]) + + class PostApprovalTests(utils.AskbotTestCase): """test notifications sent to authors when their posts are approved or published""" diff --git a/askbot/tests/templatefilter_tests.py b/askbot/tests/templatefilter_tests.py index 090be956..3902aad4 100644 --- a/askbot/tests/templatefilter_tests.py +++ b/askbot/tests/templatefilter_tests.py @@ -6,12 +6,12 @@ class AbsolutizeUrlsTests(TestCase): def setUp(self): askbot_settings.update('APP_URL', 'http://example.com') def test_absolutize_image_urls(self): - text = """<img class="junk" src="/some.gif"> <IMG SRC='/some.png'>""" + text = """<img class="junk" src="/some.gif"> <img class="junk" src="../../cat.gif"> <IMG SRC='/some.png'>""" #jinja register.filter decorator works in a weird way output = filters.absolutize_urls[0](text) self.assertEqual( output, - '<img class="junk" src="http://example.com/some.gif" style="max-width:500px;"> <IMG SRC="http://example.com/some.png" style="max-width:500px;">' + '<img class="junk" src="http://example.com/some.gif" style="max-width:500px;"> <img class="junk" src="http://example.com/../../cat.gif" style="max-width:500px;"> <IMG SRC="http://example.com/some.png" style="max-width:500px;">' ) def test_absolutize_anchor_urls(self): text = """<a class="junk" href="/something">link</a> <A HREF='/something'>link</A>""" |