wired badge awarding into pledge modified and pledge complete signals
parent
33e652881c
commit
759e39f61d
|
@ -944,6 +944,18 @@ class Wishes(models.Model):
|
|||
class Meta:
|
||||
db_table = 'core_wishlist_works'
|
||||
|
||||
class Badge(models.Model):
|
||||
name = models.CharField(max_length=72, blank=True)
|
||||
description = models.TextField(default='', null=True)
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return '/static/images/%s.png' % self.name
|
||||
|
||||
|
||||
pledger= Badge.objects.get(name='pledger')
|
||||
pledger2= Badge.objects.get(name='pledger2')
|
||||
|
||||
class UserProfile(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
user = models.OneToOneField(User, related_name='profile')
|
||||
|
@ -959,16 +971,32 @@ class UserProfile(models.Model):
|
|||
goodreads_user_name = models.CharField(max_length=200, null=True, blank=True)
|
||||
goodreads_auth_token = models.TextField(null=True, blank=True)
|
||||
goodreads_auth_secret = models.TextField(null=True, blank=True)
|
||||
goodreads_user_link = models.CharField(max_length=200, null=True, blank=True)
|
||||
goodreads_user_link = models.CharField(max_length=200, null=True, blank=True)
|
||||
|
||||
def add_pledge_badge(self):
|
||||
#give user a badge
|
||||
if self.badges.all().count():
|
||||
if self.badges.all()[0].id == pledger.id:
|
||||
self.badges.remove(pledger)
|
||||
self.badges.add(pledger2)
|
||||
else:
|
||||
self.badges.add(pledger)
|
||||
|
||||
class Badge(models.Model):
|
||||
name = models.CharField(max_length=72, blank=True)
|
||||
description = models.TextField(default='', null=True)
|
||||
def reset_pledge_badge(self):
|
||||
#count user pledges
|
||||
n_pledges = self.pledge_count
|
||||
if self.badges.exists():
|
||||
self.badges.remove(pledger)
|
||||
self.badges.remove(pledger2)
|
||||
if n_pledges == 1:
|
||||
self.badges.add(pledger)
|
||||
elif n_pledges > 1:
|
||||
self.badges.add(pledger2)
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return '/static/images/%s.png' % self.name
|
||||
|
||||
def pledge_count(self):
|
||||
return self.user.transaction_set.exclude(status='NONE').exclude(status='Canceled',reason=None).exclude(anonymous=True).count()
|
||||
|
||||
#class CampaignSurveyResponse(models.Model):
|
||||
# # generic
|
||||
# campaign = models.ForeignKey("Campaign", related_name="surveyresponse", null=False)
|
||||
|
|
|
@ -177,6 +177,8 @@ def handle_pledge_modified(sender, transaction=None, up_or_down=None, **kwargs):
|
|||
# up_or_down is 'increased', 'decreased', or 'canceled'
|
||||
if transaction==None or up_or_down==None:
|
||||
return
|
||||
if up_or_down == 'canceled':
|
||||
transaction.user.profile.reset_pledge_badge()
|
||||
notification.queue([transaction.user], "pledge_status_change", {
|
||||
'site':Site.objects.get_current(),
|
||||
'transaction': transaction,
|
||||
|
@ -190,6 +192,10 @@ pledge_modified.connect(handle_pledge_modified)
|
|||
def handle_you_have_pledged(sender, transaction=None, **kwargs):
|
||||
if transaction==None:
|
||||
return
|
||||
|
||||
#give user a badge
|
||||
transaction.user.profile.add_pledge_badge()
|
||||
|
||||
notification.queue([transaction.user], "pledge_you_have_pledged", {
|
||||
'site':Site.objects.get_current(),
|
||||
'transaction': transaction
|
||||
|
|
|
@ -14,7 +14,6 @@ from regluit.payment.models import Transaction
|
|||
from regluit.core.models import Campaign, Wishlist, Work
|
||||
from regluit.core.signals import handle_transaction_charged
|
||||
from regluit.payment.parameters import *
|
||||
from regluit.payment.paypal import *
|
||||
import traceback
|
||||
from django.core.validators import URLValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
|
@ -352,6 +351,12 @@ class TransactionTest(TestCase):
|
|||
t.user = user
|
||||
t.save()
|
||||
|
||||
#test pledge adders
|
||||
user.profile.reset_pledge_badge()
|
||||
self.assertEqual(user.profile.badges.all()[0].name,'pledger')
|
||||
user.profile.add_pledge_badge()
|
||||
self.assertEqual(user.profile.badges.all()[0].name,'pledger2')
|
||||
|
||||
p = PaymentManager()
|
||||
results = p.query_campaign(c,campaign_total=True, summary=False)
|
||||
self.assertEqual(results[0].amount, D('12.34'))
|
||||
|
|
Loading…
Reference in New Issue