Mercurial > public > sg101
annotate gpp/membermap/signals.py @ 260:3a4bbf9c2cce
Fixing #107. Apparently some signal handlers were getting connected twice (double import?) and thus saving a forum post would cause 2 email notifications to go out to the post topic's subscribers. Use the dispatch_uid parameter in the connect call to work around this issue.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 22 Sep 2010 00:24:59 +0000 |
parents | 0140ff687d49 |
children | 6f3beff3ac63 |
rev | line source |
---|---|
gremmie@1 | 1 """ |
gremmie@1 | 2 Signal handlers for the membermap application. |
gremmie@1 | 3 We want to detect changes to the UserProfile model. If that person is on |
gremmie@1 | 4 the map, re-save her MapEntry so that any avatar changes get picked up. |
gremmie@1 | 5 """ |
gremmie@1 | 6 from django.db.models.signals import post_save |
gremmie@1 | 7 from bio.models import UserProfile |
gremmie@1 | 8 from membermap.models import MapEntry |
gremmie@1 | 9 |
gremmie@1 | 10 |
gremmie@1 | 11 def on_profile_save(sender, **kwargs): |
bgneal@260 | 12 import pdb; pdb.set_trace() |
gremmie@1 | 13 if 'instance' in kwargs: |
gremmie@1 | 14 profile = kwargs['instance'] |
bgneal@46 | 15 try: |
bgneal@46 | 16 map_entry = MapEntry.objects.get(user=profile.user) |
bgneal@46 | 17 except MapEntry.DoesNotExist: |
bgneal@46 | 18 # Not on the map, no harm, no foul |
bgneal@46 | 19 return |
gremmie@1 | 20 if map_entry is not None: |
gremmie@1 | 21 map_entry.save() |
gremmie@1 | 22 |
gremmie@1 | 23 |
bgneal@260 | 24 post_save.connect(on_profile_save, |
bgneal@260 | 25 sender=UserProfile, |
bgneal@260 | 26 dispatch_uid='membermap.signals') |