def get_vote_count_today(self):\r
today = datetime.date.today()\r
return self.actions.filter(canceled=False, action_type__in=("voteup", "votedown"),\r
- action_date__range=(today - datetime.timedelta(days=1), today)).count()\r
+ action_date__gte=(today - datetime.timedelta(days=1))).count()\r
\r
def get_reputation_by_upvoted_today(self):\r
today = datetime.datetime.now()\r
def get_flagged_items_count_today(self):\r
today = datetime.date.today()\r
return self.actions.filter(canceled=False, action_type="flag",\r
- action_date__range=(today - datetime.timedelta(days=1), today)).count()\r
+ action_date__gte=(today - datetime.timedelta(days=1))).count()\r
\r
@true_if_is_super_or_staff\r
def can_view_deleted_post(self, post):\r
--- /dev/null
+{% load extra_filters extra_tags i18n email_tags %}
+
+{% declare %}
+ logo_location := os.path.join(str(settings.UPFILES_FOLDER), os.path.basename(str(settings.APP_LOGO)))
+{% enddeclare %}
+{% embedmedia logo_location as logo %}
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <style type="text/css">
+ body {
+ background: #FFF;
+ font-size: 12px;
+ line-height: 150%;
+ margin: 0;
+ padding: 0;
+ color: #000;
+ font-family: sans-serif;
+ }
+
+ #wrapper {
+ width: 600px;
+ margin: auto;
+ padding: 0;
+ }
+
+ a img {
+ border: none;
+ }
+ </style>
+ </head>
+ <body>
+ <a href="{% fullurl index %}">
+ <img src="cid:logo" title="{% trans "home" %}" alt="{{settings.APP_TITLE}} logo"/>
+ </a>
+ <br />
+ <p>{{ settings.APP_TITLE }}</p>
+ <br /><br />
+ <div id="wrapper">
+ <div id="room">
+ <div id="CALeft">
+ {% block content%}
+ {% endblock%}
+ </div>
+ </div>
+ <div class="spacer3"></div>
+ </div>
+ </body>
+</html>
\ No newline at end of file
-{% 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
+ question_author = question.author.username\r
+ app_url = settings.APP_URL\r
+ question_url = question.get_absolute_url()\r
+ question_title = question.title\r
+ question_tags = question.tagnames\r
+{% enddeclare %}\r
\r
- <p>\r
- {% blocktrans with question.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 and question.tagnames as question_tags %}\r
- {{ author_name }} has just posted a new question on {{ app_title }}, with title\r
- <a href="{{ app_url }}{{ question_url }}">{{ question_title }}</a> and tagged <em>{{ question_tags }}</em>:\r
+{% email %}\r
+ {% subject %}{% blocktrans %}{{ prefix }} New question on {{ app_name }}{% endblocktrans %}{% endsubject %}\r
+\r
+ {% htmlcontent notifications/base.html %}\r
+ <p>{% trans "Hello" %} {{ recipient.username }},</p>\r
+\r
+ <p>\r
+ {% blocktrans %}\r
+ {{ question_author }} has just posted a new question on {{ app_name }}, with title\r
+ <a href="{{ app_url }}{{ question_url }}">{{ question_title }}</a> and tagged <em>{{ question_tags }}</em>:\r
+ {% endblocktrans %}\r
+ </p>\r
+\r
+ <blockquote>\r
+ {{ question.html|safe }}\r
+ </blockquote>\r
+\r
+ <p>{% trans "Don't forget to come over and cast your vote." %}</p>\r
+\r
+ <p>{% blocktrans %}Sincerely,<br />\r
+ Forum Administrator{% endblocktrans %}</p>\r
+ {% endhtmlcontent %}\r
+\r
+ {% textcontent %}\r
+ {% trans "Hello" %} {{ recipient.username }}\r
+ \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
- </p>\r
\r
- <blockquote>\r
- {{ question.html|safe }}\r
- </blockquote>\r
\r
- <p>\r
- {% blocktrans %}\r
- Don't forget to come over and cast your vote.\r
- {% endblocktrans %}\r
- </p>\r
+ {{ question.body|safe }}\r
+\r
+\r
+ {% trans "Don't forget to come over and cast your vote." %}\r
+\r
+ {% blocktrans %}Sincerely,\r
+ Forum Administrator{% endblocktrans %}\r
+ {% endtextcontent %}\r
+{% endemail %}\r
\r
- <p>{% blocktrans %}Sincerely,<br />\r
- Forum Administrator{% endblocktrans %}</p>\r
-{% endblock %}\r
import re\r
import datetime\r
from forum.models import User, Question, Comment, QuestionSubscription, SubscriptionSettings, Answer\r
-from forum.utils.mail import send_email\r
+from forum.utils.mail import send_email, send_template_email\r
from django.utils.translation import ugettext as _\r
from forum.actions import AskAction, AnswerAction, CommentAction, AcceptAnswerAction, UserJoinsAction, QuestionViewAction\r
from forum import settings\r
def question_posted(action, new):\r
question = action.node\r
\r
- subscribers = User.objects.values('email', 'username').filter(\r
+ subscribers = User.objects.filter(\r
Q(subscription_settings__enable_notifications=True, subscription_settings__new_question='i') |\r
(Q(subscription_settings__new_question_watched_tags='i') &\r
Q(marked_tags__name__in=question.tagnames.split(' ')) &\r
Q(tag_selections__reason='good'))\r
).exclude(id=question.author.id).distinct()\r
\r
- recipients = create_recipients_dict(subscribers)\r
+ #recipients = create_recipients_dict(subscribers)\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
+ 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
from django import template
from forum import settings
+from forum.utils.mail import create_and_send_mail_messages
register = template.Library()
self.nodelist.render(context)
messages.append((recipient, context['subject'], context['htmlcontent'], context['textcontent'], context['embeddedmedia']))
- create_mail_messages(messages)
+ create_and_send_mail_messages(messages)
@register.tag
def email(parser, token):
return EmbedMediaNode(location, alias)
-from email.mime.multipart import MIMEMultipart
-from email.mime.text import MIMEText
-from email.mime.image import MIMEImage
-from django.core.mail import DNS_NAME
-from smtplib import SMTP
-import email.Charset
-import socket
-def create_mail_messages(messages):
- sender = '%s <%s>' % (unicode(settings.APP_SHORT_NAME), unicode(settings.DEFAULT_FROM_EMAIL))
-
- connection = SMTP(str(settings.EMAIL_HOST), str(settings.EMAIL_PORT),
- local_hostname=DNS_NAME.get_fqdn())
-
- try:
- if (bool(settings.EMAIL_USE_TLS)):
- connection.ehlo()
- connection.starttls()
- connection.ehlo()
-
- if settings.EMAIL_HOST_USER and settings.EMAIL_HOST_PASSWORD:
- connection.login(str(settings.EMAIL_HOST_USER), str(settings.EMAIL_HOST_PASSWORD))
-
- if sender is None:
- sender = str(settings.DEFAULT_FROM_EMAIL)
-
- for recipient, subject, html, text, media in messages:
- msgRoot = MIMEMultipart('related')
- msgRoot['Subject'] = subject
- msgRoot['From'] = sender
- msgRoot['To'] = '%s <%s>' % (recipient.username, recipient.email)
- msgRoot.preamble = 'This is a multi-part message from %s.' % unicode(settings.APP_SHORT_NAME).encode('utf8')
-
- msgAlternative = MIMEMultipart('alternative')
- msgRoot.attach(msgAlternative)
-
- msgAlternative.attach(MIMEText(text, _charset='utf-8'))
- msgAlternative.attach(MIMEText(html, 'html', _charset='utf-8'))
-
- for alias, location in media.items():
- fp = open(location, 'rb')
- msgImage = MIMEImage(fp.read())
- fp.close()
- msgImage.add_header('Content-ID', '<'+alias+'>')
- msgRoot.attach(msgImage)
-
- try:
- connection.sendmail(sender, [recipient.email], msgRoot.as_string())
- except Exception, e:
- pass
-
- try:
- connection.quit()
- except socket.sslerror:
- connection.close()
- except Exception, e:
- print e
import socket\r
import os\r
\r
-from email.MIMEMultipart import MIMEMultipart\r
-from email.MIMEText import MIMEText\r
-from email.MIMEImage import MIMEImage\r
+from email.mime.multipart import MIMEMultipart\r
+from email.mime.text import MIMEText\r
+from email.mime.image import MIMEImage\r
\r
from django.core.mail import DNS_NAME\r
from smtplib import SMTP\r
thread.setDaemon(True)\r
thread.start()\r
else:\r
- send_msg_list(msgs)
\ No newline at end of file
+ send_msg_list(msgs)\r
+\r
+\r
+def send_template_email(recipients, template, context):\r
+ t = loader.get_template(template)\r
+ context.update(dict(recipients=recipients, settings=settings))\r
+ t.render(Context(context))\r
+\r
+def create_and_send_mail_messages(messages):\r
+ sender = '%s <%s>' % (unicode(settings.APP_SHORT_NAME), unicode(settings.DEFAULT_FROM_EMAIL))\r
+\r
+ connection = SMTP(str(settings.EMAIL_HOST), str(settings.EMAIL_PORT),\r
+ local_hostname=DNS_NAME.get_fqdn())\r
+\r
+ try:\r
+ if (bool(settings.EMAIL_USE_TLS)):\r
+ connection.ehlo()\r
+ connection.starttls()\r
+ connection.ehlo()\r
+\r
+ if settings.EMAIL_HOST_USER and settings.EMAIL_HOST_PASSWORD:\r
+ connection.login(str(settings.EMAIL_HOST_USER), str(settings.EMAIL_HOST_PASSWORD))\r
+\r
+ if sender is None:\r
+ sender = str(settings.DEFAULT_FROM_EMAIL)\r
+\r
+ for recipient, subject, html, text, media in messages:\r
+ msgRoot = MIMEMultipart('related')\r
+ msgRoot['Subject'] = subject\r
+ msgRoot['From'] = sender\r
+ msgRoot['To'] = '%s <%s>' % (recipient.username, recipient.email)\r
+ msgRoot.preamble = 'This is a multi-part message from %s.' % unicode(settings.APP_SHORT_NAME).encode('utf8')\r
+\r
+ msgAlternative = MIMEMultipart('alternative')\r
+ msgRoot.attach(msgAlternative)\r
+\r
+ msgAlternative.attach(MIMEText(text, _charset='utf-8'))\r
+ msgAlternative.attach(MIMEText(html, 'html', _charset='utf-8'))\r
+\r
+ for alias, location in media.items():\r
+ fp = open(location, 'rb')\r
+ msgImage = MIMEImage(fp.read())\r
+ fp.close()\r
+ msgImage.add_header('Content-ID', '<'+alias+'>')\r
+ msgRoot.attach(msgImage)\r
+\r
+ try:\r
+ connection.sendmail(sender, [recipient.email], msgRoot.as_string())\r
+ except Exception, e:\r
+ pass\r
+\r
+ try:\r
+ connection.quit()\r
+ except socket.sslerror:\r
+ connection.close()\r
+ except Exception, e:\r
+ print e\r