From 9e4af2da15929caa9cb6c275d61883abc59e0fd2 Mon Sep 17 00:00:00 2001 From: Evgeny Fadeev Date: Sun, 28 Feb 2010 22:14:59 -0500 Subject: re-introduced Josephs new message notification and a few newly found bugs --- forum/const.py | 8 ++--- forum/forms.py | 1 + forum/management/commands/send_email_alerts.py | 1 + forum/models/__init__.py | 42 +++++++++++++++++++++++-- forum/models/repute.py | 4 ++- forum/models/user.py | 2 ++ forum/skins/default/templates/questions.html | 2 +- forum/utils/cache.py | 2 +- locale/en/LC_MESSAGES/django.mo | Bin 26986 -> 27289 bytes locale/en/LC_MESSAGES/django.po | 22 +++++++++++-- 10 files changed, 71 insertions(+), 13 deletions(-) diff --git a/forum/const.py b/forum/const.py index 76fd4a24..ce81acb2 100644 --- a/forum/const.py +++ b/forum/const.py @@ -75,10 +75,10 @@ TYPE_ACTIVITY = ( ) TYPE_RESPONSE = { - 'QUESTION_ANSWERED' : 'question_answered', - 'QUESTION_COMMENTED': 'question_commented', - 'ANSWER_COMMENTED' : 'answer_commented', - 'ANSWER_ACCEPTED' : 'answer_accepted', + 'QUESTION_ANSWERED' : _('question_answered'), + 'QUESTION_COMMENTED': _('question_commented'), + 'ANSWER_COMMENTED' : _('answer_commented'), + 'ANSWER_ACCEPTED' : _('answer_accepted'), } CONST = { diff --git a/forum/forms.py b/forum/forms.py index f22763f7..08ce8738 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -8,6 +8,7 @@ from django.contrib.auth.models import User from forum.utils.forms import NextUrlField, UserNameField from recaptcha_django import ReCaptchaField from django.conf import settings +from django.contrib.contenttypes.models import ContentType import logging class TitleField(forms.CharField): diff --git a/forum/management/commands/send_email_alerts.py b/forum/management/commands/send_email_alerts.py index ab318e50..c476e9c9 100644 --- a/forum/management/commands/send_email_alerts.py +++ b/forum/management/commands/send_email_alerts.py @@ -10,6 +10,7 @@ import datetime from django.conf import settings import logging from forum.utils.odict import OrderedDict +from django.contrib.contenttypes.models import ContentType class Command(NoArgsCommand): def handle_noargs(self,**options): diff --git a/forum/models/__init__.py b/forum/models/__init__.py index 9b504103..56d5a4e5 100755 --- a/forum/models/__init__.py +++ b/forum/models/__init__.py @@ -4,6 +4,7 @@ from tag import Tag, MarkedTag from meta import Vote, Comment, FlaggedItem from user import Activity, AnonymousEmail, EmailFeedSetting from repute import Badge, Award, Repute +import re from base import * @@ -111,9 +112,39 @@ def record_ask_event(instance, created, **kwargs): activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ASK_QUESTION) activity.save() +#todo: translate this +record_answer_event_re = re.compile("You have received (a|\d+) .*new response.*") def record_answer_event(instance, created, **kwargs): if created: - activity = Activity(user=instance.author, active_at=instance.added_at, content_object=instance, activity_type=TYPE_ACTIVITY_ANSWER) + q_author = instance.question.author + found_match = False + print 'going through %d messages' % q_author.message_set.all().count() + for m in q_author.message_set.all(): + print m.message + match = record_answer_event_re.search(m.message) + if match: + found_match = True + try: + cnt = int(match.group(1)) + except: + cnt = 1 + m.message = u"You have received %d new responses."\ + % (cnt+1, q_author.get_profile_url()) + print 'updated message' + print m.message + m.save() + break + if not found_match: + msg = u"You have received a new response."\ + % q_author.get_profile_url() + print 'new message' + print msg + q_author.message_set.create(message=msg) + + activity = Activity(user=instance.author, \ + active_at=instance.added_at,\ + content_object=instance, \ + activity_type=TYPE_ACTIVITY_ANSWER) activity.save() def record_comment_event(instance, created, **kwargs): @@ -165,7 +196,12 @@ def notify_award_message(instance, created, **kwargs): """ if created: user = instance.user - user.message_set.create(message=u"Congratulations, you have received a badge '%s'" % instance.badge.name) + + msg = (u"Congratulations, you have received a badge '%s'. " \ + + u"Check out your profile.") \ + % (instance.badge.name, user.get_profile_url()) + + user.message_set.create(message=message) def record_answer_accepted(instance, created, **kwargs): """ @@ -338,4 +374,4 @@ from forum.modules import get_modules_script_classes for k, v in get_modules_script_classes('models', models.Model).items(): if not k in __all__: __all__.append(k) - exec "%s = v" % k \ No newline at end of file + exec "%s = v" % k diff --git a/forum/models/repute.py b/forum/models/repute.py index 91ba0375..149f656f 100755 --- a/forum/models/repute.py +++ b/forum/models/repute.py @@ -1,4 +1,6 @@ from base import * +from django.contrib.contenttypes.models import ContentType +from django.contrib.auth.models import User from django.utils.translation import ugettext as _ @@ -106,4 +108,4 @@ class Repute(models.Model): class Meta: app_label = 'forum' - db_table = u'repute' \ No newline at end of file + db_table = u'repute' diff --git a/forum/models/user.py b/forum/models/user.py index ac6cbc0d..fde1bbb0 100755 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -1,4 +1,6 @@ from base import * +from django.contrib.contenttypes.models import ContentType +from django.contrib.auth.models import User from django.utils.translation import ugettext as _ diff --git a/forum/skins/default/templates/questions.html b/forum/skins/default/templates/questions.html index 4c3b96d2..c2d74eca 100644 --- a/forum/skins/default/templates/questions.html +++ b/forum/skins/default/templates/questions.html @@ -189,7 +189,7 @@ {% endblocktrans %} {% else %} {% blocktrans count questions as cnt with questions_count|intcomma as q_num %} - have total {{q_num}} questions + have total {{q_num}} question {% plural %} have total {{q_num}} questions {% endblocktrans %} diff --git a/forum/utils/cache.py b/forum/utils/cache.py index 410c0662..6341392e 100644 --- a/forum/utils/cache.py +++ b/forum/utils/cache.py @@ -3,7 +3,7 @@ import itertools from django.contrib.contenttypes.models import ContentType -from lanai.utils.lists import flatten +from forum.utils.lists import flatten def fetch_model_dict(model, ids, fields=None): """ diff --git a/locale/en/LC_MESSAGES/django.mo b/locale/en/LC_MESSAGES/django.mo index 20813cb3..385fe3c8 100644 Binary files a/locale/en/LC_MESSAGES/django.mo and b/locale/en/LC_MESSAGES/django.mo differ diff --git a/locale/en/LC_MESSAGES/django.po b/locale/en/LC_MESSAGES/django.po index 3f53e36d..50dbc597 100644 --- a/locale/en/LC_MESSAGES/django.po +++ b/locale/en/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2010-02-22 22:59-0500\n" +"POT-Creation-Date: 2010-02-28 21:53-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -362,6 +362,22 @@ msgstr "" msgid "email update sent to user" msgstr "" +#: forum/const.py:78 +msgid "question_answered" +msgstr "answer" + +#: forum/const.py:79 +msgid "question_commented" +msgstr "question comment" + +#: forum/const.py:80 +msgid "answer_commented" +msgstr "answer comment" + +#: forum/const.py:81 +msgid "answer_accepted" +msgstr "answer accepted" + #: forum/const.py:85 msgid "[closed]" msgstr "" @@ -749,7 +765,7 @@ msgstr "" #: forum/middleware/anon_user.py:33 #, python-format msgid "first time greeting with %(url)s" -msgstr "" +msgstr "Hello and welcome to OSQA - please join us!" #: forum/models/question.py:247 #, python-format @@ -2401,7 +2417,7 @@ msgstr[1] "" #, python-format msgid "" "\n" -" have total %(q_num)s questions\n" +" have total %(q_num)s question\n" " " msgid_plural "" "\n" -- cgit v1.2.3-1-g7c22