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
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
-{% 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
{% 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>
<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 %}
<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>
-{% 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
-{% 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
-{% 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
{% 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
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
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
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
\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
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
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')