Mercurial > public > sg101
annotate potd/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 | 7a795ccd6479 |
children |
rev | line source |
---|---|
bgneal@532 | 1 """ |
bgneal@532 | 2 Signal handlers for the potd application. |
bgneal@532 | 3 |
bgneal@532 | 4 """ |
bgneal@532 | 5 from django.db.models.signals import post_save, post_delete |
bgneal@532 | 6 |
bgneal@532 | 7 from potd.models import Photo, Sequence |
bgneal@532 | 8 |
bgneal@532 | 9 |
bgneal@532 | 10 def on_photo_save(sender, **kwargs): |
bgneal@532 | 11 """ |
bgneal@532 | 12 This function is executed when a Photo is saved. It inserts the photo into |
bgneal@532 | 13 the current sequence. |
bgneal@532 | 14 |
bgneal@532 | 15 """ |
bgneal@532 | 16 photo = kwargs['instance'] |
bgneal@532 | 17 Sequence.objects.insert_photo(photo.pk) |
bgneal@532 | 18 |
bgneal@532 | 19 |
bgneal@532 | 20 def on_photo_delete(sender, **kwargs): |
bgneal@532 | 21 """ |
bgneal@532 | 22 This function is executed when a Photo is deleted. It removes the photo from |
bgneal@532 | 23 the current sequence of photos. |
bgneal@532 | 24 |
bgneal@532 | 25 """ |
bgneal@532 | 26 photo = kwargs['instance'] |
bgneal@532 | 27 Sequence.objects.remove_photo(photo.pk) |
bgneal@532 | 28 |
bgneal@532 | 29 |
bgneal@935 | 30 post_save.connect(on_photo_save, sender=Photo, dispatch_uid='potd.receivers') |
bgneal@935 | 31 post_delete.connect(on_photo_delete, sender=Photo, dispatch_uid='potd.receivers') |