annotate gpp/bio/signals.py @ 402:9175392da056

Fixing #198; add a media player to the podcast pages.
author Brian Neal <bgneal@gmail.com>
date Sun, 27 Mar 2011 01:51:18 +0000
parents 47f4259ce511
children d83296cac940
rev   line source
bgneal@44 1 """
bgneal@44 2 Signal handler(s) for the bio application.
bgneal@44 3 """
bgneal@44 4 from django.db.models.signals import post_save
bgneal@44 5 from django.contrib.auth.models import User
bgneal@204 6
bgneal@204 7 import bio.badges
bgneal@44 8 from bio.models import UserProfile
bgneal@204 9 from donations.models import Donation
bgneal@204 10 from weblinks.models import Link
bgneal@204 11 from downloads.models import Download
bgneal@204 12 from news.models import Story
bgneal@400 13 from potd.models import Photo
bgneal@204 14
bgneal@44 15
bgneal@44 16 def on_user_save(sender, **kwargs):
bgneal@44 17 """
bgneal@44 18 This signal handler ensures that every User has a corresonding
bgneal@44 19 UserProfile. It is called after User instance is saved. It creates
bgneal@44 20 a UserProfile for the User if the created argument is True.
bgneal@400 21
bgneal@44 22 """
bgneal@44 23 created = kwargs['created']
bgneal@44 24 if created:
bgneal@44 25 user = kwargs['instance']
bgneal@204 26 profile = bio.models.UserProfile()
bgneal@44 27 profile.user = user
bgneal@44 28 profile.save()
bgneal@44 29
bgneal@44 30
bgneal@204 31 def on_donation_save(sender, **kwargs):
bgneal@400 32 """
bgneal@400 33 This function is called after a Donation is saved.
bgneal@204 34 If the Donation was newly created and not anonymous,
bgneal@204 35 award the user a contributor pin.
bgneal@400 36
bgneal@204 37 """
bgneal@204 38 if kwargs['created']:
bgneal@204 39 donation = kwargs['instance']
bgneal@204 40 if not donation.is_anonymous and donation.user:
bgneal@204 41 bio.badges.award_badge(bio.badges.CONTRIBUTOR_PIN, donation.user)
bgneal@204 42
bgneal@204 43
bgneal@204 44 def on_link_save(sender, **kwargs):
bgneal@400 45 """
bgneal@400 46 This function is called after a Link is saved. If the Link was newly
bgneal@204 47 created, award the user a link pin.
bgneal@400 48
bgneal@204 49 """
bgneal@204 50 if kwargs['created']:
bgneal@204 51 link = kwargs['instance']
bgneal@204 52 bio.badges.award_badge(bio.badges.LINK_PIN, link.user)
bgneal@204 53
bgneal@204 54
bgneal@204 55 def on_download_save(sender, **kwargs):
bgneal@400 56 """
bgneal@400 57 This function is called after a Download is saved. If the Download was
bgneal@204 58 newly created, award the user a download pin.
bgneal@400 59
bgneal@204 60 """
bgneal@204 61 if kwargs['created']:
bgneal@204 62 download = kwargs['instance']
bgneal@204 63 bio.badges.award_badge(bio.badges.DOWNLOAD_PIN, download.user)
bgneal@204 64
bgneal@204 65
bgneal@204 66 def on_story_save(sender, **kwargs):
bgneal@400 67 """
bgneal@400 68 This function is called after a Story is saved. If the Story was
bgneal@204 69 newly created, award the user a news pin.
bgneal@400 70
bgneal@204 71 """
bgneal@204 72 if kwargs['created']:
bgneal@204 73 story = kwargs['instance']
bgneal@204 74 bio.badges.award_badge(bio.badges.NEWS_PIN, story.submitter)
bgneal@204 75
bgneal@204 76
bgneal@400 77 def on_photo_save(sender, **kwargs):
bgneal@400 78 """
bgneal@400 79 This function is called after a Photo is saved. If the Photo was
bgneal@400 80 newly created, award the user a POTD pin.
bgneal@400 81
bgneal@400 82 """
bgneal@400 83 if kwargs['created']:
bgneal@400 84 photo = kwargs['instance']
bgneal@400 85 bio.badges.award_badge(bio.badges.POTD_PIN, photo.user)
bgneal@400 86
bgneal@400 87
bgneal@260 88 post_save.connect(on_user_save, sender=User, dispatch_uid='bio.signals')
bgneal@260 89 post_save.connect(on_donation_save, sender=Donation, dispatch_uid='bio.signals')
bgneal@260 90 post_save.connect(on_link_save, sender=Link, dispatch_uid='bio.signals')
bgneal@260 91 post_save.connect(on_download_save, sender=Download, dispatch_uid='bio.signals')
bgneal@260 92 post_save.connect(on_story_save, sender=Story, dispatch_uid='bio.signals')
bgneal@400 93 post_save.connect(on_photo_save, sender=Photo, dispatch_uid='bio.signals')