comparison legacy/management/commands/fix_potd_smiles.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/legacy/management/commands/fix_potd_smiles.py@97593a955291
children
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """
2 This command fixes the old 1.0 smiley system to match the new scheme.
3
4 """
5 from django.core.management.base import NoArgsCommand
6 from comments.models import Comment
7
8
9 SMILEY_MAP = {
10 ':confused:': ':?',
11 ':upset:': ':argh:',
12 ':eek:': ':shock:',
13 ':rolleyes:': ':whatever:',
14 ':mad:': 'X-(',
15 ':shy:': ':oops:',
16 ':laugh:': ':lol:',
17 ':dead:': 'x_x',
18 ':cry:': ':-(',
19 ';)': ':wink:',
20 ':|': ':-|',
21 ';-)': ':wink:',
22 ':D': ':-D',
23 ':P': ':-P',
24 'B)': '8)',
25 ':(': ':-(',
26 ':)': ':-)',
27 }
28
29
30 class Command(NoArgsCommand):
31
32 def handle_noargs(self, **opts):
33
34 comments = Comment.objects.filter(id__gt=3000)
35 for comment in comments:
36 save = False
37 for key, val in SMILEY_MAP.items():
38 if key in comment.comment:
39 comment.comment = comment.comment.replace(key, val)
40 save = True
41
42 if save:
43 comment.save()
44