summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-05-30 22:17:55 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-05-30 22:17:55 -0400
commiteff58f74b06e581c787500c7303f26cccce565f2 (patch)
tree1a6e42151e36808e1ea84811a37b6077c2a5d118
parentad74fdd061fcf4811d90458c2e29bbe124d3e12e (diff)
downloadaskbot-eff58f74b06e581c787500c7303f26cccce565f2.tar.gz
askbot-eff58f74b06e581c787500c7303f26cccce565f2.tar.bz2
askbot-eff58f74b06e581c787500c7303f26cccce565f2.zip
added setting allowing to change when author of the emailed post is notified of his own posting
-rw-r--r--askbot/conf/email.py30
-rw-r--r--askbot/const/__init__.py39
-rw-r--r--askbot/models/__init__.py14
-rw-r--r--askbot/models/post.py35
-rw-r--r--askbot/models/signals.py7
-rw-r--r--askbot/tests/email_alert_tests.py8
6 files changed, 115 insertions, 18 deletions
diff --git a/askbot/conf/email.py b/askbot/conf/email.py
index 195f36e3..1b81fa96 100644
--- a/askbot/conf/email.py
+++ b/askbot/conf/email.py
@@ -274,8 +274,6 @@ settings.register(
)
)
-
-
settings.register(
livesettings.BooleanValue(
EMAIL,
@@ -291,6 +289,31 @@ settings.register(
)
settings.register(
+ livesettings.StringValue(
+ EMAIL,
+ 'SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN',
+ description = _(
+ 'Emailed post: when to notify author about publishing'
+ ),
+ choices = const.SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN_CHOICES,
+ default = const.NEVER
+ )
+)
+
+#not implemented at this point
+#settings.register(
+# livesettings.IntegerValue(
+# EMAIL,
+# 'SELF_NOTIFY_WEB_POST_AUTHOR_WHEN',
+# description = _(
+# 'Web post: when to notify author about publishing'
+# ),
+# choices = const.SELF_NOTIFY_WEB_POST_AUTHOR_WHEN_CHOICES,
+# default = const.NEVER
+# )
+#)
+
+settings.register(
livesettings.StringValue(
EMAIL,
'REPLY_BY_EMAIL_HOSTNAME',
@@ -301,8 +324,6 @@ settings.register(
)
)
-
-
settings.register(
livesettings.IntegerValue(
EMAIL,
@@ -311,4 +332,3 @@ settings.register(
description=_('Email replies having fewer words than this number will be posted as comments instead of answers')
)
)
-
diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py
index 8e7ba9e6..e693a63c 100644
--- a/askbot/const/__init__.py
+++ b/askbot/const/__init__.py
@@ -6,6 +6,7 @@ text in this project, all unicode text go here.
"""
from django.utils.translation import ugettext as _
import re
+
CLOSE_REASONS = (
(1, _('duplicate question')),
(2, _('question is off-topic or not relevant')),
@@ -55,6 +56,44 @@ POST_SORT_METHODS = (
POST_TYPES = ('answer', 'comment', 'question', 'tag_wiki', 'reject_reason')
SIMPLE_REPLY_SEPARATOR_TEMPLATE = '==== %s -=-=='
+
+#values for SELF_NOTIFY_WHEN... settings use bits
+NEVER = 'never'
+FOR_FIRST_REVISION = 'first'
+FOR_ANY_REVISION = 'any'
+SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN_CHOICES = (
+ (NEVER, _('Never')),
+ (FOR_FIRST_REVISION, _('When new post is published')),
+ (FOR_ANY_REVISION, _('When post is published or revised')),
+)
+#need more options for web posts b/c user is looking at the page
+#when posting. when posts are made by email - user is not looking
+#at the site and therefore won't get any feedback unless an email is sent back
+#todo: rename INITIAL -> FIRST and make values of type string
+#FOR_INITIAL_REVISION_WHEN_APPROVED = 1
+#FOR_ANY_REVISION_WHEN_APPROVED = 2
+#FOR_INITIAL_REVISION_ALWAYS = 3
+#FOR_ANY_REVISION_ALWAYS = 4
+#SELF_NOTIFY_WEB_POST_AUTHOR_WHEN_CHOICES = (
+# (NEVER, _('Never')),
+# (
+# FOR_INITIAL_REVISION_WHEN_APPROVED,
+# _('When inital revision is approved by moderator')
+# ),
+# (
+# FOR_ANY_REVISION_WHEN_APPROVED,
+# _('When any revision is approved by moderator')
+# ),
+# (
+# FOR_INITIAL_REVISION_ALWAYS,
+# _('Any time when inital revision is published')
+# ),
+# (
+# FOR_ANY_REVISION_ALWAYS,
+# _('Any time when revision is published')
+# )
+#)
+
REPLY_SEPARATOR_TEMPLATE = '==== %(user_action)s %(instruction)s -=-=='
REPLY_WITH_COMMENT_TEMPLATE = _(
'Note: to reply with a comment, '
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 1583b2e5..8c96ce8c 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -2299,7 +2299,9 @@ def user_approve_post_revision(user, post_revision, timestamp = None):
post.thread.invalidate_cached_data()
#send the signal of published revision
- signals.post_revision_published.send(None, revision = post_revision)
+ signals.post_revision_published.send(
+ None, revision = post_revision, was_approved = True
+ )
@auto_now_timestamp
def flag_post(user, post, timestamp=None, cancel=False, cancel_all = False, force = False):
@@ -2817,11 +2819,14 @@ def send_instant_notifications_about_activity_in_post(
headers = headers
)
-def notify_author_of_published_revision(revision, **kwargs):
+def notify_author_of_published_revision(
+ revision = None, was_approved = None, **kwargs
+):
"""notifies author about approved post revision,
assumes that we have the very first revision
"""
- if revision.revision == 1:#only email about first revision
+ #only email about first revision
+ if revision.should_notify_author_about_publishing(was_approved):
from askbot.tasks import notify_author_of_published_revision_celery_task
notify_author_of_published_revision_celery_task.delay(revision)
@@ -3243,6 +3248,9 @@ signals.user_updated.connect(record_user_full_updated, sender=User)
signals.user_logged_in.connect(complete_pending_tag_subscriptions)#todo: add this to fake onlogin middleware
signals.user_logged_in.connect(post_anonymous_askbot_content)
signals.post_updated.connect(record_post_update_activity)
+
+#probably we cannot use post-save here the point of this is
+#to tell when the revision becomes publicly visible, not when it is saved
signals.post_revision_published.connect(notify_author_of_published_revision)
signals.site_visited.connect(record_user_visit)
diff --git a/askbot/models/post.py b/askbot/models/post.py
index 0bc57ebb..06db7688 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -345,7 +345,7 @@ class Post(models.Model):
db_table = 'askbot_post'
- def parse_post_text(post):
+ def parse_post_text(self):
"""typically post has a field to store raw source text
in comment it is called .comment, in Question and Answer it is
called .text
@@ -361,18 +361,18 @@ class Post(models.Model):
removed_mentions - list of mention <Activity> objects - for removed ones
"""
- if post.post_type in ('question', 'answer', 'tag_wiki', 'reject_reason'):
+ if self.post_type in ('question', 'answer', 'tag_wiki', 'reject_reason'):
_urlize = False
_use_markdown = True
_escape_html = False #markdow does the escaping
- elif post.is_comment():
+ elif self.is_comment():
_urlize = True
_use_markdown = True
_escape_html = True
else:
raise NotImplementedError
- text = post.text
+ text = self.text
if _escape_html:
text = cgi.escape(text)
@@ -384,12 +384,12 @@ class Post(models.Model):
text = sanitize_html(markup.get_parser().convert(text))
#todo, add markdown parser call conditional on
- #post.use_markdown flag
+ #self.use_markdown flag
post_html = text
mentioned_authors = list()
removed_mentions = list()
if '@' in text:
- op = post.get_origin_post()
+ op = self.get_origin_post()
anticipated_authors = op.get_author_list(
include_comments = True,
recursive = True
@@ -416,10 +416,10 @@ class Post(models.Model):
#find mentions that were removed and identify any previously
#entered mentions so that we can send alerts on only new ones
from askbot.models.user import Activity
- if post.pk is not None:
+ if self.pk is not None:
#only look for previous mentions if post was already saved before
prev_mention_qs = Activity.objects.get_mentions(
- mentioned_in = post
+ mentioned_in = self
)
new_set = set(mentioned_authors)
for prev_mention in prev_mention_qs:
@@ -1778,6 +1778,7 @@ class PostRevision(models.Model):
self.post.thread.save()
#above changes will hide post from the public display
if self.by_email:
+ #todo: move this to the askbot.mail module
from askbot.mail import send_mail
email_context = {
'site': askbot_settings.APP_SHORT_NAME
@@ -1818,7 +1819,6 @@ class PostRevision(models.Model):
#todo: make this group-sensitive
activity.add_recipients(get_admins_and_moderators())
-
def moderate_or_publish(self):
"""either place on moderation queue or announce
that this revision is published"""
@@ -1828,6 +1828,23 @@ class PostRevision(models.Model):
from askbot.models import signals
signals.post_revision_published.send(None, revision = self)
+ def should_notify_author_about_publishing(self, was_approved = False):
+ """True if author should get email about making own post"""
+ if self.by_email:
+ schedule = askbot_settings.SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN
+ if schedule == const.NEVER:
+ return False
+ elif schedule == const.FOR_FIRST_REVISION:
+ return self.revision == 1
+ elif schedule == const.FOR_ANY_REVISION:
+ return True
+ else:
+ raise ValueError()
+ else:
+ #logic not implemented yet
+ #the ``was_approved`` argument will be used here
+ #schedule = askbot_settings.SELF_NOTIFY_WEB_POST_AUTHOR_WHEN
+ return False
def revision_type_str(self):
return self.REVISION_TYPE_CHOICES_DICT[self.revision_type]
diff --git a/askbot/models/signals.py b/askbot/models/signals.py
index 1541eff5..d538de76 100644
--- a/askbot/models/signals.py
+++ b/askbot/models/signals.py
@@ -32,7 +32,12 @@ post_updated = django.dispatch.Signal(
'newly_mentioned_users'
]
)
-post_revision_published = django.dispatch.Signal(providing_args = ['revision'])
+post_revision_published = django.dispatch.Signal(
+ providing_args = [
+ 'revision',
+ 'was_approved'
+ ]
+ )
site_visited = django.dispatch.Signal(providing_args=['user', 'timestamp'])
def pop_signal_receivers(signal):
diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py
index 6d0cc105..f07a6613 100644
--- a/askbot/tests/email_alert_tests.py
+++ b/askbot/tests/email_alert_tests.py
@@ -959,6 +959,10 @@ class PostApprovalTests(utils.AskbotTestCase):
self.enable_content_moderation = \
askbot_settings.ENABLE_CONTENT_MODERATION
askbot_settings.update('ENABLE_CONTENT_MODERATION', True)
+ self.self_notify_when = \
+ askbot_settings.SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN
+ when = const.FOR_FIRST_REVISION
+ askbot_settings.update('SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN', when)
assert(
django_settings.EMAIL_BACKEND == 'django.core.mail.backends.locmem.EmailBackend'
)
@@ -971,6 +975,10 @@ class PostApprovalTests(utils.AskbotTestCase):
'ENABLE_CONTENT_MODERATION',
self.enable_content_moderation
)
+ askbot_settings.update(
+ 'SELF_NOTIFY_EMAILED_POST_AUTHOR_WHEN',
+ self.self_notify_when
+ )
def test_emailed_question_answerable_approval_notification(self):
self.u1 = self.create_user('user1', status = 'a')#regular user