annotate legacy/management/commands/fix_potd_smiles.py @ 943:cf9918328c64
Haystack tweaks for Django 1.7.7.
I had to upgrade to Haystack 2.3.1 to get it to work with Django
1.7.7. I also had to update the Xapian backend. But I ran into
problems.
On my laptop anyway (Ubuntu 14.0.4), xapian gets mad when search terms
are greater than 245 chars (or something) when indexing. So I created
a custom field that would simply omit terms greater than 64 chars and
used this field everywhere I previously used a CharField.
Secondly, the custom search form was broken now. Something changed in
the Xapian backend and exact searches stopped working. Fortunately the
auto_query (which I was using originally and broke during an upgrade)
started working again. So I cut the search form back over to doing an
auto_query. I kept the form the same (3 fields) because I didn't want
to change the form and I think it's better that way.
author |
Brian Neal <bgneal@gmail.com> |
date |
Wed, 13 May 2015 20:25:07 -0500 |
parents |
ee87ea74d46b |
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
|