small optimization of supporter count

pull/1/head
eric 2012-07-07 16:38:23 -04:00
parent a7af78cc9a
commit 1764cd62d6
5 changed files with 10 additions and 4 deletions

View File

@ -316,6 +316,11 @@ class Campaign(models.Model):
"""nb: returns (distinct) supporter IDs, not supporter objects"""
translist = self.transactions().filter(status=TRANSACTION_STATUS_ACTIVE).values_list('user', flat=True).distinct()
return translist
@property
def supporters_count(self):
# avoid transmitting the whole list if you don't need to; let the db do the count.
return self.transactions().filter(status=TRANSACTION_STATUS_ACTIVE).values_list('user', flat=True).distinct().count()
def effective_premiums(self):
"""returns the available premiums for the Campaign including any default premiums"""

View File

@ -79,7 +79,7 @@ Please fix the following before launching your campaign:
<div class="pledged-info">
<div class="pledged-group">
{{ work.last_campaign.supporters.count }} Ungluers have pledged ${{ work.last_campaign.current_total|intcomma }}
{{ work.last_campaign.supporters_count }} Ungluers have pledged ${{ work.last_campaign.current_total|intcomma }}
</div>
<div class="status">
<img src="/static/images/images/icon-book-37by25-{{ work.percent_unglued }}.png" title="book list status" alt="book list status" />

View File

@ -37,7 +37,7 @@
<div class="pledged-info">
<div class="pledged-group">
{{ work.last_campaign.supporters.count }} Ungluers have pledged ${{ work.last_campaign.current_total|intcomma }}
{{ work.last_campaign.supporters_count }} Ungluers have pledged ${{ work.last_campaign.current_total|intcomma }}
</div>
<div class="status">
<img src="/static/images/images/icon-book-37by25-{{ work.percent_unglued }}.png" title="book list status" alt="book list status" />

View File

@ -181,10 +181,10 @@ $j(document).ready(function(){
{% if not work.first_ebook %}
<div class="pledged-info"><div class="pledged-group">
{% if status == 'ACTIVE' %}
{% if work.last_campaign.supporters.count == 1 %}
{% if work.last_campaign.supporters_count == 1 %}
One Ungluer has
{% else %}
{{ work.last_campaign.supporters.count }} Ungluers have
{{ work.last_campaign.supporters_count }} Ungluers have
{% endif %}
pledged ${{ work.last_campaign.current_total|floatformat:0|intcomma }}<br />toward a ${{ work.last_campaign.target|floatformat:0|intcomma }} goal
{% else %}

View File

@ -331,6 +331,7 @@ class TransactionTest(TestCase):
results = p.query_campaign(c,campaign_total=True, summary=False)
self.assertEqual(results[0].amount, D('12.34'))
self.assertEqual(c.left,c.target-D('12.34'))
self.assertEqual(c.supporters_count, 1)
class BasicGuiTest(TestCase):
def setUp(self):