From 5dfebd5164518572b9f1c9822990ee476854304d Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Mon, 31 May 2010 22:31:20 -0700 Subject: fixed some bugs in comment posting and made progress in instant notifications --- forum/models/__init__.py | 24 +++++++++++++++++++--- forum/models/base.py | 4 +++- forum/models/meta.py | 3 +++ forum/models/user.py | 2 +- .../default/templates/instant_notification.html | 3 +-- forum/utils/markup.py | 2 +- 6 files changed, 30 insertions(+), 8 deletions(-) diff --git a/forum/models/__init__.py b/forum/models/__init__.py index 0c0914ec..3b4fd8c0 100644 --- a/forum/models/__init__.py +++ b/forum/models/__init__.py @@ -16,6 +16,7 @@ from django.contrib.auth.models import User from django.template.defaultfilters import slugify from django.utils.safestring import mark_safe from django.db import models +from django.conf import settings as django_settings from forum import const import logging import re @@ -251,6 +252,23 @@ User.add_to_class( user_should_receive_instant_notification_about_post ) +def format_instant_notification_body(template, data): + """data has the following keys: + receiving_user: User instance + update_author: Uses instance + updated_post: post = Question|Answer|Comment instance + update_url: absolute url (including http...) of the post + revision_number: latest revision number of the post + update_type: type of update from the map in function below + related_origin_post: another post related to the updated one, if any + admin_email: email address of forum administrator + email_settings_url: full url to the page where user can change email settings + """ + #todo: write this function so that + #it can be easily used for testing of the email messages + #separately using a script + return template.render(Context(data)) + def send_instant_notifications_about_activity_in_post( activity = None, post = None, @@ -288,15 +306,15 @@ def send_instant_notifications_about_activity_in_post( 'update_type': update_type_map[activity.activity_type], 'revision_number': post.get_latest_revision_number(), 'related_origin_post': post.get_origin_post(), - 'admin_email': settings.ADMINS[0][1], + 'admin_email': django_settings.ADMINS[0][1], #todo: clean up url calculation below 'email_settings_url': base_url + u.get_profile_url() \ + '?sort=email_subscriptions' } #send update subject = _('email update message subject') - text = template.render(Context(data)) - msg = EmailMessage(subject, text, settings.DEFAULT_FROM_EMAIL, [u.email]) + text = format_instant_notification_body(template, data) + msg = EmailMessage(subject, text, django_settings.DEFAULT_FROM_EMAIL, [u.email]) print 'sending email to %s' % u.email print 'subject: %s' % subject print 'body: %s' % text diff --git a/forum/models/base.py b/forum/models/base.py index e90bc7a0..110c0deb 100644 --- a/forum/models/base.py +++ b/forum/models/base.py @@ -26,6 +26,7 @@ def render_post_text_and_get_newly_mentioned_users(post, text = html.urlize(text) if '@' not in text: + post.html = text return list() from forum.models.user import Activity @@ -36,6 +37,7 @@ def render_post_text_and_get_newly_mentioned_users(post, anticipated_authors = op.get_author_list( include_comments = True, recursive = True ) extra_name_seeds = markup.extract_mentioned_name_seeds(text) + extra_authors = set() for name_seed in extra_name_seeds: extra_authors.update(User.objects.filter(username__startswith = name_seed)) @@ -46,7 +48,7 @@ def render_post_text_and_get_newly_mentioned_users(post, mentioned_authors, post.html = markup.mentionize_text(text, anticipated_authors) #maybe delete some previous mentions - if self.id != None: + if post.id != None: #only look for previous mentions if post was already saved before prev_mention_qs = Activity.objects.get_mentions( mentioned_in = post diff --git a/forum/models/meta.py b/forum/models/meta.py index 2781d160..d0530694 100644 --- a/forum/models/meta.py +++ b/forum/models/meta.py @@ -94,6 +94,9 @@ class Comment(MetaContent, UserContent): def get_text(self): return self.comment + def set_text(self, text): + self.comment = text + _render_text_and_get_newly_mentioned_users = \ render_post_text_and_get_newly_mentioned_users diff --git a/forum/models/user.py b/forum/models/user.py index c6f95505..c05d911b 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -159,7 +159,7 @@ class EmailFeedSettingManager(models.Manager): for feed in feeds: if feed.feed_type == 'm_and_c': - if post.__clas__.__name__ == 'Comment':#isinstance(post, Comment): + if post.__class__.__name__ == 'Comment':#isinstance(post, Comment): return True else: if subscriber in newly_mentioned_users: diff --git a/forum/skins/default/templates/instant_notification.html b/forum/skins/default/templates/instant_notification.html index 3f4da467..856e6676 100644 --- a/forum/skins/default/templates/instant_notification.html +++ b/forum/skins/default/templates/instant_notification.html @@ -14,8 +14,7 @@ email_settings_url - url of user's email settings {% endcomment %} {% load i18n %} {% load smart_if %} -{% blocktrans with receiving_user.get_best_name as user_name %}Dear {{user_name}},{% endblocktrans %} - +{% blocktrans with receiving_user.username as user_name %}Dear {{user_name}},{% endblocktrans %} {% if update_type == 'question_comment' or update_type == 'answer_comment' %} {% blocktrans with post_author.get_profile_link as author_link and related_origin_post.get_absolute_url as origin_post_url and related_origin_post.title as origin_post_title %} {{author_link}} has left a new comment diff --git a/forum/utils/markup.py b/forum/utils/markup.py index 2b2b8ab1..941e978b 100644 --- a/forum/utils/markup.py +++ b/forum/utils/markup.py @@ -78,7 +78,7 @@ def mentionize_text(text, anticipated_authors): text = text[pos+1:] mentioned_author, text = extract_first_matching_mentioned_author( text, - authors + anticipated_authors ) if mentioned_author: mentioned_authors.append(mentioned_author) -- cgit v1.2.3-1-g7c22