annotate gpp/legacy/management/commands/fix_potd_smiles.py @ 552:9e42e6618168

For bitbucket issue #2, tweak the admin settings for the Post model to reduce slow queries. Define our own queryset() method so we can control the select_related(), and not have it cascade from post to topics to forums to categories. Removed 'topic' from list_display because MySQL still sucked with 2 inner joins. Now it seems to be tolerable with only one join to User.
author Brian Neal <bgneal@gmail.com>
date Wed, 25 Jan 2012 20:07:03 -0600
parents 97593a955291
children
rev   line source
bgneal@538 1 """
bgneal@538 2 This command fixes the old 1.0 smiley system to match the new scheme.
bgneal@538 3
bgneal@538 4 """
bgneal@538 5 from django.core.management.base import NoArgsCommand
bgneal@538 6 from comments.models import Comment
bgneal@538 7
bgneal@538 8
bgneal@538 9 SMILEY_MAP = {
bgneal@538 10 ':confused:': ':?',
bgneal@538 11 ':upset:': ':argh:',
bgneal@538 12 ':eek:': ':shock:',
bgneal@538 13 ':rolleyes:': ':whatever:',
bgneal@538 14 ':mad:': 'X-(',
bgneal@538 15 ':shy:': ':oops:',
bgneal@538 16 ':laugh:': ':lol:',
bgneal@538 17 ':dead:': 'x_x',
bgneal@538 18 ':cry:': ':-(',
bgneal@538 19 ';)': ':wink:',
bgneal@538 20 ':|': ':-|',
bgneal@538 21 ';-)': ':wink:',
bgneal@538 22 ':D': ':-D',
bgneal@538 23 ':P': ':-P',
bgneal@538 24 'B)': '8)',
bgneal@538 25 ':(': ':-(',
bgneal@538 26 ':)': ':-)',
bgneal@538 27 }
bgneal@538 28
bgneal@538 29
bgneal@538 30 class Command(NoArgsCommand):
bgneal@538 31
bgneal@538 32 def handle_noargs(self, **opts):
bgneal@538 33
bgneal@538 34 comments = Comment.objects.filter(id__gt=3000)
bgneal@538 35 for comment in comments:
bgneal@538 36 save = False
bgneal@538 37 for key, val in SMILEY_MAP.items():
bgneal@538 38 if key in comment.comment:
bgneal@538 39 comment.comment = comment.comment.replace(key, val)
bgneal@538 40 save = True
bgneal@538 41
bgneal@538 42 if save:
bgneal@538 43 comment.save()
bgneal@538 44