~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to check_input/management/commands/send_suspicious_mail.py

  • Committer: franku
  • Date: 2017-11-30 15:53:56 UTC
  • mfrom: (476.1.12 spam_fight)
  • Revision ID: somal@arcor.de-20171130155356-gcx9f8krnkvf6v0y
mergedĀ theĀ anti_spam_app

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from django.core.management.base import BaseCommand
2
 
from pybb.models import Post
 
2
from check_input.models import SuspiciousInput
3
3
from django.core.mail import send_mail
4
4
from django.conf import settings
5
5
from django.contrib.sites.models import Site
 
6
from django.contrib.contenttypes.models import ContentType
6
7
 
7
8
 
8
9
class Command(BaseCommand):
9
 
    help = 'Send emails if hidden posts are found'
 
10
    help = 'Send email if suspicious content is found'
10
11
 
11
12
    def handle(self, *args, **options):
12
 
        hidden_posts = Post.objects.filter(hidden=True)
13
 
 
14
 
        if hidden_posts:
15
 
            message = 'There were %d hidden posts found:' % len(hidden_posts)
16
 
            for post in hidden_posts:
17
 
                message += '\n' + post.user.username + \
18
 
                    ': ' + post.body_text[:70]
19
 
 
20
 
            message += '\n\nAdmin page: ' + Site.objects.get_current().domain + \
21
 
                '/admin/pybb/post/'
 
13
        spams = SuspiciousInput.objects.all()
 
14
        if spams:
 
15
            message = 'There were %d hidden posts found:' % len(spams)
 
16
    
 
17
            for spam in spams:
 
18
                app = ContentType.objects.get_for_id(
 
19
                    spam.content_type_id)
 
20
                message += '\nIn %s/%s: ' % (app.app_label, app.model)
 
21
                message += '\n User \'%s\' wrote: %s' % (spam.user, spam.text)
 
22
    
 
23
            message += '\n\nAdmin page: https://%s/admin/pybb/post/' % Site.objects.get_current().domain
22
24
            recipients = [addr[1] for addr in settings.ADMINS]
23
 
            send_mail('Hidden posts were found', message, 'pybb@widelands.org',
 
25
            send_mail('Hidden posts were found', message, 'admins@widelands.org',
24
26
                      recipients, fail_silently=False)