]> git.openstreetmap.org Git - osqa.git/commitdiff
Converts all instant notifications to the new style emails.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 1 Jun 2010 23:35:25 +0000 (23:35 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 1 Jun 2010 23:35:25 +0000 (23:35 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@354 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/models/action.py
forum/settings/email.py
forum/skins/default/templates/notifications/answeraccepted.html
forum/skins/default/templates/notifications/base.html
forum/skins/default/templates/notifications/newanswer.html
forum/skins/default/templates/notifications/newcomment.html
forum/skins/default/templates/notifications/newmember.html
forum/skins/default/templates/notifications/newquestion.html
forum/subscriptions.py
forum/templatetags/extra_tags.py

index 7f9a7c189acf73817d9f64d72969b919ace2e072..07050a820243fc567b828d84aad017c01bdff189 100644 (file)
@@ -181,7 +181,9 @@ def trigger_hooks_threaded(action, hooks, new):
                 try:\r
                     hook(action=action, new=new)\r
                 except Exception, e:\r
+                    import traceback\r
                     logging.error("Error in %s hook: %s" % (cls.__name__, str(e)))\r
+                    logging.error(traceback.format_exc())\r
 \r
 class ActionProxyMetaClass(BaseMetaClass):\r
     types = {}\r
index d1a46c4b7ba457750644fb434843860fd29c8743..a4e18ed6749f5c0bd06716feff93aee2b486f06f 100644 (file)
@@ -40,4 +40,8 @@ label = _("Email subject prefix"),
 help_text = _("Every email sent through your website will have the subject prefixed by this string. It's usually a good idea to have such a prefix so your users can easilly set up a filter on theyr email clients."),\r
 required=False))\r
 \r
+EMAIL_CAN_SPAM = Setting(u'EMAIL_CAN_SPAM', '', EMAIL_SET, dict(\r
+label = _("Email Can Spam"),\r
+help_text = "Email Can Spam, usually the phisical address of the organization running the website. See <a href=\"http://en.wikipedia.org/wiki/CAN-SPAM_Act_of_2003\">http://en.wikipedia.org/wiki/CAN-SPAM_Act_of_2003</a> for more info."))\r
+\r
 EMAIL_DIGEST_CONTROL = Setting('EMAIL_DIGEST_CONTROL', None)\r
index 6c3404065be5e97016bc41e33a1a3060f7f23312..367a67f2539c6933ae8bf1efada486a1fc2510de 100644 (file)
@@ -1,23 +1,33 @@
-{% extends "email_base.html" %}\r
-{% load i18n %}\r
-{% load extra_tags %}\r
+{% load i18n extra_tags email_tags %}\r
 \r
-{% block content %}\r
-    {% var accepted_by = answer.nstate.accepted.by.username %}\r
-    {% var answer_author = answer.author.username %}\r
-    {% var app_url = settings.APP_URL %}\r
-    {% var question_url = question.get_absolute_url %}\r
-    {% var question_title = question.title %}\r
+{% declare %}\r
+    prefix = settings.EMAIL_SUBJECT_PREFIX\r
+    app_name = settings.APP_SHORT_NAME\r
+    app_url = settings.APP_URL\r
+    answer_author = answer.author.username\r
+    question = answer.question\r
+    question_url = question.get_absolute_url()\r
+    question_title = question.title\r
+    accepted_by = answer.nstate.accepted.by.username\r
+{% enddeclare %}\r
 \r
-    <p>{% trans "Hello" %} {% user_var username %},</p>\r
+{% email %}\r
+    {% subject %}{% blocktrans %}{{ prefix }} New answer to {{ question_title }}{% endblocktrans %}{% endsubject %}\r
 \r
-    <p>\r
+    {% htmlcontent notifications/base.html %}\r
+        <p style="{{ p_style }}">\r
+            {% blocktrans %}\r
+            {{ accepted_by }} has just accepted {{ answer_author }}'s answer on his question\r
+            <a href="{{ app_url }}{{ question_url }}">{{ question_title }}</a>.\r
+            {% endblocktrans %}\r
+        </p>\r
+    {% endhtmlcontent %}\r
+\r
+    {% textcontent notifications/base_text.html %}\r
         {% blocktrans %}\r
-        Just to let you know that {{ accepted_by }} has just accepted {{ answer_author }}'s answer on his question\r
-        <a href="{{ app_url }}{{ question_url }}">{{ question_title }}</a>:\r
+        {{ accepted_by }} has just accepted {{ answer_author }}'s answer on his question\r
+            "{{ question_title }}".\r
         {% endblocktrans %}\r
-    </p>\r
+    {% endtextcontent %}\r
 \r
-    <p>{% blocktrans %}Sincerely,<br />\r
-    Forum Administrator{% endblocktrans %}</p>\r
-{% endblock %}\r
+{% endemail %}\r
index 6879bc2992b4d1305a87a7ffb99cb5f07a6d9c6b..2b0cc05cfe5d40499fedbe1d195e0d98f9e0d2df 100644 (file)
@@ -1,13 +1,11 @@
 {% load extra_filters extra_tags i18n email_tags %}
 
 {% declare %}
-    logo_location = "http://meta.osqa.net/upfiles/osqa_logo.png"
     p_style = "color:#333333;font-family:'helvetica neue', arial, Helvetica, sans-serif;line-height:18px;font-size:14px;margin-top:10px;"
     a_style = "text-decoration:none;color:#3060a8;font-weight:bold;"
     hr_style = "color:#ccc;border:0;height:1px;background-color:#ccc;margin-bottom:20px;"
     small_style = "color:#333333;font-family:'Lucida Grande', Trebuchet, Helvetica, sans-serif;font-size:12px;"
     table_style = "border:20px #e5ebf8 solid;margin:10px auto 10px auto;width:750px;text-align:left;"
-    postal_address = "DZone, Inc. 140 Preston Executive Drive, Cary NC 27513, USA"
 {% enddeclare %}
 <html>
 <head>
@@ -16,7 +14,7 @@
 <center>
 <table style="{{ table_style }}">
 <tbody><tr><td style="padding:20px;">
-<img src="{{ logo_location }}" alt="{{settings.APP_TITLE}}" />
+<img src="{{ settings.APP_URL }}{{ settings.APP_LOGO }}" alt="{{settings.APP_TITLE}}" />
 <hr style="{{ hr_style }}" />
 <p style="{{ p_style }}">{% trans "Hello" %} {{ recipient.username }},</p>
 {% block content %}
@@ -26,7 +24,7 @@
 <a href="{{ settings.APP_URL }}{% url user_subscriptions id=recipient.id %}" style="{{ a_style }}">here</a>.
 </p>
 <hr style="{{ hr_style }}" />
-<p style="{{ p_style }}"><small style="{{ small_style }}">{{ postal_address }}</small></p>
+<p style="{{ p_style }}"><small style="{{ small_style }}">{{ settings.EMAIL_CAN_SPAM }}</small></p>
 </td></tr></tbody></table>
 </center>
 </body>
index 425f404a5b5fce196ace334afd1fde0365fbc1ae..50fe5040708a9f58e574f6e33e2be95f79b516ec 100644 (file)
@@ -1,27 +1,44 @@
-{% extends "email_base.html" %}\r
-{% load i18n %}\r
-{% load extra_tags %}\r
+{% load i18n extra_tags email_tags %}\r
 \r
-{% block content %}\r
-    <p>{% trans "Hello" %} {% user_var username %},</p>\r
+{% declare %}\r
+    prefix = settings.EMAIL_SUBJECT_PREFIX\r
+    app_name = settings.APP_SHORT_NAME\r
+    app_url = settings.APP_URL\r
+    answer_author = answer.author.username\r
+    question = answer.question\r
+    question_url = question.get_absolute_url()\r
+    question_title = question.title\r
+{% enddeclare %}\r
 \r
-    <p>\r
-        {% blocktrans with answer.author.username as author_name and settings.APP_SHORT_NAME as app_title and settings.APP_URL as app_url and question.get_absolute_url as question_url and question.title as question_title %}\r
-        {{ author_name }} has just posted a new answer on {{ app_title }} to the question\r
-        <a href="{{ app_url }}{{ question_url }}">{{ question_title }}"</a>:\r
-        {% endblocktrans %}\r
-    </p>\r
+{% email %}\r
+    {% subject %}{% blocktrans %}{{ prefix }} New answer to {{ question_title }}{% endblocktrans %}{% endsubject %}\r
+\r
+    {% htmlcontent notifications/base.html %}\r
+        <p style="{{ p_style }}">\r
+            {% blocktrans %}\r
+            {{ answer_author }} has just posted a new answer on {{ app_name }} to the question\r
+            <a href="{{ app_url }}{{ question_url }}">{{ question_title }}</a>:\r
+            {% endblocktrans %}\r
+        </p>\r
 \r
-    <blockquote>\r
+        <blockquote>\r
         {{ answer.html|safe }}\r
-    </blockquote>\r
+        </blockquote>\r
+\r
+        <p style="{{ p_style }}">{% trans "Don't forget to come over and cast your vote." %}</p>\r
+    {% endhtmlcontent %}\r
+\r
+    {% textcontent notifications/base_text.html %}\r
+        {% blocktrans %}\r
+        {{ answer_author }} has just posted a new answer on {{ app_name }} to the question\r
+            "{{ question_title }}":\r
+        {% endblocktrans %}\r
+\r
+\r
+        {{ answer.body|safe }}\r
+\r
+        {% trans "Don't forget to come over and cast your vote." %} \r
+    {% endtextcontent %}\r
 \r
-    <p>\r
-    {% blocktrans %}\r
-        Don't forget to come over and cast your vote.\r
-    {% endblocktrans %}\r
-    </p>\r
+{% endemail %}\r
 \r
-    <p>{% blocktrans %}Sincerely,<br />\r
-    Forum Administrator{% endblocktrans %}</p>\r
-{% endblock %}\r
index 30e3c6543a4406debab01af6384b0f8fee1bf313..6d59f1b95b9a88f6eacaa2653867ed1302729cdf 100644 (file)
@@ -1,34 +1,47 @@
-{% extends "email_base.html" %}\r
-{% load i18n %}\r
-{% load extra_tags %}\r
-\r
-{% block content %}\r
-    <p>{% trans "Hello" %} {% user_var username %},</p>\r
-\r
-    <p>\r
-        {% blocktrans with comment.user.username as author_name %}\r
-            {{ author_name }} has just posted a comment on\r
-        {% endblocktrans %}\r
-\r
-        {% if post.question %}\r
-            {% blocktrans with settings.APP_URL as app_url and post.author.username as poster_name and post.author.get_profile_url as poster_url%}\r
-                the answer posted by <a href="{{ app_url }}{{ poster_url }}">{{ poster_name }}</a> to\r
-            {% endblocktrans %}\r
-        {% endif %}\r
-\r
-        {% blocktrans with question.title as question_title and settings.APP_URL as app_url and question.get_absolute_url as question_url %}\r
-             the question  <a href="{{ app_url }}{{ question_url }}">{{ question_title }}</a>\r
-        {% endblocktrans %}\r
-    </p>\r
-\r
-    <blockquote>\r
+{% load i18n extra_tags email_tags %}\r
+\r
+{% declare %}\r
+    prefix = settings.EMAIL_SUBJECT_PREFIX\r
+    app_name = settings.APP_SHORT_NAME\r
+    app_url = settings.APP_URL\r
+    post = comment.parent\r
+    question = post.question and post.question or post\r
+    post_author = post.author.username\r
+    comment_author = comment.author\r
+    question_url = question.get_absolute_url()\r
+    question_title = question.title\r
+{% enddeclare %}\r
+\r
+{% email %}\r
+    {% subject %}{% blocktrans %}{{ prefix }} New comment on {{ question_title }}{% endblocktrans %}{% endsubject %}\r
+\r
+    {% htmlcontent notifications/base.html %}\r
+        <p style="{{ p_style }}">\r
+            {% blocktrans %}{{ comment_author }} has just posted a comment on {% endblocktrans %}\r
+            {% ifnotequal post question %}\r
+                {% blocktrans %}the answer posted by {{ post_author }} to {% endblocktrans %}\r
+            {% endifnotequal %}\r
+            {% blocktrans %}the question <a href="{{ app_url }}{{ question_url }}">{{ question_title }}</a>{% endblocktrans %}\r
+        </p>\r
+\r
+        <blockquote>\r
         {{ comment.comment }}\r
-    </blockquote>\r
+        </blockquote>\r
+\r
+        <p style="{{ p_style }}">{% trans "Don't forget to come over and cast your vote." %}</p>\r
+    {% endhtmlcontent %}\r
+\r
+    {% textcontent notifications/base_text.html %}\r
+        {% blocktrans %}{{ comment_author }} has just posted a comment on {% endblocktrans %}\r
+        {% ifnotequal post question %}\r
+            {% blocktrans %}the answer posted by {{ post_author }} to {% endblocktrans %}\r
+        {% endifnotequal %}\r
+        {% blocktrans %}the question "{{ question_title }}"{% endblocktrans %}\r
+\r
+\r
+        {{ comment.body }}\r
 \r
-    {% blocktrans %}\r
-        Don't forget to come over and cast your vote.\r
-    {% endblocktrans %}\r
+        {% trans "Don't forget to come over and cast your vote." %}\r
+    {% endtextcontent %}\r
 \r
-    <p>{% blocktrans %}Sincerely,<br />\r
-    Forum Administrator{% endblocktrans %}</p>\r
-{% endblock %}\r
+{% endemail %}\r
index 149b9a9d16bb6c48ae96f9b43a71a2ed9fe5c52e..528c3ac7b77298040567e9abec06abe58e63884e 100644 (file)
@@ -1,17 +1,31 @@
-{% extends "email_base.html" %}\r
-{% load i18n %}\r
-{% load extra_tags %}\r
+{% load i18n extra_tags email_tags %}\r
 \r
-{% block content %}\r
-    <p>{% trans "Hello" %} {% user_var username %},</p>\r
+{% declare %}\r
+    prefix = settings.EMAIL_SUBJECT_PREFIX\r
+    app_name = settings.APP_SHORT_NAME\r
+    app_url = settings.APP_URL\r
+    newmember_name = newmember.username\r
+    newmember_url = newmember.get_profile_url\r
+{% enddeclare %}\r
 \r
-    <p>\r
-        {% blocktrans with newmember.username as newmember_name and settings.APP_SHORT_NAME as app_title and settings.APP_URL as app_url and newmember.get_profile_url as newmember_url %}\r
-        {{ newmember_name }} has just joined {{ app_title }}. You can visit {{ newmember_name }}'s profile using the following link: <br />\r
-        <a href="{{ app_url }}{{ newmember_url }}">{{ newmember_name }} profile</a>\r
+{% email %}\r
+    {% subject %}{% blocktrans %}{{ newmember_name }} is a new member on {{ app_name }}{% endblocktrans %}{% endsubject %}\r
+\r
+    {% htmlcontent notifications/base.html %}\r
+        <p style="{{ p_style }}">\r
+            {% blocktrans %}\r
+            {{ newmember_name }} has just joined {{ app_name }}. You can visit {{ newmember_name }}'s profile using the following link: <br />\r
+            <a href="{{ app_url }}{{ newmember_url }}">{{ newmember_name }} profile</a>\r
+            {% endblocktrans %}\r
+        </p>\r
+    {% endhtmlcontent %}\r
+\r
+    {% textcontent notifications/base_text.html %}\r
+        {% blocktrans %}\r
+        {{ newmember_name }} has just joined {{ app_name }}. You can visit {{ newmember_name }}'s profile using the following url: <br />\r
+            {{ app_url }}{{ newmember_url }}\r
         {% endblocktrans %}\r
-    </p>\r
+    {% endtextcontent %}\r
+\r
+{% endemail %}\r
 \r
-    <p>{% blocktrans %}Sincerely,<br />\r
-    Forum Administrator{% endblocktrans %}</p>\r
-{% endblock %}\r
index 6615831806a2702fe70a10bf38a1030831ec0239..d9987e6a24c4d0171002523fa031d001bf218397 100644 (file)
     {% endhtmlcontent %}\r
 \r
 {% textcontent notifications/base_text.html %}\r
-{% blocktrans %}\r
-{{ question_author }} has just posted a new question on {{ app_name }}, with title\r
-"{{ question_title }}" and tagged {{ question_tags }}:\r
-{% endblocktrans %}\r
+    {% blocktrans %}\r
+        {{ question_author }} has just posted a new question on {{ app_name }}, with title\r
+        "{{ question_title }}" and tagged {{ question_tags }}:\r
+    {% endblocktrans %}\r
 \r
-{{ question.body|safe }}\r
+    {{ question.body|safe }}\r
 \r
-{% trans "Don't forget to come over and cast your vote." %}\r
+    {% trans "Don't forget to come over and cast your vote." %}\r
 {% endtextcontent %}\r
+\r
 {% endemail %}\r
 \r
index c808ce9af16d864cd4f9e63417d9654a04ba6d46..b361823f5ed8b024fb9753d4d905e7c676bf59fc 100644 (file)
@@ -15,12 +15,6 @@ def create_subscription_if_not_exists(question, user):
         subscription = QuestionSubscription(question=question, user=user)\r
         subscription.save()\r
 \r
-def apply_default_filters(queryset, excluded_id):\r
-    return queryset.values('email', 'username').exclude(id=excluded_id)\r
-\r
-def create_recipients_dict(usr_list):\r
-    return [(s['username'], s['email'], {'username': s['username']}) for s in usr_list]\r
-\r
 def question_posted(action, new):\r
     question = action.node\r
 \r
@@ -31,15 +25,8 @@ def question_posted(action, new):
               Q(tag_selections__reason='good'))\r
     ).exclude(id=question.author.id).distinct()\r
 \r
-    #recipients = create_recipients_dict(subscribers)\r
-\r
     send_template_email(subscribers, "notifications/newquestion.html", {'question': question})\r
 \r
-    #send_email(settings.EMAIL_SUBJECT_PREFIX + _("New question on %(app_name)s") % dict(app_name=settings.APP_SHORT_NAME),\r
-    #           recipients, "notifications/newquestion.html", {\r
-    #    'question': question,\r
-    #})\r
-\r
     if question.author.subscription_settings.questions_asked:\r
         subscription = QuestionSubscription(question=question, user=question.author)\r
         subscription.save()\r
@@ -60,18 +47,13 @@ def answer_posted(action, new):
     answer = action.node\r
     question = answer.question\r
 \r
-    subscribers = question.subscribers.values('email', 'username').filter(\r
+    subscribers = question.subscribers.filter(\r
             subscription_settings__enable_notifications=True,\r
             subscription_settings__notify_answers=True,\r
             subscription_settings__subscribed_questions='i'\r
     ).exclude(id=answer.author.id).distinct()\r
-    recipients = create_recipients_dict(subscribers)\r
 \r
-    send_email(settings.EMAIL_SUBJECT_PREFIX + _("New answer to '%(question_title)s'") % dict(question_title=question.title),\r
-               recipients, "notifications/newanswer.html", {\r
-        'question': question,\r
-        'answer': answer\r
-    }, threaded=False)\r
+    send_template_email(subscribers, "notifications/newanswer.html", {'answer': answer})\r
 \r
     if answer.author.subscription_settings.questions_answered:\r
         create_subscription_if_not_exists(question, answer.author)\r
@@ -81,37 +63,27 @@ AnswerAction.hook(answer_posted)
 \r
 def comment_posted(action, new):\r
     comment = action.node\r
-    post = comment.content_object\r
+    post = comment.parent\r
 \r
     if post.__class__ == Question:\r
         question = post\r
     else:\r
         question = post.question\r
 \r
-    subscribers = question.subscribers.values('email', 'username')\r
-\r
     q_filter = Q(subscription_settings__notify_comments=True) | Q(subscription_settings__notify_comments_own_post=True, id=post.author.id)\r
 \r
-    #inreply = re.search('@\w+', comment.comment)\r
-    #if inreply is not None:\r
-    #    q_filter = q_filter | Q(subscription_settings__notify_reply_to_comments=True,\r
-    #                            username__istartswith=inreply.group(0)[1:],\r
-    ##                            comments__object_id=post.id,\r
-    #                            comments__content_type=ContentType.objects.get_for_model(post.__class__)\r
-    #                            )\r
+    inreply = re.search('@\w+', comment.comment)\r
+    if inreply is not None:\r
+        q_filter = q_filter | Q(subscription_settings__notify_reply_to_comments=True,\r
+                                username__istartswith=inreply.group(0)[1:],\r
+                                nodes__parent=post, nodes__node_type="comment")\r
 \r
-    subscribers = subscribers.filter(\r
+    subscribers = question.subscribers.filter(\r
             q_filter, subscription_settings__subscribed_questions='i', subscription_settings__enable_notifications=True\r
     ).exclude(id=comment.user.id).distinct()\r
 \r
-    recipients = create_recipients_dict(subscribers)\r
 \r
-    send_email(settings.EMAIL_SUBJECT_PREFIX + _("New comment on %(question_title)s") % dict(question_title=question.title),\r
-               recipients, "notifications/newcomment.html", {\r
-                'comment': comment,\r
-                'post': post,\r
-                'question': question,\r
-    }, threaded=False)\r
+    send_template_email(subscribers, "notifications/newcomment.html", {'comment': comment})\r
 \r
     if comment.user.subscription_settings.questions_commented:\r
         create_subscription_if_not_exists(question, comment.user)\r
@@ -122,34 +94,24 @@ CommentAction.hook(comment_posted)
 def answer_accepted(action, new):\r
     question = action.node.question\r
 \r
-    subscribers = question.subscribers.values('email', 'username').filter(\r
+    subscribers = question.subscribers.filter(\r
             subscription_settings__enable_notifications=True,\r
             subscription_settings__notify_accepted=True,\r
             subscription_settings__subscribed_questions='i'\r
     ).exclude(id=action.node.nstate.accepted.by.id).distinct()\r
-    recipients = create_recipients_dict(subscribers)\r
 \r
-    send_email(settings.EMAIL_SUBJECT_PREFIX + _("An answer to '%(question_title)s' was accepted") % dict(question_title=question.title),\r
-               recipients, "notifications/answeraccepted.html", {\r
-        'question': question,\r
-        'answer': action.node\r
-    }, threaded=False)\r
+    send_template_email(subscribers, "notifications/answeraccepted.html", {'answer': action.node})\r
 \r
 AcceptAnswerAction.hook(answer_accepted)\r
 \r
 \r
 def member_joined(action, new):\r
-    subscribers = User.objects.values('email', 'username').filter(\r
+    subscribers = User.objects.filter(\r
             subscription_settings__enable_notifications=True,\r
             subscription_settings__member_joins='i'\r
     ).exclude(id=action.user.id).distinct()\r
 \r
-    recipients = create_recipients_dict(subscribers)\r
-\r
-    send_email(settings.EMAIL_SUBJECT_PREFIX + _("%(username)s is a new member on %(app_name)s") % dict(username=action.user.username, app_name=settings.APP_SHORT_NAME),\r
-               recipients, "notifications/newmember.html", {\r
-        'newmember': action.user,\r
-    }, threaded=False)\r
+    send_template_email(subscribers, "notifications/newmember.html", {'newmember': action.user})\r
 \r
 UserJoinsAction.hook(member_joined)\r
 \r
index 9499a3f76f1c6422729fc5c661e2e9c6203ed8cc..7600bf4651b7ec0e925f884c8644e542cb6c9474 100644 (file)
@@ -427,7 +427,11 @@ class DeclareNode(template.Node):
                 d['os'] = os
                 for c in clist:
                     d.update(c)
-                context[m.group(1).strip()] = eval(m.group(3).strip(), d)
+                try:
+                    context[m.group(1).strip()] = eval(m.group(3).strip(), d)
+                except Exception, e:
+                    logging.error("Error in declare tag, when evaluating: %s" % m.group(3).strip())
+                    raise
         return ''
 
 @register.tag(name='declare')