# HG changeset patch # User Brian Neal # Date 1301174967 0 # Node ID 47f4259ce51197068aa30489d56e80d88cb7975c # Parent 24f1230f3ee3e8c534f0e3f40bed9ef0cb121334 Fixing #197; add a badge for photo of the day. diff -r 24f1230f3ee3 -r 47f4259ce511 gpp/bio/badges.py --- a/gpp/bio/badges.py Sat Mar 26 03:08:05 2011 +0000 +++ b/gpp/bio/badges.py Sat Mar 26 21:29:27 2011 +0000 @@ -7,7 +7,7 @@ # Numeric ID's for badges that are awarded for user actions: (CONTRIBUTOR_PIN, CALENDAR_PIN, NEWS_PIN, LINK_PIN, DOWNLOAD_PIN, - SECURITY_PIN) = range(6) + SECURITY_PIN, POTD_PIN) = range(7) def award_badge(badge_id, user): @@ -33,3 +33,5 @@ # Already have this badge bo.count += 1 bo.save() + + logging.info('Awarded %s with the badge: %s', user.username, badge.name) diff -r 24f1230f3ee3 -r 47f4259ce511 gpp/bio/fixtures/badges.json --- a/gpp/bio/fixtures/badges.json Sat Mar 26 03:08:05 2011 +0000 +++ b/gpp/bio/fixtures/badges.json Sat Mar 26 21:29:27 2011 +0000 @@ -66,12 +66,23 @@ } }, { + "pk": 10, + "model": "bio.badge", + "fields": { + "numeric_id": 6, + "image": "badges/camera.png", + "order": 6, + "name": "POTD Pin", + "description": "For submitting a photo of the day." + } + }, + { "pk": 1, "model": "bio.badge", "fields": { "numeric_id": 100, "image": "badges/award_star_bronze_1.png", - "order": 6, + "order": 7, "name": "Bronze Star", "description": "For service to the site and community." } @@ -82,7 +93,7 @@ "fields": { "numeric_id": 101, "image": "badges/award_star_silver_2.png", - "order": 7, + "order": 8, "name": "Silver Star", "description": "For distinguished and dedicated service to the site and community." } @@ -93,7 +104,7 @@ "fields": { "numeric_id": 102, "image": "badges/award_star_gold_3.png", - "order": 8, + "order": 9, "name": "Gold Star", "description": "For exceptional and meritorious service to the site and community." } diff -r 24f1230f3ee3 -r 47f4259ce511 gpp/bio/signals.py --- a/gpp/bio/signals.py Sat Mar 26 03:08:05 2011 +0000 +++ b/gpp/bio/signals.py Sat Mar 26 21:29:27 2011 +0000 @@ -10,6 +10,7 @@ from weblinks.models import Link from downloads.models import Download from news.models import Story +from potd.models import Photo def on_user_save(sender, **kwargs): @@ -17,6 +18,7 @@ This signal handler ensures that every User has a corresonding UserProfile. It is called after User instance is saved. It creates a UserProfile for the User if the created argument is True. + """ created = kwargs['created'] if created: @@ -27,9 +29,11 @@ def on_donation_save(sender, **kwargs): - """This function is called after a Donation is saved. + """ + This function is called after a Donation is saved. If the Donation was newly created and not anonymous, award the user a contributor pin. + """ if kwargs['created']: donation = kwargs['instance'] @@ -38,8 +42,10 @@ def on_link_save(sender, **kwargs): - """This function is called after a Link is saved. If the Link was newly + """ + This function is called after a Link is saved. If the Link was newly created, award the user a link pin. + """ if kwargs['created']: link = kwargs['instance'] @@ -47,8 +53,10 @@ def on_download_save(sender, **kwargs): - """This function is called after a Download is saved. If the Download was + """ + This function is called after a Download is saved. If the Download was newly created, award the user a download pin. + """ if kwargs['created']: download = kwargs['instance'] @@ -56,16 +64,30 @@ def on_story_save(sender, **kwargs): - """This function is called after a Story is saved. If the Story was + """ + This function is called after a Story is saved. If the Story was newly created, award the user a news pin. + """ if kwargs['created']: story = kwargs['instance'] bio.badges.award_badge(bio.badges.NEWS_PIN, story.submitter) +def on_photo_save(sender, **kwargs): + """ + This function is called after a Photo is saved. If the Photo was + newly created, award the user a POTD pin. + + """ + if kwargs['created']: + photo = kwargs['instance'] + bio.badges.award_badge(bio.badges.POTD_PIN, photo.user) + + post_save.connect(on_user_save, sender=User, dispatch_uid='bio.signals') post_save.connect(on_donation_save, sender=Donation, dispatch_uid='bio.signals') post_save.connect(on_link_save, sender=Link, dispatch_uid='bio.signals') post_save.connect(on_download_save, sender=Download, dispatch_uid='bio.signals') post_save.connect(on_story_save, sender=Story, dispatch_uid='bio.signals') +post_save.connect(on_photo_save, sender=Photo, dispatch_uid='bio.signals')