annotate forums/receivers.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 |
5902dc5e58a3 |
children |
|
rev |
line source |
bgneal@75
|
1 """
|
bgneal@920
|
2 Signal handlers for the forums application.
|
bgneal@469
|
3
|
bgneal@75
|
4 """
|
bgneal@75
|
5 from django.db.models.signals import post_save
|
bgneal@75
|
6 from django.db.models.signals import post_delete
|
bgneal@181
|
7
|
bgneal@348
|
8 from forums.models import Forum, Topic, Post
|
bgneal@920
|
9 import forums.latest
|
bgneal@75
|
10
|
bgneal@75
|
11
|
bgneal@75
|
12 def on_topic_save(sender, **kwargs):
|
bgneal@75
|
13 if kwargs['created']:
|
bgneal@75
|
14 topic = kwargs['instance']
|
bgneal@75
|
15 topic.forum.topic_count_update()
|
bgneal@75
|
16 topic.forum.save()
|
bgneal@75
|
17
|
bgneal@75
|
18
|
bgneal@75
|
19 def on_topic_delete(sender, **kwargs):
|
bgneal@75
|
20 topic = kwargs['instance']
|
bgneal@75
|
21 topic.forum.topic_count_update()
|
bgneal@75
|
22 topic.forum.save()
|
bgneal@522
|
23 forums.latest.notify_topic_delete(topic)
|
bgneal@75
|
24
|
bgneal@75
|
25
|
bgneal@75
|
26 def on_post_save(sender, **kwargs):
|
bgneal@75
|
27 if kwargs['created']:
|
bgneal@75
|
28 post = kwargs['instance']
|
bgneal@75
|
29
|
bgneal@75
|
30 # update the topic
|
bgneal@75
|
31 post.topic.post_count_update()
|
bgneal@75
|
32 post.topic.save()
|
bgneal@75
|
33
|
bgneal@75
|
34 # update the forum
|
bgneal@75
|
35 post.topic.forum.post_count_update()
|
bgneal@75
|
36 post.topic.forum.save()
|
bgneal@75
|
37
|
bgneal@75
|
38
|
bgneal@75
|
39 def on_post_delete(sender, **kwargs):
|
bgneal@75
|
40 post = kwargs['instance']
|
bgneal@75
|
41
|
bgneal@75
|
42 # update the topic
|
bgneal@348
|
43 try:
|
bgneal@348
|
44 post.topic.post_count_update()
|
bgneal@348
|
45 post.topic.save()
|
bgneal@348
|
46 except Topic.DoesNotExist:
|
bgneal@348
|
47 pass
|
bgneal@348
|
48 else:
|
bgneal@348
|
49 # update the forum
|
bgneal@348
|
50 try:
|
bgneal@348
|
51 post.topic.forum.post_count_update()
|
bgneal@348
|
52 post.topic.forum.save()
|
bgneal@348
|
53 except Forum.DoesNotExist:
|
bgneal@348
|
54 pass
|
bgneal@75
|
55
|
bgneal@75
|
56
|
bgneal@920
|
57 post_save.connect(on_topic_save, sender=Topic, dispatch_uid='forums.receivers')
|
bgneal@920
|
58 post_delete.connect(on_topic_delete, sender=Topic, dispatch_uid='forums.receivers')
|
bgneal@920
|
59 post_save.connect(on_post_save, sender=Post, dispatch_uid='forums.receivers')
|
bgneal@920
|
60 post_delete.connect(on_post_delete, sender=Post, dispatch_uid='forums.receivers')
|