summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-08-10 15:03:27 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2012-08-10 15:03:27 -0400
commita54c5f955b704f1c6b8c6a4ffc37c6307043dbfc (patch)
tree5d39f09c54db59269f30393a8b6c3bae4013e51b
parentaeffec86e7cb4c65b26767afb6efc05bf4e261d5 (diff)
downloadaskbot-a54c5f955b704f1c6b8c6a4ffc37c6307043dbfc.tar.gz
askbot-a54c5f955b704f1c6b8c6a4ffc37c6307043dbfc.tar.bz2
askbot-a54c5f955b704f1c6b8c6a4ffc37c6307043dbfc.zip
made notifications work for the thread sharing
-rw-r--r--askbot/const/__init__.py20
-rw-r--r--askbot/models/__init__.py8
-rw-r--r--askbot/models/post.py30
-rw-r--r--askbot/models/question.py4
-rw-r--r--askbot/skins/default/templates/question/sidebar.html2
-rw-r--r--askbot/tasks.py7
-rw-r--r--askbot/views/commands.py41
7 files changed, 78 insertions, 34 deletions
diff --git a/askbot/const/__init__.py b/askbot/const/__init__.py
index 2633055f..037ee379 100644
--- a/askbot/const/__init__.py
+++ b/askbot/const/__init__.py
@@ -176,6 +176,7 @@ TYPE_ACTIVITY_MODERATED_POST_EDIT = 25
TYPE_ACTIVITY_CREATE_REJECT_REASON = 26
TYPE_ACTIVITY_UPDATE_REJECT_REASON = 27
TYPE_ACTIVITY_VALIDATION_EMAIL_SENT = 28
+TYPE_ACTIVITY_POST_SHARED = 29
#TYPE_ACTIVITY_EDIT_QUESTION = 17
#TYPE_ACTIVITY_EDIT_ANSWER = 18
@@ -199,6 +200,7 @@ TYPE_ACTIVITY = (
(TYPE_ACTIVITY_FAVORITE, _('selected favorite')),
(TYPE_ACTIVITY_USER_FULL_UPDATED, _('completed user profile')),
(TYPE_ACTIVITY_EMAIL_UPDATE_SENT, _('email update sent to user')),
+ (TYPE_ACTIVITY_POST_SHARED, _('a post was shared')),
(
TYPE_ACTIVITY_UNANSWERED_REMINDER_SENT,
_('reminder about unanswered questions sent'),
@@ -244,6 +246,7 @@ RESPONSE_ACTIVITY_TYPES_FOR_INSTANT_NOTIFICATIONS = (
TYPE_ACTIVITY_UPDATE_QUESTION,
TYPE_ACTIVITY_ANSWER,
TYPE_ACTIVITY_ASK_QUESTION,
+ TYPE_ACTIVITY_POST_SHARED
)
@@ -256,6 +259,7 @@ RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY = (
TYPE_ACTIVITY_COMMENT_ANSWER,
TYPE_ACTIVITY_UPDATE_ANSWER,
TYPE_ACTIVITY_UPDATE_QUESTION,
+ TYPE_ACTIVITY_POST_SHARED,
# TYPE_ACTIVITY_PRIZE,
# TYPE_ACTIVITY_MARK_ANSWER,
# TYPE_ACTIVITY_VOTE_UP,
@@ -267,15 +271,15 @@ RESPONSE_ACTIVITY_TYPES_FOR_DISPLAY = (
# TYPE_ACTIVITY_FAVORITE,
)
-
RESPONSE_ACTIVITY_TYPE_MAP_FOR_TEMPLATES = {
- TYPE_ACTIVITY_COMMENT_QUESTION: 'question_comment',
- TYPE_ACTIVITY_COMMENT_ANSWER: 'answer_comment',
- TYPE_ACTIVITY_UPDATE_ANSWER: 'answer_update',
- TYPE_ACTIVITY_UPDATE_QUESTION: 'question_update',
- TYPE_ACTIVITY_ANSWER: 'new_answer',
- TYPE_ACTIVITY_ASK_QUESTION: 'new_question',
- }
+ TYPE_ACTIVITY_COMMENT_QUESTION: 'question_comment',
+ TYPE_ACTIVITY_COMMENT_ANSWER: 'answer_comment',
+ TYPE_ACTIVITY_UPDATE_ANSWER: 'answer_update',
+ TYPE_ACTIVITY_UPDATE_QUESTION: 'question_update',
+ TYPE_ACTIVITY_ANSWER: 'new_answer',
+ TYPE_ACTIVITY_ASK_QUESTION: 'new_question',
+ TYPE_ACTIVITY_POST_SHARED: 'post_shared'
+}
assert(
set(RESPONSE_ACTIVITY_TYPES_FOR_INSTANT_NOTIFICATIONS) \
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index 5392fc30..27336576 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -2806,6 +2806,8 @@ def format_instant_notification_email(
assert(isinstance(post, Post) and post.is_question())
elif update_type == 'new_question':
assert(isinstance(post, Post) and post.is_question())
+ elif update_type == 'post_shared':
+ pass
else:
raise ValueError('unexpected update_type %s' % update_type)
@@ -2830,9 +2832,11 @@ def format_instant_notification_email(
content_preview += '<p>======= Full thread summary =======</p>'
- content_preview += post.thread.format_for_email()
+ content_preview += post.thread.format_for_email(user=to_user)
- if post.is_comment():
+ if update_type == 'post_shared':
+ user_action = _('%(user)s shared a %(post_link)s.')
+ elif post.is_comment():
if update_type.endswith('update'):
user_action = _('%(user)s edited a %(post_link)s.')
else:
diff --git a/askbot/models/post.py b/askbot/models/post.py
index d54f7092..8d2d05a4 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -583,30 +583,29 @@ class Post(models.Model):
self,
updated_by=None,
notify_sets=None,
+ activity_type=None,
timestamp=None,
- created=False,
diff=None
):
"""Called when a post is updated. Arguments:
* ``notify_sets`` - result of ``Post.get_notify_sets()`` method
- * ``created`` - a boolean. True when ``post`` has just been created
- * remaining arguments are self - explanatory
The method does two things:
* records "red envelope" recipients of the post
* sends email alerts to all subscribers to the post
"""
- #todo: take into account created == True case
- (activity_type, update_object) = self.get_updated_activity_data(created)
-
+ assert(activity_type is not None)
if self.is_comment():
#it's just a comment!
summary = self.text
else:
#summary = post.get_latest_revision().summary
- summary = diff
+ if diff:
+ summary = diff
+ else:
+ summary = self.text
update_activity = Activity(
user = updated_by,
@@ -636,7 +635,7 @@ class Post(models.Model):
if askbot_settings.ENABLE_EMAIL_ALERTS == False:
return
#todo: fix this temporary spam protection plug
- if created and askbot_settings.MIN_REP_TO_TRIGGER_EMAIL:
+ if askbot_settings.MIN_REP_TO_TRIGGER_EMAIL:
if not (updated_by.is_administrator() or updated_by.is_moderator()):
if updated_by.reputation < askbot_settings.MIN_REP_TO_TRIGGER_EMAIL:
notify_sets['for_email'] = \
@@ -1136,10 +1135,7 @@ class Post(models.Model):
#print 'answer subscribers: ', answer_subscribers
#print 'exclude_list is ', exclude_list
- subscriber_set -= set(exclude_list)
-
- #print 'final subscriber set is ', subscriber_set
- return list(subscriber_set)
+ return subscriber_set - set(exclude_list)
def _comment__get_instant_notification_subscribers(
self,
@@ -1205,13 +1201,7 @@ class Post(models.Model):
subscriber_set.update(global_subscribers)
- #print 'exclude list is: ', exclude_list
- if exclude_list:
- subscriber_set -= set(exclude_list)
-
- #print 'final list of subscribers:', subscriber_set
-
- return list(subscriber_set)
+ return subscriber_set - set(exclude_list)
def get_instant_notification_subscribers(
self, potential_subscribers = None,
@@ -1230,7 +1220,7 @@ class Post(models.Model):
exclude_list=exclude_list
)
elif self.is_tag_wiki() or self.is_reject_reason():
- return list()
+ return set()
else:
raise NotImplementedError
diff --git a/askbot/models/question.py b/askbot/models/question.py
index 14515b8f..ab3e6959 100644
--- a/askbot/models/question.py
+++ b/askbot/models/question.py
@@ -560,9 +560,9 @@ class Thread(models.Model):
else:
return self.title
- def format_for_email(self):
+ def format_for_email(self, user=None):
"""experimental function: output entire thread for email"""
- question, answers, junk = self.get_cached_post_data()
+ question, answers, junk = self.get_cached_post_data(user=user)
output = question.format_for_email_as_subthread()
if answers:
answer_heading = ungettext(
diff --git a/askbot/skins/default/templates/question/sidebar.html b/askbot/skins/default/templates/question/sidebar.html
index 6c4643e9..ef99e988 100644
--- a/askbot/skins/default/templates/question/sidebar.html
+++ b/askbot/skins/default/templates/question/sidebar.html
@@ -84,7 +84,7 @@
<form action="{% url share_question_with_group %}" method="post">{% csrf_token %}
<input
type="hidden"
- name="group_name"
+ name="recipient_name"
value="{{ settings.GLOBAL_GROUP_NAME }}"
/>
<input type="hidden" name="thread_id" value="{{ thread.id }}"/>
diff --git a/askbot/tasks.py b/askbot/tasks.py
index d4c3b676..4aa11798 100644
--- a/askbot/tasks.py
+++ b/askbot/tasks.py
@@ -112,13 +112,18 @@ def record_post_update_celery_task(
mentioned_users=newly_mentioned_users,
exclude_list=[updated_by,]
)
+ #todo: take into account created == True case
+ #update_object is not used
+ (activity_type, update_object) = post.get_updated_activity_data(created)
+
post.issue_update_notifications(
updated_by=updated_by,
notify_sets=notify_sets,
+ activity_type=activity_type,
timestamp=timestamp,
- created=created,
diff=diff
)
+
except Exception:
# HACK: exceptions from Celery job don't propagate upwards
# to the Django test runner
diff --git a/askbot/views/commands.py b/askbot/views/commands.py
index 316895f7..1b6b21e8 100644
--- a/askbot/views/commands.py
+++ b/askbot/views/commands.py
@@ -1156,12 +1156,40 @@ def share_question_with_group(request):
group_name = form.cleaned_data['recipient_name']
thread = models.Thread.objects.get(id=thread_id)
+ question_post = thread._question_post()
+
+ #get notif set before
+ sets1 = question_post.get_notify_sets(
+ mentioned_users=list(),
+ exclude_list=[request.user,]
+ )
+
+ #share the post
if group_name == askbot_settings.GLOBAL_GROUP_NAME:
thread.make_public(recursive=True)
else:
group = models.Tag.group_tags.get(name=group_name)
thread.add_to_groups((group,), recursive=True)
+ #get notif sets after
+ sets2 = question_post.get_notify_sets(
+ mentioned_users=list(),
+ exclude_list=[request.user,]
+ )
+
+ notify_sets = {
+ 'for_mentions': sets2['for_mentions'] - sets1['for_mentions'],
+ 'for_email': sets2['for_email'] - sets1['for_email'],
+ 'for_inbox': sets2['for_inbox'] - sets1['for_inbox']
+ }
+
+ question_post.issue_update_notifications(
+ updated_by=request.user,
+ notify_sets=notify_sets,
+ activity_type=const.TYPE_ACTIVITY_POST_SHARED,
+ timestamp=datetime.datetime.now()
+ )
+
return HttpResponseRedirect(thread.get_absolute_url())
except Exception:
error_message = _('Sorry, looks like sharing request was invalid')
@@ -1181,6 +1209,19 @@ def share_question_with_user(request):
user = models.User.objects.get(username=username)
group = user.get_personal_group()
thread.add_to_groups([group], recursive=True)
+ #notify the person
+ #todo: see if user could already see the post - b/f the sharing
+ notify_sets = {
+ 'for_inbox': set([user]),
+ 'for_mentions': set([user]),
+ 'for_email': set([user])
+ }
+ thread._question_post().issue_update_notifications(
+ updated_by=request.user,
+ notify_sets=notify_sets,
+ activity_type=const.TYPE_ACTIVITY_POST_SHARED,
+ timestamp=datetime.datetime.now()
+ )
return HttpResponseRedirect(thread.get_absolute_url())
except Exception: