B2U campaign percentages

pull/1/head
eric 2013-08-08 22:32:58 -04:00
parent c2f3910fe8
commit 75c32569e2
4 changed files with 31 additions and 15 deletions

View File

@ -791,20 +791,23 @@ class Work(models.Model):
def percent_unglued(self): def percent_unglued(self):
status = 0 status = 0
if self.last_campaign() is not None: campaign = self.last_campaign()
if(self.last_campaign_status() == 'SUCCESSFUL'): if campaign is not None:
print campaign.status
if(campaign.status == 'SUCCESSFUL'):
status = 6 status = 6
elif(self.last_campaign_status() == 'ACTIVE'): elif(campaign.status == 'ACTIVE'):
target = float(self.last_campaign().target) target = float(campaign.target)
if target <= 0: if target <= 0:
status = 6 status = 6
else: else:
total = float(self.last_campaign().current_total) print campaign.type
percent = int(total*6/target) if campaign.type == BUY2UNGLUE:
if percent >= 6: status = int( 6 - 6*campaign.left/campaign.target)
status = 6
else: else:
status = percent status = int(float(campaign.current_total)*6/target)
if status >= 6:
status = 6
return status return status
def percent_of_goal(self): def percent_of_goal(self):
@ -812,9 +815,10 @@ class Work(models.Model):
campaign = self.last_campaign() campaign = self.last_campaign()
if campaign is not None: if campaign is not None:
if(campaign.status == 'SUCCESSFUL' or campaign.status == 'ACTIVE'): if(campaign.status == 'SUCCESSFUL' or campaign.status == 'ACTIVE'):
target = campaign.target if campaign.type == BUY2UNGLUE:
total = campaign.current_total percent = int(100 - 100*campaign.left/campaign.target)
percent = int(total/target*100) else:
percent = int(campaign.current_total/campaign.target*100)
return percent return percent
def ebooks(self): def ebooks(self):

View File

@ -432,10 +432,18 @@ class CampaignTests(TestCase):
deadline=datetime(2013, 1, 1), deadline=datetime(2013, 1, 1),
work=w, type=2, work=w, type=2,
cc_date_initial=datetime(2113, 1, 1), cc_date_initial=datetime(2113, 1, 1),
status='INITIALIZED',
) )
self.assertTrue(c.set_dollar_per_day()<0.34) self.assertTrue(c.set_dollar_per_day()<0.34)
self.assertTrue(c.dollar_per_day>0.31) self.assertTrue(c.dollar_per_day>0.31)
#c.save()
#self.assertEqual(w.percent_unglued(),0)
c._current_total = D(6000.1)
c.status = 'ACTIVE'
c.save()
c.update_left()
print(w.percent_of_goal())
self.assertEqual(w.percent_unglued(),3)
self.assertTrue(w.percent_of_goal()>49)
def test_required_fields(self): def test_required_fields(self):
# a campaign must have a target, deadline and a work # a campaign must have a target, deadline and a work

View File

@ -80,7 +80,11 @@ Please fix the following before launching your campaign:
<div class="pledged-info"> <div class="pledged-info">
<div class="pledged-group"> <div class="pledged-group">
{% ifequal work.last_campaign.type 1 %}
{{ 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 }}
{% else %}
Total revenue: ${{ work.last_campaign.current_total|intcomma }} from {{ work.last_campaign.supporters_count }} Ungluers
{% endifequal %}
</div> </div>
<div class="status"> <div class="status">
<img src="/static/images/images/icon-book-37by25-{{ work.percent_unglued }}.png" title="book list status" alt="book list status" /> <img src="/static/images/images/icon-book-37by25-{{ work.percent_unglued }}.png" title="book list status" alt="book list status" />

View File

@ -54,7 +54,7 @@ Any questions not covered here? Please email us at <a href="mailto:rights@gluej
{% ifequal campaign.type 1 %} {% ifequal campaign.type 1 %}
${{ campaign.current_total }} pledged of ${{ campaign.target }}, {{ campaign.supporters_count }} supporters ${{ campaign.current_total }} pledged of ${{ campaign.target }}, {{ campaign.supporters_count }} supporters
{% else %} {% else %}
${{ campaign.current_total }} sold of ${{ campaign.target }}, CC Date: {{ campaign.cc_date }} ${{ campaign.current_total }} sold. ${{ campaign.target }} to go. CC Date: {{ campaign.cc_date }}
{% endifequal %} {% endifequal %}
</div> </div>
{% if campaign.status = 'ACTIVE' or campaign.status = 'INITIALIZED' %} {% if campaign.status = 'ACTIVE' or campaign.status = 'INITIALIZED' %}
@ -134,7 +134,7 @@ Any questions not covered here? Please email us at <a href="mailto:rights@gluej
{% ifequal campaign.type 1 %} {% ifequal campaign.type 1 %}
${{ campaign.current_total }} pledged of ${{ campaign.target }}, {{ campaign.supporters_count }} supporters ${{ campaign.current_total }} pledged of ${{ campaign.target }}, {{ campaign.supporters_count }} supporters
{% else %} {% else %}
${{ campaign.current_total }} sold of ${{ campaign.target }}, CC Date: {{ campaign.cc_date }} ${{ campaign.current_total }} sold. ${{ campaign.target }} to go, CC Date: {{ campaign.cc_date }}
{% endifequal %} {% endifequal %}
</div> </div>
{% endif %} {% endif %}