Blame view

dictionary/management/commands/remove_notes.py 851 Bytes
Bartłomiej Nitoń authored
1
2
3
4
5
6
7
8
9
#-*- coding:utf-8 -*-

"""Script for removing notes with specified text string."""

from django.core.management.base import BaseCommand

from dictionary.models import *

class Command(BaseCommand):
Bartłomiej Nitoń authored
10
    'Slowal command for removing messages with specified text string.'
Bartłomiej Nitoń authored
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    help = 'Remove messages with specified text string.'

    def handle(self, **options):
        remove_notes()  

def remove_notes():
    'Remove messages with specified text string.'
    print 'Be patient, it can take a while.'
    notes_to_remove = [u'.', u'bez komentarza.']
    for message in Message.objects.all():
        text = message.message_text.lower().strip()
        if text in notes_to_remove:
            print '!!!!!!!!!!delete!!!!!!!!!!!!'
            print message.sender
            print message.message_text
            message.delete()