Commit 7c7a77c6 authored by stef's avatar stef

Merge git://github.com/tOkeshu/nnmon

Conflicts:
	bt/views.py
parents 2fb168cb 16b3d7f5
...@@ -7,6 +7,7 @@ from django.core.servers.basehttp import FileWrapper ...@@ -7,6 +7,7 @@ from django.core.servers.basehttp import FileWrapper
from django.conf import settings from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -14,7 +15,7 @@ from django.db.models import Count ...@@ -14,7 +15,7 @@ from django.db.models import Count
from models import Violation, Attachment, Comment, Confirmation, COUNTRIES, STATUS from models import Violation, Attachment, Comment, Confirmation, COUNTRIES, STATUS
from tempfile import mkstemp from tempfile import mkstemp
from datetime import datetime from datetime import datetime
import hashlib, os, re, json, smtplib import hashlib, os, re, json
from random import randint from random import randint
from email.mime.text import MIMEText from email.mime.text import MIMEText
from email.header import Header from email.header import Header
...@@ -57,14 +58,15 @@ def activate(request): ...@@ -57,14 +58,15 @@ def activate(request):
actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest() actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest()
to=[x.email for x in User.objects.filter(groups__name='moderator')] to=[x.email for x in User.objects.filter(groups__name='moderator')]
details='\n'.join(["%s: %s" % (k.capitalize(), val) for k,val in v.__dict__.items() if not k.startswith('_') and val]) details='\n'.join(["%s: %s" % (k.capitalize(), val) for k,val in v.__dict__.items() if not k.startswith('_') and val])
msg = MIMEText("A new report was submitted. To approve click here: %s/moderate/?key=%s\n\nDetails follow:\n%s\n%s" %
(settings.ROOT_URL or 'http://localhost:8001/', actid, details, v.comment_set.get().comment), _charset="utf-8") msg = {'from': 'nnmon@respectmynet.eu',
msg['Subject'] = 'NNMon submission approval'.encode("Utf-8") 'to': to,
msg['From'] = 'nnmon@respectmynet.eu' 'subject': 'NNMon submission approval'.encode("Utf-8"),
msg['To'] = ', '.join(to) 'body': "A new report was submitted. To approve click here: %s/moderate/?key=%s\n\nDetails follow:\n%s\n%s" %
s = smtplib.SMTP('localhost') (settings.ROOT_URL or 'http://localhost:8001/', actid, details, v.comment_set.get().comment)
s.sendmail('nnmon@respectmynet.eu', to, msg.as_string()) }
s.quit() send_mail(msg['subject'], msg['body'], msg['from'], msg['to'], fail_silently=False)
v.activationid=actid v.activationid=actid
v.save() v.save()
messages.add_message(request, messages.INFO, _('Thank you for verifying your submission. It will be listed shortly, after we\'ve checked that the report is valid.').encode("Utf-8")) messages.add_message(request, messages.INFO, _('Thank you for verifying your submission. It will be listed shortly, after we\'ve checked that the report is valid.').encode("Utf-8"))
...@@ -82,12 +84,14 @@ def moderate(request): ...@@ -82,12 +84,14 @@ def moderate(request):
if request.GET.get('action','')=='approve': if request.GET.get('action','')=='approve':
messages.add_message(request, messages.INFO, _('Thank you for approving the <a href="%s">submission</a>.' % v.get_absolute_url)) messages.add_message(request, messages.INFO, _('Thank you for approving the <a href="%s">submission</a>.' % v.get_absolute_url))
msg = MIMEText(_("Your report has been approved.\nTo see it, please visit: %s%s") % (settings.ROOT_URL or 'http://localhost:8001/', v.get_absolute_url()), _charset="utf-8") msg = {'from': 'nnmon@respectmynet.eu',
msg['Subject'] = Header(_('NNMon submission approved').encode("Utf-8"), 'utf-8') 'to': [v.comment_set.get().submitter_email],
msg['From'] = 'nnmon@respectmynet.eu' 'subject': _('NNMon submission approved').encode("Utf-8"),
msg['To'] = v.comment_set.get().submitter_email 'body': _("Your report has been approved.\nTo see it, please visit: %s/view/%s") %
s = smtplib.SMTP('localhost') (settings.ROOT_URL or 'http://localhost:8001/', v.get_absolute_url())
s.sendmail('nnmon@respectmynet.eu', [msg['To']], msg.as_string()) }
send_mail(msg['subject'], msg['body'], msg['from'], msg['to'], fail_silently=False)
s.quit() s.quit()
if settings.TWITTER_API: if settings.TWITTER_API:
try: try:
...@@ -126,13 +130,13 @@ def confirm(request, id, name=None): ...@@ -126,13 +130,13 @@ def confirm(request, id, name=None):
def sendverifymail(service,to,msg): def sendverifymail(service,to,msg):
actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest() actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest()
msg = MIMEText(msg % (settings.ROOT_URL or 'http://localhost:8001/', service, actid), _charset="utf-8") msg = {'from': 'nnmon@respectmynet.eu',
msg['Subject'] = Header(_('NNMon submission verification').encode("Utf-8"), 'utf-8') 'to': [to.encode("Utf-8")],
msg['From'] = 'nnmon@respectmynet.eu' 'subject': _('NNMon submission verification').encode("Utf-8"),
msg['To'] = Header(to.encode("Utf-8"), 'utf-8') 'body': msg % (settings.ROOT_URL or 'http://localhost:8001/', service, actid),
s = smtplib.SMTP('localhost') }
s.sendmail('nnmon@respectmynet.eu', [to], msg.as_string()) send_mail(msg['subject'], msg['body'], msg['from'], msg['to'], fail_silently=False)
s.quit()
return actid return actid
def add(request): def add(request):
......
Reading emails in development mode
==================================
In development mode, emails are written in `/tmp/app-messages/`.
To find the last sent email use your funcky `ls` command:
ls -ltr
...@@ -174,6 +174,10 @@ LOGGING = { ...@@ -174,6 +174,10 @@ LOGGING = {
} }
} }
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend'
EMAIL_FILE_PATH = '/tmp/app-messages'
TINYMCE_COMPRESSOR = True TINYMCE_COMPRESSOR = True
SESSION_ENGINE = 'django.contrib.sessions.backends.file' SESSION_ENGINE = 'django.contrib.sessions.backends.file'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment